最新代码
This commit is contained in:
65
public/sdk/three/jsm/nodes/utils/ConvertNode.js
Normal file
65
public/sdk/three/jsm/nodes/utils/ConvertNode.js
Normal file
@ -0,0 +1,65 @@
|
||||
import Node, { addNodeClass } from '../core/Node.js';
|
||||
|
||||
class ConvertNode extends Node {
|
||||
|
||||
constructor( node, convertTo ) {
|
||||
|
||||
super();
|
||||
|
||||
this.node = node;
|
||||
this.convertTo = convertTo;
|
||||
|
||||
}
|
||||
|
||||
getNodeType( builder ) {
|
||||
|
||||
const requestType = this.node.getNodeType( builder );
|
||||
|
||||
let convertTo = null;
|
||||
|
||||
for ( const overloadingType of this.convertTo.split( '|' ) ) {
|
||||
|
||||
if ( convertTo === null || builder.getTypeLength( requestType ) === builder.getTypeLength( overloadingType ) ) {
|
||||
|
||||
convertTo = overloadingType;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return convertTo;
|
||||
|
||||
}
|
||||
|
||||
serialize( data ) {
|
||||
|
||||
super.serialize( data );
|
||||
|
||||
data.convertTo = this.convertTo;
|
||||
|
||||
}
|
||||
|
||||
deserialize( data ) {
|
||||
|
||||
super.deserialize( data );
|
||||
|
||||
this.convertTo = data.convertTo;
|
||||
|
||||
}
|
||||
|
||||
generate( builder, output ) {
|
||||
|
||||
const node = this.node;
|
||||
const type = this.getNodeType( builder );
|
||||
|
||||
const snippet = node.build( builder, type );
|
||||
|
||||
return builder.format( snippet, type, output );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default ConvertNode;
|
||||
|
||||
addNodeClass( 'ConvertNode', ConvertNode );
|
Reference in New Issue
Block a user