mirror of
https://github.com/tengge1/ShadowEditor.git
synced 2026-01-25 15:08:11 +00:00
76 lines
1.4 KiB
JavaScript
76 lines
1.4 KiB
JavaScript
/**
|
|
* @author sunag / http://www.sunag.com.br/
|
|
*/
|
|
|
|
THREE.OperatorNode = function ( a, b, op ) {
|
|
|
|
THREE.TempNode.call( this );
|
|
|
|
this.a = a;
|
|
this.b = b;
|
|
this.op = op || THREE.OperatorNode.ADD;
|
|
|
|
};
|
|
|
|
THREE.OperatorNode.ADD = '+';
|
|
THREE.OperatorNode.SUB = '-';
|
|
THREE.OperatorNode.MUL = '*';
|
|
THREE.OperatorNode.DIV = '/';
|
|
|
|
THREE.OperatorNode.prototype = Object.create( THREE.TempNode.prototype );
|
|
THREE.OperatorNode.prototype.constructor = THREE.OperatorNode;
|
|
THREE.OperatorNode.prototype.nodeType = "Operator";
|
|
|
|
THREE.OperatorNode.prototype.getType = function ( builder ) {
|
|
|
|
var a = this.a.getType( builder );
|
|
var b = this.b.getType( builder );
|
|
|
|
if ( builder.isFormatMatrix( a ) ) {
|
|
|
|
return 'v4';
|
|
|
|
} else if ( builder.getFormatLength( b ) > builder.getFormatLength( a ) ) {
|
|
|
|
// use the greater length vector
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
return a;
|
|
|
|
};
|
|
|
|
THREE.OperatorNode.prototype.generate = function ( builder, output ) {
|
|
|
|
var material = builder.material,
|
|
data = material.getDataNode( this.uuid );
|
|
|
|
var type = this.getType( builder );
|
|
|
|
var a = this.a.build( builder, type );
|
|
var b = this.b.build( builder, type );
|
|
|
|
return builder.format( '(' + a + this.op + b + ')', type, output );
|
|
|
|
};
|
|
|
|
THREE.OperatorNode.prototype.toJSON = function ( meta ) {
|
|
|
|
var data = this.getJSONNode( meta );
|
|
|
|
if ( ! data ) {
|
|
|
|
data = this.createJSONNode( meta );
|
|
|
|
data.a = this.a.toJSON( meta ).uuid;
|
|
data.b = this.b.toJSON( meta ).uuid;
|
|
data.op = this.op;
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
};
|