Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MorphNode: Fix loop performance #27707

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions examples/jsm/nodes/accessors/MorphNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { textureLoad } from './TextureNode.js';
import { vertexIndex } from '../core/IndexNode.js';
import { ivec2, int } from '../shadernode/ShaderNode.js';
import { DataArrayTexture, Vector2, Vector4, FloatType } from 'three';
import { loop } from '../utils/LoopNode.js';

const morphTextures = new WeakMap();
const morphVec4 = new Vector4();
Expand Down Expand Up @@ -185,10 +186,9 @@ class MorphNode extends Node {

const width = int( size.width );

for ( let i = 0; i < morphTargetsCount; i ++ ) {
loop( morphTargetsCount, ( { i } ) => {

const influence = referenceIndex( 'morphTargetInfluences', i, 'float' );
const depth = int( i );

if ( hasMorphPosition === true ) {

Expand All @@ -197,7 +197,7 @@ class MorphNode extends Node {
influence,
stride,
width,
depth,
depth: i,
offset: int( 0 )
} ) );

Expand All @@ -210,13 +210,13 @@ class MorphNode extends Node {
influence,
stride,
width,
depth,
depth: i,
offset: int( 1 )
} ) );

}

}
} );

}

Expand Down
44 changes: 22 additions & 22 deletions examples/jsm/nodes/accessors/ReferenceNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ import { NodeUpdateType } from '../core/constants.js';
import { uniform } from '../core/UniformNode.js';
import { texture } from './TextureNode.js';
import { nodeObject } from '../shadernode/ShaderNode.js';
import { uniforms } from './UniformsNode.js';

class ReferenceNode extends Node {

constructor( property, uniformType, object = null ) {
constructor( property, uniformType, object = null, indexNode = null ) {

super();

this.property = property;
this.index = null;
this.indexNode = indexNode;

this.uniformType = uniformType;

Expand All @@ -34,20 +35,6 @@ class ReferenceNode extends Node {

}

setIndex( index ) {

this.index = index;

return this;

}

getIndex() {

return this.index;

}

setNodeType( uniformType ) {

let node = null;
Expand All @@ -56,6 +43,10 @@ class ReferenceNode extends Node {

node = texture( null );

} else if ( this.indexNode !== null ) {

node = uniforms( null, uniformType ).element( this.indexNode );

} else {

node = uniform( uniformType );
Expand All @@ -74,19 +65,28 @@ class ReferenceNode extends Node {

update( /*frame*/ ) {

let value = this.reference[ this.property ];
const value = this.reference[ this.property ];

if ( this.indexNode !== null ) {

if ( this.index !== null ) {
this.node.node.array = value;

} else {

value = value[ this.index ];
this.node.value = value;

}

this.node.value = value;

}

setup( /*builder*/ ) {
setup( builder ) {

if ( this.indexNode !== null ) {

this.node.node.array = ( this.object !== null ? this.object : builder.object )[ this.property ];

}

return this.node;

Expand All @@ -97,6 +97,6 @@ class ReferenceNode extends Node {
export default ReferenceNode;

export const reference = ( name, type, object ) => nodeObject( new ReferenceNode( name, type, object ) );
export const referenceIndex = ( name, index, type, object ) => nodeObject( new ReferenceNode( name, type, object ).setIndex( index ) );
export const referenceIndex = ( name, index, type, object ) => nodeObject( new ReferenceNode( name, type, object, index ) );

addNodeClass( 'ReferenceNode', ReferenceNode );
4 changes: 2 additions & 2 deletions examples/jsm/nodes/accessors/UniformsNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class UniformsNode extends BufferNode {
this._elementType = null;
this._elementLength = 0;

this.updateBeforeType = NodeUpdateType.RENDER;
this.updateType = NodeUpdateType.RENDER;

this.isArrayBufferNode = true;

Expand All @@ -62,7 +62,7 @@ class UniformsNode extends BufferNode {

}

updateBefore( /*frame*/ ) {
update( /*frame*/ ) {

const { array, value } = this;

Expand Down