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

Examples: Move jsm/nodes to ES6. #21801

Merged
merged 1 commit into from
May 8, 2021
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
242 changes: 122 additions & 120 deletions examples/jsm/nodes/accessors/CameraNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,232 +3,234 @@ import { FunctionNode } from '../core/FunctionNode.js';
import { FloatNode } from '../inputs/FloatNode.js';
import { PositionNode } from '../accessors/PositionNode.js';

function CameraNode( scope, camera ) {
class CameraNode extends TempNode {

TempNode.call( this, 'v3' );
constructor( scope, camera ) {

this.setScope( scope || CameraNode.POSITION );
this.setCamera( camera );
super( 'v3' );

}

CameraNode.Nodes = ( function () {

var depthColor = new FunctionNode( [
'float depthColor( float mNear, float mFar ) {',

' #ifdef USE_LOGDEPTHBUF_EXT',
this.setScope( scope || CameraNode.POSITION );
this.setCamera( camera );

' float depth = gl_FragDepthEXT / gl_FragCoord.w;',
}

' #else',
setCamera( camera ) {

' float depth = gl_FragCoord.z / gl_FragCoord.w;',
this.camera = camera;
this.updateFrame = camera !== undefined ? this.onUpdateFrame : undefined;

' #endif',
}

' return 1.0 - smoothstep( mNear, mFar, depth );',
setScope( scope ) {

'}'
].join( '\n' ) );
switch ( this.scope ) {

return {
depthColor: depthColor
};
case CameraNode.DEPTH:

} )();
delete this.near;
delete this.far;

CameraNode.POSITION = 'position';
CameraNode.DEPTH = 'depth';
CameraNode.TO_VERTEX = 'toVertex';

CameraNode.prototype = Object.create( TempNode.prototype );
CameraNode.prototype.constructor = CameraNode;
CameraNode.prototype.nodeType = 'Camera';
break;

CameraNode.prototype.setCamera = function ( camera ) {
}

this.camera = camera;
this.updateFrame = camera !== undefined ? this.onUpdateFrame : undefined;
this.scope = scope;

};
switch ( scope ) {

CameraNode.prototype.setScope = function ( scope ) {
case CameraNode.DEPTH:

switch ( this.scope ) {
const camera = this.camera;

case CameraNode.DEPTH:
this.near = new FloatNode( camera ? camera.near : 1 );
this.far = new FloatNode( camera ? camera.far : 1200 );

delete this.near;
delete this.far;
break;

break;
}

}

this.scope = scope;
getType( /* builder */ ) {

switch ( scope ) {
switch ( this.scope ) {

case CameraNode.DEPTH:
case CameraNode.DEPTH:

var camera = this.camera;
return 'f';

this.near = new FloatNode( camera ? camera.near : 1 );
this.far = new FloatNode( camera ? camera.far : 1200 );
}

break;
return this.type;

}

};
getUnique( /* builder */ ) {

switch ( this.scope ) {

CameraNode.prototype.getType = function ( /* builder */ ) {
case CameraNode.DEPTH:
case CameraNode.TO_VERTEX:

switch ( this.scope ) {
return true;

case CameraNode.DEPTH:
}

return 'f';
return false;

}

return this.type;
getShared( /* builder */ ) {

};
switch ( this.scope ) {

CameraNode.prototype.getUnique = function ( /* builder */ ) {
case CameraNode.POSITION:

switch ( this.scope ) {
return false;

case CameraNode.DEPTH:
case CameraNode.TO_VERTEX:
}

return true;
return true;

}

return false;
generate( builder, output ) {

};
let result;

CameraNode.prototype.getShared = function ( /* builder */ ) {
switch ( this.scope ) {

switch ( this.scope ) {
case CameraNode.POSITION:

case CameraNode.POSITION:
result = 'cameraPosition';

return false;
break;

}
case CameraNode.DEPTH:

return true;
const depthColor = builder.include( CameraNode.Nodes.depthColor );

};
result = depthColor + '( ' + this.near.build( builder, 'f' ) + ', ' + this.far.build( builder, 'f' ) + ' )';

CameraNode.prototype.generate = function ( builder, output ) {
break;

case CameraNode.TO_VERTEX:

var result;
result = 'normalize( ' + new PositionNode( PositionNode.WORLD ).build( builder, 'v3' ) + ' - cameraPosition )';

switch ( this.scope ) {
break;

case CameraNode.POSITION:
}

result = 'cameraPosition';
return builder.format( result, this.getType( builder ), output );

break;
}

case CameraNode.DEPTH:
onUpdateFrame( /* frame */ ) {

var depthColor = builder.include( CameraNode.Nodes.depthColor );
switch ( this.scope ) {

result = depthColor + '( ' + this.near.build( builder, 'f' ) + ', ' + this.far.build( builder, 'f' ) + ' )';
case CameraNode.DEPTH:

break;
const camera = this.camera;

case CameraNode.TO_VERTEX:
this.near.value = camera.near;
this.far.value = camera.far;

result = 'normalize( ' + new PositionNode( PositionNode.WORLD ).build( builder, 'v3' ) + ' - cameraPosition )';
break;

break;
}

}

return builder.format( result, this.getType( builder ), output );
copy( source ) {

};
super.copy( source );

CameraNode.prototype.onUpdateFrame = function ( /* frame */ ) {
this.setScope( source.scope );

switch ( this.scope ) {
if ( source.camera ) {

case CameraNode.DEPTH:
this.setCamera( source.camera );

var camera = this.camera;
}

switch ( source.scope ) {

this.near.value = camera.near;
this.far.value = camera.far;
case CameraNode.DEPTH:

break;
this.near.number = source.near;
this.far.number = source.far;

break;

}

return this;

}

};
toJSON( meta ) {

CameraNode.prototype.copy = function ( source ) {
let data = this.getJSONNode( meta );

TempNode.prototype.copy.call( this, source );
if ( ! data ) {

this.setScope( source.scope );
data = this.createJSONNode( meta );

if ( source.camera ) {
data.scope = this.scope;

this.setCamera( source.camera );
if ( this.camera ) data.camera = this.camera.uuid;

}
switch ( this.scope ) {

switch ( source.scope ) {
case CameraNode.DEPTH:

case CameraNode.DEPTH:
data.near = this.near.value;
data.far = this.far.value;

this.near.number = source.near;
this.far.number = source.far;
break;

break;
}

}
}

return this;
return data;

};
}

CameraNode.prototype.toJSON = function ( meta ) {
}

var data = this.getJSONNode( meta );
CameraNode.Nodes = ( function () {

if ( ! data ) {
const depthColor = new FunctionNode( [
'float depthColor( float mNear, float mFar ) {',

data = this.createJSONNode( meta );
' #ifdef USE_LOGDEPTHBUF_EXT',

data.scope = this.scope;
' float depth = gl_FragDepthEXT / gl_FragCoord.w;',

if ( this.camera ) data.camera = this.camera.uuid;
' #else',

switch ( this.scope ) {
' float depth = gl_FragCoord.z / gl_FragCoord.w;',

case CameraNode.DEPTH:
' #endif',

data.near = this.near.value;
data.far = this.far.value;
' return 1.0 - smoothstep( mNear, mFar, depth );',

break;
'}'
].join( '\n' ) );

}
return {
depthColor: depthColor
};

}
} )();

return data;
CameraNode.POSITION = 'position';
CameraNode.DEPTH = 'depth';
CameraNode.TO_VERTEX = 'toVertex';

};
CameraNode.prototype.nodeType = 'Camera';

export { CameraNode };
Loading