Skip to content

Commit

Permalink
Nodes: Fixes and clean up (#26931)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunag committed Oct 10, 2023
1 parent 0590d5f commit 9116475
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 42 deletions.
10 changes: 10 additions & 0 deletions examples/jsm/nodes/accessors/SkinningNode.js
Expand Up @@ -78,6 +78,16 @@ class SkinningNode extends Node {

}

generate( builder, output ) {

if ( output !== 'void' ) {

return positionLocal.build( builder, output );

}

}

update() {

this.skinnedMesh.skeleton.update();
Expand Down
49 changes: 28 additions & 21 deletions examples/jsm/nodes/core/AssignNode.js
Expand Up @@ -4,51 +4,58 @@ import { addNodeElement, nodeProxy } from '../shadernode/ShaderNode.js';

class AssignNode extends TempNode {

constructor( aNode, bNode ) {
constructor( targetNode, sourceNode ) {

super();

this.aNode = aNode;
this.bNode = bNode;
this.targetNode = targetNode;
this.sourceNode = sourceNode;

}

hasDependencies( builder ) {
hasDependencies() {

return false;

}

getNodeType( builder, output ) {

const aNode = this.aNode;
const bNode = this.bNode;

const typeA = aNode.getNodeType( builder );
const typeB = bNode.getNodeType( builder );

return typeB === 'void' ? 'void' : typeA;
return output !== 'void' ? this.targetNode.getNodeType( builder ) : 'void';

}

generate( builder, output ) {

const aNode = this.aNode;
const bNode = this.bNode;
const targetNode = this.targetNode;
const sourceNode = this.sourceNode;

const targetType = targetNode.getNodeType( builder );

const target = targetNode.build( builder );
const source = sourceNode.build( builder, targetType );

const snippet = `${ target } = ${ source }`;

if ( output === 'void' ) {

builder.addLineFlowCode( snippet );

return;

} else {

const type = this.getNodeType( builder, output );
const sourceType = sourceNode.getNodeType( builder );

const a = aNode.build( builder, type );
const b = bNode.build( builder, type );
if ( sourceType === 'void' ) {

if ( output !== 'void' ) {
builder.addLineFlowCode( snippet );

builder.addLineFlowCode( `${a} = ${b}` );
return a;
return target;

} else if ( type !== 'void' ) {
}

return builder.format( `${a} = ${b}`, type, output );
return builder.format( snippet, targetType, output );

}

Expand Down
9 changes: 3 additions & 6 deletions examples/jsm/renderers/common/Background.js
@@ -1,6 +1,6 @@
import DataMap from './DataMap.js';
import { Color, Mesh, SphereGeometry, BackSide } from 'three';
import { context, normalWorld, backgroundBlurriness, backgroundIntensity, NodeMaterial, modelViewProjection, tslFn } from '../../nodes/Nodes.js';
import { context, normalWorld, backgroundBlurriness, backgroundIntensity, NodeMaterial, modelViewProjection } from '../../nodes/Nodes.js';

let _clearAlpha;
const _clearColor = new Color();
Expand Down Expand Up @@ -59,11 +59,8 @@ class Background extends DataMap {
getSamplerLevelNode: () => backgroundBlurriness
} ).mul( backgroundIntensity );

const viewProj = tslFn( () => {
const matrix = modelViewProjection();
matrix.z = matrix.w;
return matrix;
} )();
let viewProj = modelViewProjection();
viewProj = viewProj.setZ( viewProj.w );

const nodeMaterial = new NodeMaterial();
nodeMaterial.outputNode = this.backgroundMeshNode;
Expand Down
4 changes: 2 additions & 2 deletions examples/jsm/renderers/common/Textures.js
Expand Up @@ -213,7 +213,7 @@ class Textures extends DataMap {

backend.updateTexture( texture, options );

if ( options.needsMipmaps ) backend.generateMipmaps( texture );
if ( options.needsMipmaps && texture.mipmaps.length === 0 ) backend.generateMipmaps( texture );

}

Expand Down Expand Up @@ -305,7 +305,7 @@ class Textures extends DataMap {

if ( this.isEnvironmentTexture( texture ) ) return true;

return ( texture.isCompressedTexture !== true ) /*&& ( texture.generateMipmaps === true )*/ && ( texture.minFilter !== NearestFilter ) && ( texture.minFilter !== LinearFilter );
return ( texture.isCompressedTexture === true ) || ( ( texture.minFilter !== NearestFilter ) && ( texture.minFilter !== LinearFilter ) );

}

Expand Down
20 changes: 10 additions & 10 deletions examples/webgpu_compute_particles.html
Expand Up @@ -90,9 +90,9 @@
const randY = instanceIndex.add( 2 ).hash();
const randZ = instanceIndex.add( 3 ).hash();

position.x.assign( randX.mul( 60 ).add( - 30 ) );
position.y.assign( randY.mul( 10 ) );
position.z.assign( randZ.mul( 60 ).add( - 30 ) );
position.x = randX.mul( 60 ).add( - 30 );
position.y = randY.mul( 10 );
position.z = randZ.mul( 60 ).add( - 30 );

color.assign( vec3( randX, randY, randZ ) );

Expand All @@ -105,22 +105,22 @@
const position = positionBuffer.element( instanceIndex );
const velocity = velocityBuffer.element( instanceIndex );

velocity.assign( velocity.add( vec3( 0.00, gravity, 0.00 ) ) );
position.assign( position, position.add( velocity ) );
velocity.addAssign( vec3( 0.00, gravity, 0.00 ) );
position.addAssign( velocity );

velocity.assign( velocity.mul( friction ) );
velocity.mulAssign( friction );

// floor

If( position.y.lessThan( 0 ), () => {

position.y.assign( 0 );
velocity.y.assign( velocity.y.negate().mul( bounce ) );
position.y = 0;
velocity.y = velocity.y.negate().mul( bounce );

// floor friction

velocity.x.assign( velocity.x.mul( .9 ) );
velocity.z.assign( velocity.z.mul( .9 ) );
velocity.x = velocity.x.mul( .9 );
velocity.z = velocity.z.mul( .9 );

} );

Expand Down
6 changes: 3 additions & 3 deletions examples/webgpu_compute_points.html
Expand Up @@ -82,8 +82,8 @@

const position = particle.add( velocity ).temp();

velocity.x.assign( position.x.abs().greaterThanEqual( limit.x ).cond( velocity.x.negate(), velocity.x ) );
velocity.y.assign( position.y.abs().greaterThanEqual( limit.y ).cond( velocity.y.negate(), velocity.y ) );
velocity.x = position.x.abs().greaterThanEqual( limit.x ).cond( velocity.x.negate(), velocity.x );
velocity.y = position.y.abs().greaterThanEqual( limit.y ).cond( velocity.y.negate(), velocity.y );

position.assign( position.min( limit ).max( limit.negate() ) );

Expand Down Expand Up @@ -111,7 +111,7 @@

const velocity = velocityBufferNode.element( instanceIndex );

velocity.xy.assign( vec2( velX, velY ) );
velocity.xy = vec2( velX, velY );

} );

Expand Down

0 comments on commit 9116475

Please sign in to comment.