Browse Source

add Node.hashProperties

sunag 5 năm trước cách đây
mục cha
commit
b9e95b308d

+ 18 - 2
examples/jsm/nodes/core/Node.js

@@ -22,6 +22,8 @@ Node.prototype = {
 
 	isNode: true,
 
+	hashProperties: undefined,
+
 	analyze: function ( builder, settings ) {
 
 		settings = settings || {};
@@ -103,10 +105,11 @@ Node.prototype = {
 	getHash: function() {
 
 		var hash = '{';
+		var prop, obj;
 
-		for(var prop in this) {
+		for(prop in this) {
 
-			var obj = this[ prop ];
+			obj = this[ prop ];
 
 			if (obj instanceof Node) {
 
@@ -116,6 +119,19 @@ Node.prototype = {
 
 		}
 
+		if (this.hashProperties) {
+
+			for(var i = 0; i < this.hashProperties.length; i++) {
+
+				prop = this.hashProperties[ i ];
+				obj = this[ prop ];
+
+				hash += '"' + prop + '":"' + String( obj ) + '",';
+
+			}
+
+		}
+
 		hash += '"id":"' + this.uuid + '"}';
 
 		return hash;		

+ 1 - 0
examples/jsm/nodes/effects/ColorAdjustmentNode.js

@@ -77,6 +77,7 @@ ColorAdjustmentNode.CONTRAST = 'contrast';
 ColorAdjustmentNode.prototype = Object.create( TempNode.prototype );
 ColorAdjustmentNode.prototype.constructor = ColorAdjustmentNode;
 ColorAdjustmentNode.prototype.nodeType = "ColorAdjustment";
+ColorAdjustmentNode.prototype.hashProperties = [ "method" ];
 
 ColorAdjustmentNode.prototype.generate = function ( builder, output ) {