From 114f0ad78fcc21460a0f197b26f59cfef8aeb679 Mon Sep 17 00:00:00 2001 From: sunag Date: Mon, 20 May 2024 04:24:35 -0300 Subject: [PATCH] TSL: Node - Introduce `getElementType()` (#28437) * Fix Array Element Type * revision --- examples/jsm/nodes/accessors/BufferNode.js | 6 ++++++ examples/jsm/nodes/core/Node.js | 9 +++++++++ examples/jsm/nodes/core/NodeBuilder.js | 10 ++++++++++ examples/jsm/nodes/utils/ArrayElementNode.js | 2 +- 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/examples/jsm/nodes/accessors/BufferNode.js b/examples/jsm/nodes/accessors/BufferNode.js index 663d589658417a..6233efa0550ee0 100644 --- a/examples/jsm/nodes/accessors/BufferNode.js +++ b/examples/jsm/nodes/accessors/BufferNode.js @@ -15,6 +15,12 @@ class BufferNode extends UniformNode { } + getElementType( builder ) { + + return this.getNodeType( builder ); + + } + getInputType( /*builder*/ ) { return 'buffer'; diff --git a/examples/jsm/nodes/core/Node.js b/examples/jsm/nodes/core/Node.js index b9aaa026a1e050..79ad31a86324f4 100644 --- a/examples/jsm/nodes/core/Node.js +++ b/examples/jsm/nodes/core/Node.js @@ -163,6 +163,15 @@ class Node extends EventDispatcher { } + getElementType( builder ) { + + const type = this.getNodeType( builder ); + const elementType = builder.getElementType( type ); + + return elementType; + + } + getNodeType( builder ) { const nodeProperties = builder.getNodeProperties( this ); diff --git a/examples/jsm/nodes/core/NodeBuilder.js b/examples/jsm/nodes/core/NodeBuilder.js index 4ca4f02c0ee817..0a7929ebe7bc27 100644 --- a/examples/jsm/nodes/core/NodeBuilder.js +++ b/examples/jsm/nodes/core/NodeBuilder.js @@ -498,6 +498,16 @@ class NodeBuilder { } + getElementType( type ) { + + if ( type === 'mat2' ) return 'vec2'; + if ( type === 'mat3' ) return 'vec3'; + if ( type === 'mat4' ) return 'vec4'; + + return this.getComponentType( type ); + + } + getComponentType( type ) { type = this.getVectorType( type ); diff --git a/examples/jsm/nodes/utils/ArrayElementNode.js b/examples/jsm/nodes/utils/ArrayElementNode.js index dfba683dd9bca2..750d5f8af1602d 100644 --- a/examples/jsm/nodes/utils/ArrayElementNode.js +++ b/examples/jsm/nodes/utils/ArrayElementNode.js @@ -15,7 +15,7 @@ class ArrayElementNode extends Node { // @TODO: If extending from TempNode it br getNodeType( builder ) { - return this.node.getNodeType( builder ); + return this.node.getElementType( builder ); }