DwM: add CD_AUTO_FROM_NAME for mesh conversion

This commit is contained in:
2017-06-29 15:23:47 +10:00
parent 15079b0b43
commit f6bb3262f1

View File

@@ -243,6 +243,7 @@ static void mesh_cd_calc_used_gpu_layers(
CustomData *cd_ldata, uchar cd_lused[CD_NUMTYPES], CustomData *cd_ldata, uchar cd_lused[CD_NUMTYPES],
struct GPUMaterial **gpumat_array, int gpumat_array_len) struct GPUMaterial **gpumat_array, int gpumat_array_len)
{ {
/* See: DM_vertex_attributes_from_gpu for similar logic */
GPUVertexAttribs gattribs = {0}; GPUVertexAttribs gattribs = {0};
for (int i = 0; i < gpumat_array_len; i++) { for (int i = 0; i < gpumat_array_len; i++) {
@@ -251,37 +252,74 @@ static void mesh_cd_calc_used_gpu_layers(
GPU_material_vertex_attributes(gpumat, &gattribs); GPU_material_vertex_attributes(gpumat, &gattribs);
for (int j = 0; j < gattribs.totlayer; j++) { for (int j = 0; j < gattribs.totlayer; j++) {
const char *name = gattribs.layer[j].name; const char *name = gattribs.layer[j].name;
switch (gattribs.layer[j].type) { int type = gattribs.layer[j].type;
int layer = -1;
if (type == CD_AUTO_FROM_NAME) {
/* We need to deduct what exact layer is used.
*
* We do it based on the specified name.
*/
if (name[0]) {
layer = CustomData_get_named_layer_index(cd_ldata, CD_MLOOPUV, name);
type = CD_MTFACE;
if (layer == -1) {
layer = CustomData_get_named_layer_index(cd_ldata, CD_MLOOPCOL, name);
type = CD_MCOL;
}
#if 0 /* Tangents are always from UV's - this will never happen. */
if (layer == -1) {
layer = CustomData_get_named_layer_index(cd_ldata, CD_TANGENT, name);
type = CD_TANGENT;
}
#endif
if (layer == -1) {
continue;
}
}
else {
/* Fall back to the UV layer, which matches old behavior. */
type = CD_MTFACE;
}
}
switch (type) {
case CD_MTFACE: case CD_MTFACE:
{ {
int index = (name[0] != '\0') ? if (layer == -1) {
CustomData_get_named_layer(cd_ldata, CD_MLOOPUV, name) : layer = (name[0] != '\0') ?
CustomData_get_active_layer(cd_ldata, CD_MLOOPUV); CustomData_get_named_layer(cd_ldata, CD_MLOOPUV, name) :
if (index != -1) { CustomData_get_active_layer(cd_ldata, CD_MLOOPUV);
cd_lused[CD_MLOOPUV] |= (1 << index); }
if (layer != -1) {
cd_lused[CD_MLOOPUV] |= (1 << layer);
} }
break; break;
} }
case CD_TANGENT: case CD_TANGENT:
{ {
int index = (name[0] != '\0') ? if (layer == -1) {
CustomData_get_named_layer(cd_ldata, CD_MLOOPUV, name) : layer = (name[0] != '\0') ?
CustomData_get_active_layer(cd_ldata, CD_MLOOPUV); CustomData_get_named_layer(cd_ldata, CD_MLOOPUV, name) :
if (index != -1) { CustomData_get_active_layer(cd_ldata, CD_MLOOPUV);
cd_lused[CD_TANGENT] |= (1 << index); }
if (layer != -1) {
cd_lused[CD_TANGENT] |= (1 << layer);
/* TODO(campbell): investigate why this is needed T51919. */ /* TODO(campbell): investigate why this is needed T51919. */
cd_lused[CD_MLOOPUV] |= (1 << index); cd_lused[CD_MLOOPUV] |= (1 << layer);
} }
break; break;
} }
case CD_MCOL: case CD_MCOL:
{ {
int index = (name[0] != '\0') ? if (layer == -1) {
CustomData_get_named_layer(cd_ldata, CD_MLOOPCOL, name) : layer = (name[0] != '\0') ?
CustomData_get_active_layer(cd_ldata, CD_MLOOPCOL); CustomData_get_named_layer(cd_ldata, CD_MLOOPCOL, name) :
if (index != -1) { CustomData_get_active_layer(cd_ldata, CD_MLOOPCOL);
cd_lused[CD_MLOOPCOL] |= (1 << index); }
if (layer != -1) {
cd_lused[CD_MLOOPCOL] |= (1 << layer);
} }
break; break;
} }