File size: 1,819 Bytes
6cd9596
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/**
 * @author sunag / http://www.sunag.com.br/
 */

import { TempNode } from '../core/TempNode.js';
import { NodeUtils } from '../core/NodeUtils.js';

var inputs = NodeUtils.elements;

function JoinNode( x, y, z, w ) {

	TempNode.call( this, 'f' );

	this.x = x;
	this.y = y;
	this.z = z;
	this.w = w;

}

JoinNode.prototype = Object.create( TempNode.prototype );
JoinNode.prototype.constructor = JoinNode;
JoinNode.prototype.nodeType = "Join";

JoinNode.prototype.getNumElements = function () {

	var i = inputs.length;

	while ( i -- ) {

		if ( this[ inputs[ i ] ] !== undefined ) {

			++ i;

			break;

		}

	}

	return Math.max( i, 2 );

};

JoinNode.prototype.getType = function ( builder ) {

	return builder.getTypeFromLength( this.getNumElements() );

};

JoinNode.prototype.generate = function ( builder, output ) {

	var type = this.getType( builder ),
		length = this.getNumElements(),
		outputs = [];

	for ( var i = 0; i < length; i ++ ) {

		var elm = this[ inputs[ i ] ];

		outputs.push( elm ? elm.build( builder, 'f' ) : '0.0' );

	}

	var code = ( length > 1 ? builder.getConstructorFromLength( length ) : '' ) + '( ' + outputs.join( ', ' ) + ' )';

	return builder.format( code, type, output );

};

JoinNode.prototype.copy = function ( source ) {

	TempNode.prototype.copy.call( this, source );

	for ( var prop in source.inputs ) {

		this[ prop ] = source.inputs[ prop ];

	}

};

JoinNode.prototype.toJSON = function ( meta ) {

	var data = this.getJSONNode( meta );

	if ( ! data ) {

		data = this.createJSONNode( meta );

		data.inputs = {};

		var length = this.getNumElements();

		for ( var i = 0; i < length; i ++ ) {

			var elm = this[ inputs[ i ] ];

			if ( elm ) {

				data.inputs[ inputs[ i ] ] = elm.toJSON( meta ).uuid;

			}

		}


	}

	return data;

};

export { JoinNode };