Преглед на файлове

allow redefine nodes dynamically

SUNAG преди 9 години
родител
ревизия
7b8aad6fde
променени са 2 файла, в които са добавени 53 реда и са изтрити 25 реда
  1. 27 16
      examples/js/materials/nodes/ConstNode.js
  2. 26 9
      examples/js/materials/nodes/accessors/CameraNode.js

+ 27 - 16
examples/js/materials/nodes/ConstNode.js

@@ -4,12 +4,28 @@
 
 THREE.ConstNode = function( name, useDefine ) {
 
-	name = name || THREE.ConstNode.PI;
+	THREE.TempNode.call( this );
 
-	var rDeclaration = /^([a-z_0-9]+)\s([a-z_0-9]+)\s?\=(.*?)\;/i;
-	var type = 'fv1';
+	this.parse( name || THREE.ConstNode.PI, useDefine );
+
+};
+
+THREE.ConstNode.prototype = Object.create( THREE.TempNode.prototype );
+THREE.ConstNode.prototype.constructor = THREE.ConstNode;
+
+THREE.ConstNode.PI = 'PI';
+THREE.ConstNode.PI2 = 'PI2';
+THREE.ConstNode.RECIPROCAL_PI = 'RECIPROCAL_PI';
+THREE.ConstNode.RECIPROCAL_PI2 = 'RECIPROCAL_PI2';
+THREE.ConstNode.LOG2 = 'LOG2';
+THREE.ConstNode.EPSILON = 'EPSILON';
+
+THREE.ConstNode.prototype.parse = function( src, useDefine ) {
+
+	var name, type;
 
-	var match = name.match( rDeclaration );
+	var rDeclaration = /^([a-z_0-9]+)\s([a-z_0-9]+)\s?\=(.*?)\;/i;
+	var match = src.match( rDeclaration );
 
 	if ( match && match.length > 1 ) {
 
@@ -28,22 +44,17 @@ THREE.ConstNode = function( name, useDefine ) {
 		}
 
 	}
+	else {
 
-	this.name = name;
-
-	THREE.TempNode.call( this, type );
+		name = src;
+		type = 'fv1';
 
-};
+	}
 
-THREE.ConstNode.prototype = Object.create( THREE.TempNode.prototype );
-THREE.ConstNode.prototype.constructor = THREE.ConstNode;
+	this.name = name;
+	this.type = type;
 
-THREE.ConstNode.PI = 'PI';
-THREE.ConstNode.PI2 = 'PI2';
-THREE.ConstNode.RECIPROCAL_PI = 'RECIPROCAL_PI';
-THREE.ConstNode.RECIPROCAL_PI2 = 'RECIPROCAL_PI2';
-THREE.ConstNode.LOG2 = 'LOG2';
-THREE.ConstNode.EPSILON = 'EPSILON';
+};
 
 THREE.ConstNode.prototype.generate = function( builder, output ) {
 

+ 26 - 9
examples/js/materials/nodes/accessors/CameraNode.js

@@ -6,9 +6,34 @@ THREE.CameraNode = function( scope, camera ) {
 
 	THREE.TempNode.call( this, 'v3' );
 
-	this.scope = scope || THREE.CameraNode.POSITION;
+	this.setScope( scope || THREE.CameraNode.POSITION );
 	this.camera = camera;
 
+	this.requestUpdate = this.camera !== undefined;
+
+};
+
+THREE.CameraNode.prototype = Object.create( THREE.TempNode.prototype );
+THREE.CameraNode.prototype.constructor = THREE.CameraNode;
+
+THREE.CameraNode.POSITION = 'position';
+THREE.CameraNode.DEPTH = 'depth';
+
+THREE.CameraNode.prototype.setScope = function( scope ) {
+
+	switch ( this.scope ) {
+
+		case THREE.CameraNode.DEPTH:
+
+			delete this.near;
+			delete this.far;
+
+			break;
+
+	}
+
+	this.scope = scope;
+
 	switch ( scope ) {
 
 		case THREE.CameraNode.DEPTH:
@@ -20,16 +45,8 @@ THREE.CameraNode = function( scope, camera ) {
 
 	}
 
-	this.requestUpdate = this.camera !== undefined;
-
 };
 
-THREE.CameraNode.prototype = Object.create( THREE.TempNode.prototype );
-THREE.CameraNode.prototype.constructor = THREE.CameraNode;
-
-THREE.CameraNode.POSITION = 'position';
-THREE.CameraNode.DEPTH = 'depth';
-
 THREE.CameraNode.prototype.getType = function( builder ) {
 
 	switch ( this.scope ) {