Prechádzať zdrojové kódy

Nodes: .getCacheKey() (#24442)

* Node: .getCacheKey()

* cleanup
sunag 3 rokov pred
rodič
commit
9d6c37f6ac

+ 7 - 1
examples/jsm/nodes/core/Node.js

@@ -1,5 +1,5 @@
 import { NodeUpdateType } from './constants.js';
-import { getNodesKeys } from './NodeUtils.js';
+import { getNodesKeys, getCacheKey } from './NodeUtils.js';
 import { MathUtils } from 'three';
 
 let _nodeId = 0;
@@ -58,6 +58,12 @@ class Node {
 
 	}
 
+	getCacheKey() {
+
+		return getCacheKey( this );
+
+	}
+
 	getHash( /*builder*/ ) {
 
 		return this.uuid;

+ 22 - 0
examples/jsm/nodes/core/NodeUtils.js

@@ -1,5 +1,27 @@
 import { Color, Matrix3, Matrix4, Vector2, Vector3, Vector4 } from 'three';
 
+export const getCacheKey = ( object ) => {
+
+	let cacheKey = '{';
+
+	if ( object.isNode === true ) {
+
+		cacheKey += `uuid:"${ object.uuid }",`;
+
+	}
+
+	for ( const property of getNodesKeys( object ) ) {
+
+		cacheKey += `${ property }:${ object[ property ].getCacheKey() },`;
+
+	}
+
+	cacheKey += '}';
+
+	return cacheKey;
+
+};
+
 export const getNodesKeys = ( object ) => {
 
 	const props = [];

+ 2 - 2
examples/jsm/nodes/materials/NodeMaterial.js

@@ -1,5 +1,5 @@
 import { Material, ShaderMaterial } from 'three';
-import { getNodesKeys } from '../core/NodeUtils.js';
+import { getNodesKeys, getCacheKey } from '../core/NodeUtils.js';
 import ExpressionNode from '../core/ExpressionNode.js';
 import {
 	float, vec3, vec4,
@@ -37,7 +37,7 @@ class NodeMaterial extends ShaderMaterial {
 
 	customProgramCacheKey() {
 
-		return this.uuid + '-' + this.version;
+		return getCacheKey( this );
 
 	}