Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenloader/intern/versioning_cycles.c
| Show First 20 Lines • Show All 767 Lines • ▼ Show 20 Lines | static void update_noise_node_dimensions(bNodeTree *ntree) | ||||
| for (bNode *node = ntree->nodes.first; node; node = node->next) { | for (bNode *node = ntree->nodes.first; node; node = node->next) { | ||||
| if (node->type == SH_NODE_TEX_NOISE && node->storage) { | if (node->type == SH_NODE_TEX_NOISE && node->storage) { | ||||
| NodeTexNoise *tex = (NodeTexNoise *)node->storage; | NodeTexNoise *tex = (NodeTexNoise *)node->storage; | ||||
| tex->dimensions = 3; | tex->dimensions = 3; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* This structure is only used to pass data to | |||||
| * update_mapping_node_fcurve_rna_path_callback. | |||||
| */ | |||||
| typedef struct { | |||||
| char *nodePath; | |||||
| bNode *minimumNode; | |||||
| bNode *maximumNode; | |||||
| } MappingNodeFCurveCallbackData; | |||||
| /* This callback function is used by update_mapping_node_inputs_and_properties. | |||||
| * It is executed on every fcurve in the nodetree id updating its RNA paths. The | |||||
| * paths needs to be updated because the node properties became inputs. | |||||
| * | |||||
| * nodes["Mapping"].translation --> nodes["Mapping"].inputs[1].default_value | |||||
| * nodes["Mapping"].rotation --> nodes["Mapping"].inputs[2].default_value | |||||
| * nodes["Mapping"].scale --> nodes["Mapping"].inputs[3].default_value | |||||
| * nodes["Mapping"].max --> nodes["Maximum"].inputs[1].default_value | |||||
| * nodes["Mapping"].min --> nodes["Minimum"].inputs[1].default_value | |||||
| * | |||||
| * The fcurve can be that of any node or property in the nodetree, so we only | |||||
| * update if the rna path starts with the rna path of the mapping node and | |||||
| * doesn't end with "default_value", that is, not the Vector input. | |||||
| */ | |||||
| static void update_mapping_node_fcurve_rna_path_callback(ID *UNUSED(id), | |||||
| FCurve *fcurve, | |||||
| void *_data) | |||||
| { | |||||
| MappingNodeFCurveCallbackData *data = (MappingNodeFCurveCallbackData *)_data; | |||||
| if (!STRPREFIX(fcurve->rna_path, data->nodePath) || | |||||
| BLI_str_endswith(fcurve->rna_path, "default_value")) { | |||||
| return; | |||||
| } | |||||
| char *old_fcurve_rna_path = fcurve->rna_path; | |||||
| if (BLI_str_endswith(old_fcurve_rna_path, "translation")) { | |||||
| fcurve->rna_path = BLI_sprintfN("%s.%s", data->nodePath, "inputs[1].default_value"); | |||||
| } | |||||
| else if (BLI_str_endswith(old_fcurve_rna_path, "rotation")) { | |||||
| fcurve->rna_path = BLI_sprintfN("%s.%s", data->nodePath, "inputs[2].default_value"); | |||||
| } | |||||
| else if (BLI_str_endswith(old_fcurve_rna_path, "scale")) { | |||||
| fcurve->rna_path = BLI_sprintfN("%s.%s", data->nodePath, "inputs[3].default_value"); | |||||
| } | |||||
| else if (data->minimumNode && BLI_str_endswith(old_fcurve_rna_path, "max")) { | |||||
| fcurve->rna_path = BLI_sprintfN( | |||||
| "nodes[\"%s\"].%s", data->minimumNode->name, "inputs[1].default_value"); | |||||
| } | |||||
| else if (data->maximumNode && BLI_str_endswith(old_fcurve_rna_path, "min")) { | |||||
| fcurve->rna_path = BLI_sprintfN( | |||||
| "nodes[\"%s\"].%s", data->maximumNode->name, "inputs[1].default_value"); | |||||
| } | |||||
| if (fcurve->rna_path != old_fcurve_rna_path) { | |||||
| MEM_freeN(old_fcurve_rna_path); | |||||
| } | |||||
| } | |||||
| /* The Mapping node has been rewritten to support dynamic inputs. Previously, | /* The Mapping node has been rewritten to support dynamic inputs. Previously, | ||||
| * the transformation information was stored in a TexMapping struct in the | * the transformation information was stored in a TexMapping struct in the | ||||
| * node->storage member of bNode. Currently, the transformation information | * node->storage member of bNode. Currently, the transformation information | ||||
| * is stored in input sockets. To correct this, we transfer the information | * is stored in input sockets. To correct this, we transfer the information | ||||
| * from the TexMapping struct to the input sockets. | * from the TexMapping struct to the input sockets. | ||||
| * | * | ||||
| * Additionally, the Minimum and Maximum properties are no longer available | * Additionally, the Minimum and Maximum properties are no longer available | ||||
| * in the node. To correct this, a Vector Minimum and/or a Vector Maximum | * in the node. To correct this, a Vector Minimum and/or a Vector Maximum | ||||
| ▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | if (node->type == SH_NODE_MAPPING && node->storage) { | ||||
| bNodeSocket *sockMinimumA = BLI_findlink(&minimumNode->inputs, 0); | bNodeSocket *sockMinimumA = BLI_findlink(&minimumNode->inputs, 0); | ||||
| nodeAddLink(ntree, node, sockMappingResult, minimumNode, sockMinimumA); | nodeAddLink(ntree, node, sockMappingResult, minimumNode, sockMinimumA); | ||||
| need_update = true; | need_update = true; | ||||
| } | } | ||||
| MEM_freeN(node->storage); | MEM_freeN(node->storage); | ||||
| node->storage = NULL; | node->storage = NULL; | ||||
| AnimData *animData = BKE_animdata_from_id(&ntree->id); | |||||
| if (animData && animData->action) { | |||||
| char *nodePath = BLI_sprintfN("nodes[\"%s\"]", node->name); | char *nodePath = BLI_sprintfN("nodes[\"%s\"]", node->name); | ||||
sergey: Wouldn't it be more reliable and less verbose to use `BKE_fcurves_id_cb`? | |||||
| for (FCurve *fcu = animData->action->curves.first; fcu; fcu = fcu->next) { | MappingNodeFCurveCallbackData data = {nodePath, minimumNode, maximumNode}; | ||||
| if (STRPREFIX(fcu->rna_path, nodePath) && | BKE_fcurves_id_cb(&ntree->id, update_mapping_node_fcurve_rna_path_callback, &data); | ||||
| !BLI_str_endswith(fcu->rna_path, "default_value")) { | |||||
| char *old_fcu_rna_path = fcu->rna_path; | |||||
| if (BLI_str_endswith(old_fcu_rna_path, "translation")) { | |||||
| fcu->rna_path = BLI_sprintfN("%s.%s", nodePath, "inputs[1].default_value"); | |||||
| } | |||||
| else if (BLI_str_endswith(old_fcu_rna_path, "rotation")) { | |||||
| fcu->rna_path = BLI_sprintfN("%s.%s", nodePath, "inputs[2].default_value"); | |||||
| } | |||||
| else if (BLI_str_endswith(old_fcu_rna_path, "scale")) { | |||||
| fcu->rna_path = BLI_sprintfN("%s.%s", nodePath, "inputs[3].default_value"); | |||||
| } | |||||
| else if (minimumNode && BLI_str_endswith(old_fcu_rna_path, "max")) { | |||||
| fcu->rna_path = BLI_sprintfN( | |||||
| "nodes[\"%s\"].%s", minimumNode->name, "inputs[1].default_value"); | |||||
| } | |||||
| else if (maximumNode && BLI_str_endswith(old_fcu_rna_path, "min")) { | |||||
| fcu->rna_path = BLI_sprintfN( | |||||
| "nodes[\"%s\"].%s", maximumNode->name, "inputs[1].default_value"); | |||||
| } | |||||
| if (fcu->rna_path != old_fcu_rna_path) { | |||||
| MEM_freeN(old_fcu_rna_path); | |||||
| } | |||||
| } | |||||
| } | |||||
| MEM_freeN(nodePath); | MEM_freeN(nodePath); | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| if (need_update) { | if (need_update) { | ||||
| ntreeUpdateTree(NULL, ntree); | ntreeUpdateTree(NULL, ntree); | ||||
| } | } | ||||
| } | } | ||||
| /* The Musgrave node now has a dimension property. This property should | /* The Musgrave node now has a dimension property. This property should | ||||
| * be initialized to 3 by default. | * be initialized to 3 by default. | ||||
| ▲ Show 20 Lines • Show All 490 Lines • Show Last 20 Lines | |||||
Wouldn't it be more reliable and less verbose to use BKE_fcurves_id_cb?