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

Nodes: Fixes and clean up #26931

Merged
merged 1 commit into from
Oct 10, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't we just return positionLocal in setup? Or would it not work in this way?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will not work if the output is void, but this treatment can certainly be done automatically soon.


}

}

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