Skip to content
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
15 changes: 8 additions & 7 deletions examples/jsm/nodes/materials/BasicNodeMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ import { BasicNode } from './nodes/BasicNode.js';
import { NodeMaterial } from './NodeMaterial.js';
import { NodeUtils } from '../core/NodeUtils.js';

function BasicNodeMaterial() {
class BasicNodeMaterial extends NodeMaterial {

var node = new BasicNode();
constructor() {

NodeMaterial.call( this, node, node );
const node = new BasicNode();

this.type = 'BasicNodeMaterial';
super( node, node );

}
this.type = 'BasicNodeMaterial';

}

BasicNodeMaterial.prototype = Object.create( NodeMaterial.prototype );
BasicNodeMaterial.prototype.constructor = BasicNodeMaterial;
}

NodeUtils.addShortcuts( BasicNodeMaterial.prototype, 'fragment', [
'color',
Expand Down
15 changes: 8 additions & 7 deletions examples/jsm/nodes/materials/MeshStandardNodeMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ import { MeshStandardNode } from './nodes/MeshStandardNode.js';
import { NodeMaterial } from './NodeMaterial.js';
import { NodeUtils } from '../core/NodeUtils.js';

function MeshStandardNodeMaterial() {
class MeshStandardNodeMaterial extends NodeMaterial {

var node = new MeshStandardNode();
constructor() {

NodeMaterial.call( this, node, node );
const node = new MeshStandardNode();

this.type = 'MeshStandardNodeMaterial';
super( node, node );

}
this.type = 'MeshStandardNodeMaterial';

}

MeshStandardNodeMaterial.prototype = Object.create( NodeMaterial.prototype );
MeshStandardNodeMaterial.prototype.constructor = MeshStandardNodeMaterial;
}

NodeUtils.addShortcuts( MeshStandardNodeMaterial.prototype, 'properties', [
'color',
Expand Down
244 changes: 116 additions & 128 deletions examples/jsm/nodes/materials/NodeMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,219 +11,207 @@ import { ColorNode } from '../inputs/ColorNode.js';
import { PositionNode } from '../accessors/PositionNode.js';
import { RawNode } from './nodes/RawNode.js';

function NodeMaterial( vertex, fragment ) {
class NodeMaterial extends ShaderMaterial {

ShaderMaterial.call( this );
constructor( vertex, fragment ) {

this.vertex = vertex || new RawNode( new PositionNode( PositionNode.PROJECTION ) );
this.fragment = fragment || new RawNode( new ColorNode( 0xFF0000 ) );
super();

this.updaters = [];
this.vertex = vertex || new RawNode( new PositionNode( PositionNode.PROJECTION ) );
this.fragment = fragment || new RawNode( new ColorNode( 0xFF0000 ) );

}

NodeMaterial.prototype = Object.create( ShaderMaterial.prototype );
NodeMaterial.prototype.constructor = NodeMaterial;
NodeMaterial.prototype.type = 'NodeMaterial';

NodeMaterial.prototype.isNodeMaterial = true;

Object.defineProperties( NodeMaterial.prototype, {

properties: {

get: function () {
this.updaters = [];

return this.fragment.properties;
this.type = 'NodeMaterial';

}
}

},
get properties() {

needsUpdate: {
return this.fragment.properties;

set: function ( value ) {
}

if ( value === true ) this.version ++;
this.needsCompile = value;
get needsUpdate() {

},
return this.needsCompile;

get: function () {
}

return this.needsCompile;
set needsUpdate( value ) {

}
if ( value === true ) this.version ++;
this.needsCompile = value;

}

} );
onBeforeCompile( shader, renderer ) {

NodeMaterial.prototype.onBeforeCompile = function ( shader, renderer ) {
this.build( { renderer: renderer } );

this.build( { renderer: renderer } );
shader.defines = this.defines;
shader.uniforms = this.uniforms;
shader.vertexShader = this.vertexShader;
shader.fragmentShader = this.fragmentShader;

shader.defines = this.defines;
shader.uniforms = this.uniforms;
shader.vertexShader = this.vertexShader;
shader.fragmentShader = this.fragmentShader;
shader.extensionDerivatives = ( this.extensions.derivatives === true );
shader.extensionFragDepth = ( this.extensions.fragDepth === true );
shader.extensionDrawBuffers = ( this.extensions.drawBuffers === true );
shader.extensionShaderTextureLOD = ( this.extensions.shaderTextureLOD === true );

shader.extensionDerivatives = ( this.extensions.derivatives === true );
shader.extensionFragDepth = ( this.extensions.fragDepth === true );
shader.extensionDrawBuffers = ( this.extensions.drawBuffers === true );
shader.extensionShaderTextureLOD = ( this.extensions.shaderTextureLOD === true );
}

};
customProgramCacheKey() {

NodeMaterial.prototype.customProgramCacheKey = function () {
const hash = this.getHash();

var hash = this.getHash();
return hash;

return hash;
}

};
getHash() {

NodeMaterial.prototype.getHash = function () {
let hash = '{';

var hash = '{';
hash += '"vertex":' + this.vertex.getHash() + ',';
hash += '"fragment":' + this.fragment.getHash();

hash += '"vertex":' + this.vertex.getHash() + ',';
hash += '"fragment":' + this.fragment.getHash();
hash += '}';

hash += '}';
return hash;

return hash;
}

};
updateFrame( frame ) {

NodeMaterial.prototype.updateFrame = function ( frame ) {
for ( let i = 0; i < this.updaters.length; ++ i ) {

for ( var i = 0; i < this.updaters.length; ++ i ) {
frame.updateNode( this.updaters[ i ] );

frame.updateNode( this.updaters[ i ] );
}

}

};
build( params = {} ) {

NodeMaterial.prototype.build = function ( params ) {
const builder = params.builder || new NodeBuilder();

params = params || {};
builder.setMaterial( this, params.renderer );
builder.build( this.vertex, this.fragment );

var builder = params.builder || new NodeBuilder();
this.vertexShader = builder.getCode( 'vertex' );
this.fragmentShader = builder.getCode( 'fragment' );

builder.setMaterial( this, params.renderer );
builder.build( this.vertex, this.fragment );
this.defines = builder.defines;
this.uniforms = builder.uniforms;
this.extensions = builder.extensions;
this.updaters = builder.updaters;

this.vertexShader = builder.getCode( 'vertex' );
this.fragmentShader = builder.getCode( 'fragment' );
this.fog = builder.requires.fog;
this.lights = builder.requires.lights;

this.defines = builder.defines;
this.uniforms = builder.uniforms;
this.extensions = builder.extensions;
this.updaters = builder.updaters;
this.transparent = builder.requires.transparent || this.blending > NormalBlending;

this.fog = builder.requires.fog;
this.lights = builder.requires.lights;
return this;

this.transparent = builder.requires.transparent || this.blending > NormalBlending;
}

return this;
copy( source ) {

};
const uuid = this.uuid;

NodeMaterial.prototype.copy = function ( source ) {
for ( const name in source ) {

var uuid = this.uuid;
this[ name ] = source[ name ];

for ( var name in source ) {
}

this[ name ] = source[ name ];
this.uuid = uuid;

}
if ( source.userData !== undefined ) {

this.uuid = uuid;
this.userData = JSON.parse( JSON.stringify( source.userData ) );

if ( source.userData !== undefined ) {
}

this.userData = JSON.parse( JSON.stringify( source.userData ) );
return this;

}

return this;
toJSON( meta ) {

};
const isRootObject = ( meta === undefined || typeof meta === 'string' );

NodeMaterial.prototype.toJSON = function ( meta ) {
if ( isRootObject ) {

var isRootObject = ( meta === undefined || typeof meta === 'string' );
meta = {
nodes: {}
};

if ( isRootObject ) {
}

meta = {
nodes: {}
};
if ( meta && ! meta.materials ) meta.materials = {};

}
if ( ! meta.materials[ this.uuid ] ) {

if ( meta && ! meta.materials ) meta.materials = {};
const data = {};

if ( ! meta.materials[ this.uuid ] ) {
data.uuid = this.uuid;
data.type = this.type;

var data = {};
meta.materials[ data.uuid ] = data;

data.uuid = this.uuid;
data.type = this.type;
if ( this.name !== '' ) data.name = this.name;

meta.materials[ data.uuid ] = data;
if ( this.size !== undefined ) data.size = this.size;
if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;

if ( this.name !== '' ) data.name = this.name;
if ( this.blending !== NormalBlending ) data.blending = this.blending;
if ( this.flatShading === true ) data.flatShading = this.flatShading;
if ( this.side !== FrontSide ) data.side = this.side;
if ( this.vertexColors !== NoColors ) data.vertexColors = this.vertexColors;

if ( this.size !== undefined ) data.size = this.size;
if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
if ( this.depthFunc !== LessEqualDepth ) data.depthFunc = this.depthFunc;
if ( this.depthTest === false ) data.depthTest = this.depthTest;
if ( this.depthWrite === false ) data.depthWrite = this.depthWrite;

if ( this.blending !== NormalBlending ) data.blending = this.blending;
if ( this.flatShading === true ) data.flatShading = this.flatShading;
if ( this.side !== FrontSide ) data.side = this.side;
if ( this.vertexColors !== NoColors ) data.vertexColors = this.vertexColors;
if ( this.linewidth !== 1 ) data.linewidth = this.linewidth;
if ( this.dashSize !== undefined ) data.dashSize = this.dashSize;
if ( this.gapSize !== undefined ) data.gapSize = this.gapSize;
if ( this.scale !== undefined ) data.scale = this.scale;

if ( this.depthFunc !== LessEqualDepth ) data.depthFunc = this.depthFunc;
if ( this.depthTest === false ) data.depthTest = this.depthTest;
if ( this.depthWrite === false ) data.depthWrite = this.depthWrite;
if ( this.dithering === true ) data.dithering = true;

if ( this.linewidth !== 1 ) data.linewidth = this.linewidth;
if ( this.dashSize !== undefined ) data.dashSize = this.dashSize;
if ( this.gapSize !== undefined ) data.gapSize = this.gapSize;
if ( this.scale !== undefined ) data.scale = this.scale;
if ( this.wireframe === true ) data.wireframe = this.wireframe;
if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
if ( this.wireframeLinecap !== 'round' ) data.wireframeLinecap = this.wireframeLinecap;
if ( this.wireframeLinejoin !== 'round' ) data.wireframeLinejoin = this.wireframeLinejoin;

if ( this.dithering === true ) data.dithering = true;
if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = this.premultipliedAlpha;

if ( this.wireframe === true ) data.wireframe = this.wireframe;
if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
if ( this.wireframeLinecap !== 'round' ) data.wireframeLinecap = this.wireframeLinecap;
if ( this.wireframeLinejoin !== 'round' ) data.wireframeLinejoin = this.wireframeLinejoin;
if ( this.morphTargets === true ) data.morphTargets = true;
if ( this.skinning === true ) data.skinning = true;

if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = this.premultipliedAlpha;
if ( this.visible === false ) data.visible = false;
if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;

if ( this.morphTargets === true ) data.morphTargets = true;
if ( this.skinning === true ) data.skinning = true;
data.fog = this.fog;
data.lights = this.lights;

if ( this.visible === false ) data.visible = false;
if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
data.vertex = this.vertex.toJSON( meta ).uuid;
data.fragment = this.fragment.toJSON( meta ).uuid;

data.fog = this.fog;
data.lights = this.lights;
}

data.vertex = this.vertex.toJSON( meta ).uuid;
data.fragment = this.fragment.toJSON( meta ).uuid;
meta.material = this.uuid;

}
return meta;

meta.material = this.uuid;
}

return meta;
}

};
NodeMaterial.prototype.isNodeMaterial = true;

export { NodeMaterial };
Loading