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: Adds support for exporting Node Chaining, Materials and Objects3D (individually) #25553

Merged
merged 8 commits into from
Feb 27, 2023
10 changes: 2 additions & 8 deletions examples/jsm/node-editor/NodeEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { PointsEditor } from './scene/PointsEditor.js';
import { MeshEditor } from './scene/MeshEditor.js';
import { FileEditor } from './core/FileEditor.js';
import { FileURLEditor } from './core/FileURLEditor.js';
import { exportJSON } from './NodeEditorUtils.js';
import { EventDispatcher } from 'three';

Styles.icons.unlink = 'ti ti-unlink';
Expand Down Expand Up @@ -540,14 +541,7 @@ export class NodeEditor extends EventDispatcher {

saveButton.onClick( () => {

const json = JSON.stringify( this.canvas.toJSON() );

const a = document.createElement( 'a' );
const file = new Blob( [ json ], { type: 'text/plain' } );

a.href = URL.createObjectURL( file );
a.download = 'node_editor.json';
a.click();
exportJSON( this.canvas.toJSON(), 'node_editor' );

} );

Expand Down
12 changes: 12 additions & 0 deletions examples/jsm/node-editor/NodeEditorUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const exportJSON = ( object, name ) => {

const json = JSON.stringify( object );

const a = document.createElement( 'a' );
const file = new Blob( [ json ], { type: 'text/plain' } );

a.href = URL.createObjectURL( file );
a.download = name + '.json';
a.click();

};
23 changes: 16 additions & 7 deletions examples/jsm/node-editor/core/BaseNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,33 @@ export class BaseNode extends Node {
.setSerializable( false )
.setOutput( outputLength );

const closeButton = new ButtonInput().onClick( () => {
const contextButton = new ButtonInput().onClick( () => {

context.open();

} ).setIcon( 'ti ti-dots' );

const context = new ContextMenu( this.dom );
context.add( new ButtonInput( 'Remove' ).setIcon( 'ti ti-trash' ).onClick( () => {
const onAddButtons = () => {

context.removeEventListener( 'show', onAddButtons );

context.add( new ButtonInput( 'Remove' ).setIcon( 'ti ti-trash' ).onClick( () => {

this.dispose();

this.dispose();
} ) );

} ) );
};

const context = new ContextMenu( this.dom );
context.addEventListener( 'show', onAddButtons );

this.title = title;
this.closeButton = closeButton;

this.contextButton = contextButton;
this.context = context;

title.addButton( closeButton );
title.addButton( contextButton );

this.add( title );

Expand Down
8 changes: 3 additions & 5 deletions examples/jsm/node-editor/materials/BasicMaterialEditor.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { ColorInput, SliderInput, LabelElement } from '../../libs/flow.module.js';
import { BaseNode } from '../core/BaseNode.js';
import { MaterialEditor } from './MaterialEditor.js';
import { MeshBasicNodeMaterial } from 'three/nodes';

export class BasicMaterialEditor extends BaseNode {
export class BasicMaterialEditor extends MaterialEditor {

constructor() {

const material = new MeshBasicNodeMaterial();

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

this.setWidth( 300 );
sunag marked this conversation as resolved.
Show resolved Hide resolved

Expand Down Expand Up @@ -42,8 +42,6 @@ export class BasicMaterialEditor extends BaseNode {
this.opacity = opacity;
this.position = position;

this.material = material;

this.update();

}
Expand Down
25 changes: 25 additions & 0 deletions examples/jsm/node-editor/materials/MaterialEditor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { BaseNode } from '../core/BaseNode.js';
import { ButtonInput } from '../../libs/flow.module.js';
import { exportJSON } from '../NodeEditorUtils.js';

export class MaterialEditor extends BaseNode {

constructor( name, material, width = 300 ) {

super( name, 1, material, width );

this.context.add( new ButtonInput( 'Export' ).setIcon( 'ti ti-download' ).onClick( () => {

exportJSON( this.material.toJSON(), 'node_material' );

} ) );

}

get material() {

return this.value;

}

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

export class PointsMaterialEditor extends BaseNode {
export class PointsMaterialEditor extends MaterialEditor {

constructor() {

const material = new PointsNodeMaterial();

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

this.setWidth( 300 );

Expand Down Expand Up @@ -57,8 +57,6 @@ export class PointsMaterialEditor extends BaseNode {
this.position = position;
this.sizeAttenuation = sizeAttenuation;

this.material = material;

this.update();

}
Expand Down
8 changes: 3 additions & 5 deletions examples/jsm/node-editor/materials/StandardMaterialEditor.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { ColorInput, SliderInput, LabelElement } from '../../libs/flow.module.js';
import { BaseNode } from '../core/BaseNode.js';
import { MaterialEditor } from './MaterialEditor.js';
import { MeshStandardNodeMaterial } from 'three/nodes';

export class StandardMaterialEditor extends BaseNode {
export class StandardMaterialEditor extends MaterialEditor {

constructor() {

const material = new MeshStandardNodeMaterial();

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

this.setWidth( 300 );

Expand Down Expand Up @@ -70,8 +70,6 @@ export class StandardMaterialEditor extends BaseNode {
this.normal = normal;
this.position = position;

this.material = material;

this.update();

}
Expand Down