383
static void layerDefault_mloopcol(void *data, int count)
385
static MLoopCol default_mloopcol = {255,255,255,255};
386
MLoopCol *mlcol = (MLoopCol*)data;
388
for(i = 0; i < count; i++)
389
mlcol[i] = default_mloopcol;
393
static void layerInterp_mloopcol(void **sources, float *weights,
394
float *sub_weights, int count, void *dest)
405
col.a = col.r = col.g = col.b = 0;
407
sub_weight = sub_weights;
408
for(i = 0; i < count; ++i){
409
float weight = weights ? weights[i] : 1;
410
MLoopCol *src = sources[i];
412
col.a += src->a * (*sub_weight) * weight;
413
col.r += src->r * (*sub_weight) * weight;
414
col.g += src->g * (*sub_weight) * weight;
415
col.b += src->b * (*sub_weight) * weight;
418
col.a += src->a * weight;
419
col.r += src->r * weight;
420
col.g += src->g * weight;
421
col.b += src->b * weight;
429
static void layerInterp_mloopuv(void **sources, float *weights,
430
float *sub_weights, int count, void *dest)
432
MLoopUV *mluv = dest;
441
sub_weight = sub_weights;
442
for(i = 0; i < count; ++i){
443
float weight = weights ? weights[i] : 1;
444
MLoopUV *src = sources[i];
446
uv.u += src->uv[0] * (*sub_weight) * weight;
447
uv.v += src->uv[1] * (*sub_weight) * weight;
450
uv.u += src->uv[0] * weight;
451
uv.v += src->uv[1] * weight;
365
458
static void layerInterp_mcol(void **sources, float *weights,
366
459
float *sub_weights, int count, void *dest)
454
549
{sizeof(MStringProperty), "MStringProperty",1,"String",NULL,NULL,NULL,NULL},
455
550
{sizeof(OrigSpaceFace), "OrigSpaceFace", 1, "UVTex", layerCopy_origspace_face, NULL,
456
551
layerInterp_origspace_face, layerSwap_origspace_face, layerDefault_origspace_face},
457
{sizeof(float)*3, "", 0, NULL, NULL, NULL, NULL, NULL, NULL}
552
{sizeof(float)*3, "", 0, NULL, NULL, NULL, NULL, NULL, NULL},
553
{sizeof(MTexPoly), "MTexPoly", 1, "Face Texture", NULL, NULL, NULL, NULL, NULL},
554
{sizeof(MLoopUV), "MLoopUV", 1, "UV coord", NULL, NULL, layerInterp_mloopuv, NULL, NULL},
555
{sizeof(MLoopCol), "MLoopCol", 1, "Col", NULL, NULL, layerInterp_mloopcol, NULL, layerDefault_mloopcol},
556
{sizeof(float)*3*4, "", 0, NULL, NULL, NULL, NULL, NULL, NULL}
460
559
const char *LAYERTYPENAMES[CD_NUMTYPES] = {
461
560
"CDMVert", "CDMSticky", "CDMDeformVert", "CDMEdge", "CDMFace", "CDMTFace",
462
561
"CDMCol", "CDOrigIndex", "CDNormal", "CDFlags","CDMFloatProperty",
463
"CDMIntProperty","CDMStringProperty", "CDOrigSpace", "CDOrco"};
562
"CDMIntProperty","CDMStringProperty", "CDOrigSpace", "CDOrco", "CDMTexPoly", "CDMLoopUV", "CDMloopCol", "CDTangent"};
465
564
const CustomDataMask CD_MASK_BAREMESH =
466
565
CD_MASK_MVERT | CD_MASK_MEDGE | CD_MASK_MFACE;
1555
/*needed to convert to/from different face reps*/
1556
void CustomData_to_bmeshpoly(CustomData *fdata, CustomData *pdata, CustomData *ldata)
1559
for(i=0; i < fdata->totlayer; i++){
1560
if(fdata->layers[i].type == CD_MTFACE){
1561
CustomData_add_layer(pdata, CD_MTEXPOLY, CD_CALLOC, &(fdata->layers[i].name), 0);
1562
CustomData_add_layer(ldata, CD_MLOOPUV, CD_CALLOC, &(fdata->layers[i].name), 0);
1564
else if(fdata->layers[i].type == CD_MCOL)
1565
CustomData_add_layer(ldata, CD_MLOOPCOL, CD_CALLOC, &(fdata->layers[i].name), 0);
1568
void CustomData_from_bmeshpoly(CustomData *fdata, CustomData *pdata, CustomData *ldata, int total){
1570
for(i=0; i < pdata->totlayer; i++){
1571
if(pdata->layers[i].type == CD_MTEXPOLY)
1572
CustomData_add_layer(fdata, CD_MTFACE, CD_CALLOC, &(pdata->layers[i].name), total);
1574
for(i=0; i < ldata->totlayer; i++){
1575
if(ldata->layers[i].type == CD_MLOOPCOL)
1576
CustomData_add_layer(fdata, CD_MCOL, CD_CALLOC, &(ldata->layers[i].name), total);
1581
void CustomData_bmesh_init_pool(CustomData *data, int allocsize){
1582
if(data->totlayer)data->pool = BLI_mempool_create(data->totsize, allocsize, allocsize);
1585
void CustomData_bmesh_free_block(CustomData *data, void **block)
1587
const LayerTypeInfo *typeInfo;
1591
for(i = 0; i < data->totlayer; ++i) {
1592
if(!(data->layers[i].flag & CD_FLAG_NOFREE)) {
1593
typeInfo = layerType_getInfo(data->layers[i].type);
1595
if(typeInfo->free) {
1596
int offset = data->layers[i].offset;
1597
typeInfo->free((char*)*block + offset, 1, typeInfo->size);
1602
BLI_mempool_free(data->pool, *block);
1606
static void CustomData_bmesh_alloc_block(CustomData *data, void **block)
1610
CustomData_bmesh_free_block(data, block);
1612
if (data->totsize > 0)
1613
*block = BLI_mempool_calloc(data->pool);
1618
void CustomData_bmesh_copy_data(const CustomData *source, CustomData *dest,
1619
void *src_block, void **dest_block)
1621
const LayerTypeInfo *typeInfo;
1625
CustomData_bmesh_alloc_block(dest, dest_block);
1627
/* copies a layer at a time */
1629
for(src_i = 0; src_i < source->totlayer; ++src_i) {
1631
/* find the first dest layer with type >= the source type
1632
* (this should work because layers are ordered by type)
1634
while(dest_i < dest->totlayer
1635
&& dest->layers[dest_i].type < source->layers[src_i].type)
1638
/* if there are no more dest layers, we're done */
1639
if(dest_i >= dest->totlayer) return;
1641
/* if we found a matching layer, copy the data */
1642
if(dest->layers[dest_i].type == source->layers[src_i].type &&
1643
strcmp(dest->layers[dest_i].name, source->layers[src_i].name) == 0) {
1644
char *src_data = (char*)src_block + source->layers[src_i].offset;
1645
char *dest_data = (char*)*dest_block + dest->layers[dest_i].offset;
1647
typeInfo = layerType_getInfo(source->layers[src_i].type);
1650
typeInfo->copy(src_data, dest_data, 1);
1652
memcpy(dest_data, src_data, typeInfo->size);
1654
/* if there are multiple source & dest layers of the same type,
1655
* we don't want to copy all source layers to the same dest, so
1663
/*Bmesh Custom Data Functions. Should replace editmesh ones with these as well, due to more effecient memory alloc*/
1664
void *CustomData_bmesh_get(const CustomData *data, void *block, int type)
1668
/* get the layer index of the first layer of type */
1669
layer_index = CustomData_get_active_layer_index(data, type);
1670
if(layer_index < 0) return NULL;
1672
return (char *)block + data->layers[layer_index].offset;
1675
void *CustomData_bmesh_get_n(const CustomData *data, void *block, int type, int n)
1679
/* get the layer index of the first layer of type */
1680
layer_index = CustomData_get_layer_index(data, type);
1681
if(layer_index < 0) return NULL;
1683
return (char *)block + data->layers[layer_index+n].offset;
1686
void CustomData_bmesh_set(const CustomData *data, void *block, int type, void *source)
1688
void *dest = CustomData_bmesh_get(data, block, type);
1689
const LayerTypeInfo *typeInfo = layerType_getInfo(type);
1694
typeInfo->copy(source, dest, 1);
1696
memcpy(dest, source, typeInfo->size);
1699
void CustomData_bmesh_set_n(CustomData *data, void *block, int type, int n, void *source)
1701
void *dest = CustomData_bmesh_get_n(data, block, type, n);
1702
const LayerTypeInfo *typeInfo = layerType_getInfo(type);
1707
typeInfo->copy(source, dest, 1);
1709
memcpy(dest, source, typeInfo->size);
1712
void CustomData_bmesh_interp(CustomData *data, void **src_blocks, float *weights,
1713
float *sub_weights, int count, void *dest_block)
1716
void *source_buf[SOURCE_BUF_SIZE];
1717
void **sources = source_buf;
1719
/* slow fallback in case we're interpolating a ridiculous number of
1722
if(count > SOURCE_BUF_SIZE)
1723
sources = MEM_callocN(sizeof(*sources) * count,
1724
"CustomData_interp sources");
1726
/* interpolates a layer at a time */
1727
for(i = 0; i < data->totlayer; ++i) {
1728
CustomDataLayer *layer = &data->layers[i];
1729
const LayerTypeInfo *typeInfo = layerType_getInfo(layer->type);
1730
if(typeInfo->interp) {
1731
for(j = 0; j < count; ++j)
1732
sources[j] = (char *)src_blocks[j] + layer->offset;
1734
typeInfo->interp(sources, weights, sub_weights, count,
1735
(char *)dest_block + layer->offset);
1739
if(count > SOURCE_BUF_SIZE) MEM_freeN(sources);
1742
void CustomData_bmesh_set_default(CustomData *data, void **block)
1744
const LayerTypeInfo *typeInfo;
1748
CustomData_bmesh_alloc_block(data, block);
1750
for(i = 0; i < data->totlayer; ++i) {
1751
int offset = data->layers[i].offset;
1753
typeInfo = layerType_getInfo(data->layers[i].type);
1755
if(typeInfo->set_default)
1756
typeInfo->set_default((char*)*block + offset, 1);
1760
void CustomData_to_bmesh_block(const CustomData *source, CustomData *dest,
1761
int src_index, void **dest_block)
1763
const LayerTypeInfo *typeInfo;
1764
int dest_i, src_i, src_offset;
1767
CustomData_bmesh_alloc_block(dest, dest_block);
1769
/* copies a layer at a time */
1771
for(src_i = 0; src_i < source->totlayer; ++src_i) {
1773
/* find the first dest layer with type >= the source type
1774
* (this should work because layers are ordered by type)
1776
while(dest_i < dest->totlayer
1777
&& dest->layers[dest_i].type < source->layers[src_i].type)
1780
/* if there are no more dest layers, we're done */
1781
if(dest_i >= dest->totlayer) return;
1783
/* if we found a matching layer, copy the data */
1784
if(dest->layers[dest_i].type == source->layers[src_i].type) {
1785
int offset = dest->layers[dest_i].offset;
1786
char *src_data = source->layers[src_i].data;
1787
char *dest_data = (char*)*dest_block + offset;
1789
typeInfo = layerType_getInfo(dest->layers[dest_i].type);
1790
src_offset = src_index * typeInfo->size;
1793
typeInfo->copy(src_data + src_offset, dest_data, 1);
1795
memcpy(dest_data, src_data + src_offset, typeInfo->size);
1797
/* if there are multiple source & dest layers of the same type,
1798
* we don't want to copy all source layers to the same dest, so
1806
void CustomData_from_bmesh_block(const CustomData *source, CustomData *dest,
1807
void *src_block, int dest_index)
1809
const LayerTypeInfo *typeInfo;
1810
int dest_i, src_i, dest_offset;
1812
/* copies a layer at a time */
1814
for(src_i = 0; src_i < source->totlayer; ++src_i) {
1816
/* find the first dest layer with type >= the source type
1817
* (this should work because layers are ordered by type)
1819
while(dest_i < dest->totlayer
1820
&& dest->layers[dest_i].type < source->layers[src_i].type)
1823
/* if there are no more dest layers, we're done */
1824
if(dest_i >= dest->totlayer) return;
1826
/* if we found a matching layer, copy the data */
1827
if(dest->layers[dest_i].type == source->layers[src_i].type) {
1828
int offset = source->layers[src_i].offset;
1829
char *src_data = (char*)src_block + offset;
1830
char *dest_data = dest->layers[dest_i].data;
1832
typeInfo = layerType_getInfo(dest->layers[dest_i].type);
1833
dest_offset = dest_index * typeInfo->size;
1836
typeInfo->copy(src_data, dest_data + dest_offset, 1);
1838
memcpy(dest_data + dest_offset, src_data, typeInfo->size);
1840
/* if there are multiple source & dest layers of the same type,
1841
* we don't want to copy all source layers to the same dest, so
1452
1850
void CustomData_file_write_info(int type, char **structname, int *structnum)
1454
1852
const LayerTypeInfo *typeInfo = layerType_getInfo(type);