|
@@ -1,7 +1,7 @@
|
|
|
<!DOCTYPE html>
|
|
|
<html lang="en">
|
|
|
- <head>
|
|
|
- <title>three.js webgl - node-editor playground</title>
|
|
|
+ <head>
|
|
|
+ <title>three.js webgl - node playground</title>
|
|
|
<meta charset="utf-8">
|
|
|
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
|
|
|
<link rel="stylesheet" href="fonts/open-sans/open-sans.css" type="text/css"/>
|
|
@@ -17,193 +17,199 @@
|
|
|
position: absolute;
|
|
|
top: 0;
|
|
|
left: 0;
|
|
|
- height: 50%;
|
|
|
+ height: 100%;
|
|
|
width: 100%;
|
|
|
}
|
|
|
flow {
|
|
|
position: absolute;
|
|
|
- top: 50%;
|
|
|
+ top: 0;
|
|
|
left: 0;
|
|
|
- height: 50%;
|
|
|
+ height: 100%;
|
|
|
width: 100%;
|
|
|
- background: #222;
|
|
|
box-shadow: inset 0 0 20px 0px #000000;
|
|
|
+ pointer-events: none;
|
|
|
+ }
|
|
|
+ flow f-canvas {
|
|
|
+ pointer-events: auto;
|
|
|
+ }
|
|
|
+ flow f-canvas:not(.focusing) {
|
|
|
+ background: #191919ed;
|
|
|
}
|
|
|
</style>
|
|
|
- </head>
|
|
|
- <body>
|
|
|
-
|
|
|
- <div id="info">
|
|
|
- <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> - WebGL - Node Editor ( Playground version )<br />
|
|
|
- </div>
|
|
|
-
|
|
|
- <script async src="https://unpkg.com/[email protected]/dist/es-module-shims.js"></script>
|
|
|
-
|
|
|
- <script type="importmap">
|
|
|
- {
|
|
|
- "imports": {
|
|
|
- "three": "../build/three.module.js",
|
|
|
- "three/addons/": "./jsm/",
|
|
|
- "three/nodes": "./jsm/nodes/Nodes.js"
|
|
|
+ </head>
|
|
|
+ <body>
|
|
|
+
|
|
|
+ <script async src="https://unpkg.com/[email protected]/dist/es-module-shims.js"></script>
|
|
|
+
|
|
|
+ <script type="importmap">
|
|
|
+ {
|
|
|
+ "imports": {
|
|
|
+ "three": "../build/three.module.js",
|
|
|
+ "three/addons/": "./jsm/",
|
|
|
+ "three/nodes": "./jsm/nodes/Nodes.js"
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- </script>
|
|
|
+ </script>
|
|
|
|
|
|
- <script type="module">
|
|
|
+ <script type="module">
|
|
|
|
|
|
- import * as THREE from 'three';
|
|
|
- import * as Nodes from 'three/nodes';
|
|
|
+ import * as THREE from 'three';
|
|
|
+ import * as Nodes from 'three/nodes';
|
|
|
|
|
|
- import { nodeFrame } from 'three/addons/renderers/webgl/nodes/WebGLNodes.js';
|
|
|
+ import { nodeFrame } from 'three/addons/renderers/webgl/nodes/WebGLNodes.js';
|
|
|
|
|
|
- import { NodeEditor } from 'three/addons/node-editor/NodeEditor.js';
|
|
|
- import { MeshEditor } from 'three/addons/node-editor/scene/MeshEditor.js';
|
|
|
+ import { NodeEditor } from 'three/addons/node-editor/NodeEditor.js';
|
|
|
+ import { MeshEditor } from 'three/addons/node-editor/scene/MeshEditor.js';
|
|
|
+ import { StandardMaterialEditor } from 'three/addons/node-editor/materials/StandardMaterialEditor.js';
|
|
|
|
|
|
- import Stats from 'three/addons/libs/stats.module.js';
|
|
|
+ import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
|
|
|
+ import { FBXLoader } from 'three/addons/loaders/FBXLoader.js';
|
|
|
|
|
|
- import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
|
|
|
- import { FBXLoader } from 'three/addons/loaders/FBXLoader.js';
|
|
|
+ let camera, scene, renderer;
|
|
|
+ let model;
|
|
|
+ let nodeEditor;
|
|
|
|
|
|
- let stats;
|
|
|
- let camera, scene, renderer;
|
|
|
- let model;
|
|
|
+ init();
|
|
|
+ animate();
|
|
|
|
|
|
- init();
|
|
|
- animate();
|
|
|
+ function init() {
|
|
|
|
|
|
- function init() {
|
|
|
+ camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 5000 );
|
|
|
+ camera.position.set( 0.0, 300, 400 * 3 );
|
|
|
|
|
|
- camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 5000 );
|
|
|
- camera.position.set( 0.0, 300, 400 * 3 );
|
|
|
+ scene = new THREE.Scene();
|
|
|
+ scene.background = new THREE.Color( 0x333333 );
|
|
|
|
|
|
- scene = new THREE.Scene();
|
|
|
- scene.background = new THREE.Color( 0x333333 );
|
|
|
+ // Lights
|
|
|
|
|
|
- // Lights
|
|
|
+ const topLight = new THREE.PointLight( 0xF4F6F0, 1 );
|
|
|
+ topLight.position.set( 0, 1000, 1000 );
|
|
|
+ scene.add( topLight );
|
|
|
|
|
|
- const topLight = new THREE.PointLight( 0xF4F6F0, 1 );
|
|
|
- topLight.position.set( 0, 1000, 1000 );
|
|
|
- scene.add( topLight );
|
|
|
+ const backLight = new THREE.PointLight( 0x0c1445, 1 );
|
|
|
+ backLight.position.set( - 100, 20, - 260 );
|
|
|
+ scene.add( backLight );
|
|
|
|
|
|
- const backLight = new THREE.PointLight( 0x0c1445, 1 );
|
|
|
- backLight.position.set( - 100, 20, - 260 );
|
|
|
- scene.add( backLight );
|
|
|
+ renderer = new THREE.WebGLRenderer( { antialias: true } );
|
|
|
+ document.body.appendChild( renderer.domElement );
|
|
|
+ renderer.outputEncoding = THREE.sRGBEncoding;
|
|
|
+ renderer.toneMapping = THREE.LinearToneMapping;
|
|
|
+ renderer.toneMappingExposure = 4000;
|
|
|
+ renderer.physicallyCorrectLights = true;
|
|
|
|
|
|
- renderer = new THREE.WebGLRenderer( { antialias: true } );
|
|
|
- document.body.appendChild( renderer.domElement );
|
|
|
- renderer.outputEncoding = THREE.sRGBEncoding;
|
|
|
- renderer.toneMapping = THREE.LinearToneMapping;
|
|
|
- renderer.toneMappingExposure = 4000;
|
|
|
- renderer.physicallyCorrectLights = true;
|
|
|
+ renderer.domElement.className = 'renderer';
|
|
|
|
|
|
- renderer.domElement.className = 'renderer';
|
|
|
+ //
|
|
|
|
|
|
- //
|
|
|
+ const controls = new OrbitControls( camera, renderer.domElement );
|
|
|
+ controls.minDistance = 500;
|
|
|
+ controls.maxDistance = 3000;
|
|
|
+
|
|
|
+ window.addEventListener( 'resize', onWindowResize );
|
|
|
|
|
|
- stats = new Stats();
|
|
|
- document.body.appendChild( stats.dom );
|
|
|
+ initEditor();
|
|
|
|
|
|
- const controls = new OrbitControls( camera, renderer.domElement );
|
|
|
- controls.minDistance = 500;
|
|
|
- controls.maxDistance = 3000;
|
|
|
+ onWindowResize();
|
|
|
|
|
|
- window.addEventListener( 'resize', onWindowResize );
|
|
|
+ }
|
|
|
|
|
|
- onWindowResize();
|
|
|
+ function initEditor() {
|
|
|
|
|
|
- initEditor();
|
|
|
+ nodeEditor = new NodeEditor( scene );
|
|
|
|
|
|
- }
|
|
|
+ const reset = () => {
|
|
|
|
|
|
- function initEditor() {
|
|
|
+ const meshEditor = new MeshEditor( model );
|
|
|
+ const materialEditor = new StandardMaterialEditor();
|
|
|
|
|
|
- const nodeEditor = new NodeEditor( scene );
|
|
|
+ nodeEditor.add( meshEditor );
|
|
|
+ nodeEditor.add( materialEditor );
|
|
|
+ nodeEditor.centralizeNode( meshEditor );
|
|
|
|
|
|
- nodeEditor.addEventListener( 'new', () => {
|
|
|
+ const { x, y } = meshEditor.getPosition();
|
|
|
|
|
|
- const materialEditor = new MeshEditor( model );
|
|
|
+ meshEditor.setPosition( x + 250, y );
|
|
|
+ materialEditor.setPosition( x - 250, y );
|
|
|
|
|
|
- nodeEditor.add( materialEditor );
|
|
|
- nodeEditor.centralizeNode( materialEditor );
|
|
|
+ meshEditor.material.connect( materialEditor );
|
|
|
|
|
|
- } );
|
|
|
+ };
|
|
|
|
|
|
- document.body.appendChild( nodeEditor.domElement );
|
|
|
+ nodeEditor.addEventListener( 'new', reset );
|
|
|
|
|
|
- const loaderFBX = new FBXLoader();
|
|
|
- loaderFBX.load( 'models/fbx/stanford-bunny.fbx', ( object ) => {
|
|
|
+ document.body.appendChild( nodeEditor.domElement );
|
|
|
|
|
|
- const defaultMaterial = new Nodes.MeshBasicNodeMaterial();
|
|
|
- defaultMaterial.colorNode = new Nodes.UniformNode( 0 );
|
|
|
+ const loaderFBX = new FBXLoader();
|
|
|
+ loaderFBX.load( 'models/fbx/stanford-bunny.fbx', ( object ) => {
|
|
|
|
|
|
- const sphere = new THREE.Mesh( new THREE.SphereGeometry( 200, 32, 16 ), defaultMaterial );
|
|
|
- sphere.name = 'Sphere';
|
|
|
- sphere.position.set( 500, 0, - 500 );
|
|
|
- scene.add( sphere );
|
|
|
+ const defaultMaterial = new Nodes.MeshBasicNodeMaterial();
|
|
|
+ defaultMaterial.colorNode = new Nodes.UniformNode( 0 );
|
|
|
|
|
|
- const box = new THREE.Mesh( new THREE.BoxGeometry( 200, 200, 200 ), defaultMaterial );
|
|
|
- box.name = 'Box';
|
|
|
- box.position.set( - 500, 0, - 500 );
|
|
|
- scene.add( box );
|
|
|
+ const sphere = new THREE.Mesh( new THREE.SphereGeometry( 200, 32, 16 ), defaultMaterial );
|
|
|
+ sphere.name = 'Sphere';
|
|
|
+ sphere.position.set( 500, 0, - 500 );
|
|
|
+ scene.add( sphere );
|
|
|
|
|
|
- const defaultPointsMaterial = new Nodes.PointsNodeMaterial();
|
|
|
- defaultPointsMaterial.colorNode = new Nodes.UniformNode( 0 );
|
|
|
+ const box = new THREE.Mesh( new THREE.BoxGeometry( 200, 200, 200 ), defaultMaterial );
|
|
|
+ box.name = 'Box';
|
|
|
+ box.position.set( - 500, 0, - 500 );
|
|
|
+ scene.add( box );
|
|
|
|
|
|
- const torusKnot = new THREE.Points( new THREE.TorusKnotGeometry( 100, 30, 100, 16 ), defaultPointsMaterial );
|
|
|
- torusKnot.name = 'Torus Knot ( Points )';
|
|
|
- torusKnot.position.set( 0, 0, - 500 );
|
|
|
- scene.add( torusKnot );
|
|
|
+ const defaultPointsMaterial = new Nodes.PointsNodeMaterial();
|
|
|
+ defaultPointsMaterial.colorNode = new Nodes.UniformNode( 0 );
|
|
|
|
|
|
- model = object.children[ 0 ];
|
|
|
- model.position.set( 0, 0, 10 );
|
|
|
- model.scale.setScalar( 1 );
|
|
|
- model.material = defaultMaterial;
|
|
|
- scene.add( model );
|
|
|
+ const torusKnot = new THREE.Points( new THREE.TorusKnotGeometry( 100, 30, 100, 16 ), defaultPointsMaterial );
|
|
|
+ torusKnot.name = 'Torus Knot ( Points )';
|
|
|
+ torusKnot.position.set( 0, 0, - 500 );
|
|
|
+ scene.add( torusKnot );
|
|
|
|
|
|
- const materialEditor = new MeshEditor( model );
|
|
|
+ model = object.children[ 0 ];
|
|
|
+ model.position.set( 0, 0, 10 );
|
|
|
+ model.scale.setScalar( 1 );
|
|
|
+ model.material = defaultMaterial;
|
|
|
+ scene.add( model );
|
|
|
|
|
|
- nodeEditor.add( materialEditor );
|
|
|
- nodeEditor.centralizeNode( materialEditor );
|
|
|
+ reset();
|
|
|
|
|
|
- } );
|
|
|
+ } );
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- function onWindowResize() {
|
|
|
+ function onWindowResize() {
|
|
|
|
|
|
- const width = window.innerWidth;
|
|
|
- const height = window.innerHeight / 2;
|
|
|
+ const width = window.innerWidth;
|
|
|
+ const height = window.innerHeight;
|
|
|
|
|
|
- camera.aspect = width / height;
|
|
|
- camera.updateProjectionMatrix();
|
|
|
+ camera.aspect = width / height;
|
|
|
+ camera.updateProjectionMatrix();
|
|
|
|
|
|
- renderer.setSize( width, height );
|
|
|
+ renderer.setSize( width, height );
|
|
|
|
|
|
- }
|
|
|
+ nodeEditor.setSize( width, height );
|
|
|
|
|
|
- //
|
|
|
+ }
|
|
|
|
|
|
- function animate() {
|
|
|
+ //
|
|
|
|
|
|
- requestAnimationFrame( animate );
|
|
|
+ function animate() {
|
|
|
|
|
|
- nodeFrame.update();
|
|
|
+ requestAnimationFrame( animate );
|
|
|
|
|
|
- render();
|
|
|
+ nodeFrame.update();
|
|
|
|
|
|
- stats.update();
|
|
|
+ render();
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- function render() {
|
|
|
+ function render() {
|
|
|
|
|
|
- //if ( model ) model.rotation.y = performance.now() / 5000;
|
|
|
+ //if ( model ) model.rotation.y = performance.now() / 5000;
|
|
|
|
|
|
- renderer.render( scene, camera );
|
|
|
+ renderer.render( scene, camera );
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- </script>
|
|
|
+ </script>
|
|
|
|
|
|
- </body>
|
|
|
+ </body>
|
|
|
</html>
|