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

NodeEditor: BasicMaterialEditor and PointsEditor #23339

Merged
merged 1 commit into from
Jan 26, 2022
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
44 changes: 39 additions & 5 deletions examples/jsm/node-editor/NodeEditor.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Styles, Canvas, CircleMenu, ButtonInput, ContextMenu, Tips, Search, Loader } from '../libs/flow.module.js';
import { BasicMaterialEditor } from './materials/BasicMaterialEditor.js';
import { StandardMaterialEditor } from './materials/StandardMaterialEditor.js';
import { PointsMaterialEditor } from './materials/PointsMaterialEditor.js';
import { OperatorEditor } from './math/OperatorEditor.js';
import { NormalizeEditor } from './math/NormalizeEditor.js';
import { InvertEditor } from './math/InvertEditor.js';
Expand All @@ -23,6 +25,7 @@ import { OscillatorEditor } from './utils/OscillatorEditor.js';
import { SplitEditor } from './utils/SplitEditor.js';
import { JoinEditor } from './utils/JoinEditor.js';
import { CheckerEditor } from './procedural/CheckerEditor.js';
import { PointsEditor } from './scene/PointsEditor.js';
import { MeshEditor } from './scene/MeshEditor.js';
import { EventDispatcher } from 'three';

Expand Down Expand Up @@ -199,17 +202,30 @@ export const NodeList = [
name: 'Material',
icon: 'circles',
children: [
{
name: 'Basic Material',
icon: 'circle',
nodeClass: BasicMaterialEditor
},
{
name: 'Standard Material',
icon: 'circle',
nodeClass: StandardMaterialEditor
},
{
name: 'Points Material',
icon: 'circle-dotted',
nodeClass: PointsMaterialEditor
}
]
}
];

export const ClassLib = {
BasicMaterialEditor,
StandardMaterialEditor,
PointsMaterialEditor,
PointsEditor,
MeshEditor,
OperatorEditor,
NormalizeEditor,
Expand Down Expand Up @@ -524,17 +540,35 @@ export class NodeEditor extends EventDispatcher {

object3d.traverse( ( obj3d ) => {

if ( obj3d.isMesh === true ) {
if ( obj3d.isMesh === true || obj3d.isPoints === true ) {

let prefix = null;
let icon = null;
let editorClass = null;

if ( obj3d.isMesh === true ) {

prefix = 'Mesh';
icon = 'ti ti-3d-cube-sphere';
editorClass = MeshEditor;

} else if ( obj3d.isPoints === true ) {

prefix = 'Points';
icon = 'ti ti-border-none';
editorClass = PointsEditor;

}

const button = new ButtonInput( `Mesh - ${obj3d.name}` );
button.setIcon( 'ti ti-3d-cube-sphere' );
const button = new ButtonInput( `${prefix} - ${obj3d.name}` );
button.setIcon( icon );
button.addEventListener( 'complete', () => {

for ( const node of this.canvas.nodes ) {

if ( node.value === obj3d ) {

// not duplicated node
// prevent duplicated node

this.canvas.select( node );

Expand All @@ -544,7 +578,7 @@ export class NodeEditor extends EventDispatcher {

}

const node = new MeshEditor( obj3d );
const node = new editorClass( obj3d );

this.add( node );

Expand Down
87 changes: 87 additions & 0 deletions examples/jsm/node-editor/materials/BasicMaterialEditor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { ColorInput, SliderInput, LabelElement } from '../../libs/flow.module.js';
import { BaseNode } from '../core/BaseNode.js';
import { MeshBasicNodeMaterial } from '../../renderers/nodes/Nodes.js';
import * as THREE from 'three';

export class BasicMaterialEditor extends BaseNode {

constructor() {

const material = new MeshBasicNodeMaterial();

super( 'Basic Material', 1, material );

this.setWidth( 300 );

const color = new LabelElement( 'color' ).setInput( 3 );
const opacity = new LabelElement( 'opacity' ).setInput( 1 );
const position = new LabelElement( 'position' ).setInput( 3 );

color.add( new ColorInput( material.color.getHex() ).onChange( ( input ) => {

material.color.setHex( input.getValue() );

} ) );

opacity.add( new SliderInput( material.opacity, 0, 1 ).onChange( ( input ) => {

material.opacity = input.getValue();

this.updateTransparent();

} ) );

color.onConnect( () => this.update(), true );
opacity.onConnect( () => this.update(), true );
position.onConnect( () => this.update(), true );

this.add( color )
.add( opacity )
.add( position );

this.color = color;
this.opacity = opacity;
this.position = position;

this.material = material;

this.update();

}

update() {

const { material, color, opacity, position } = this;

color.setEnabledInputs( ! color.getLinkedObject() );
opacity.setEnabledInputs( ! opacity.getLinkedObject() );

material.colorNode = color.getLinkedObject();
material.opacityNode = opacity.getLinkedObject() || null;

material.positionNode = position.getLinkedObject() || null;

material.dispose();

this.updateTransparent();

// TODO: Fix on NodeMaterial System
material.customProgramCacheKey = () => {

return THREE.MathUtils.generateUUID();

};

}

updateTransparent() {

const { material, opacity } = this;

material.transparent = opacity.getLinkedObject() || material.opacity < 1 ? true : false;

opacity.setIcon( material.transparent ? 'ti ti-layers-intersect' : 'ti ti-layers-subtract' );

}

}
97 changes: 97 additions & 0 deletions examples/jsm/node-editor/materials/PointsMaterialEditor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { ColorInput, SliderInput, LabelElement } from '../../libs/flow.module.js';
import { BaseNode } from '../core/BaseNode.js';
import { PointsNodeMaterial } from '../../renderers/nodes/Nodes.js';
import * as THREE from 'three';

export class PointsMaterialEditor extends BaseNode {

constructor() {

const material = new PointsNodeMaterial( {
depthWrite: false,
transparent: true,
sizeAttenuation: true,
blending: THREE.AdditiveBlending
} );

super( 'Points Material', 1, material );

this.setWidth( 300 );

const color = new LabelElement( 'color' ).setInput( 3 );
const opacity = new LabelElement( 'opacity' ).setInput( 1 );
const size = new LabelElement( 'size' ).setInput( 1 );
const position = new LabelElement( 'position' ).setInput( 3 );

color.add( new ColorInput( material.color.getHex() ).onChange( ( input ) => {

material.color.setHex( input.getValue() );

} ) );

opacity.add( new SliderInput( material.opacity, 0, 1 ).onChange( ( input ) => {

material.opacity = input.getValue();

this.updateTransparent();

} ) );

color.onConnect( () => this.update(), true );
opacity.onConnect( () => this.update(), true );
size.onConnect(() => this.update(), true );
position.onConnect(() => this.update(), true );

this.add( color )
.add( opacity )
.add( size )
.add( position );

this.color = color;
this.opacity = opacity;
this.size = size;
this.position = position;

this.material = material;

this.update();

}

update() {

const { material, color, opacity, size, position } = this;

color.setEnabledInputs( ! color.getLinkedObject() );
opacity.setEnabledInputs( ! opacity.getLinkedObject() );

material.colorNode = color.getLinkedObject();
material.opacityNode = opacity.getLinkedObject() || null;

material.sizeNode = size.getLinkedObject() || null;
material.positionNode = position.getLinkedObject() || null;

material.dispose();

this.updateTransparent();

// TODO: Fix on NodeMaterial System
material.customProgramCacheKey = () => {

return THREE.MathUtils.generateUUID();

};

}

updateTransparent() {

const { material, opacity } = this;

material.transparent = opacity.getLinkedObject() || material.opacity < 1 ? true : false;

opacity.setIcon( material.transparent ? 'ti ti-layers-intersect' : 'ti ti-layers-subtract' );

}

}
Loading