123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <title>three.js - WebGPU - Selective Lights</title>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
- <link type="text/css" rel="stylesheet" href="main.css">
- <link rel="stylesheet" href="fonts/open-sans/open-sans.css" type="text/css"/>
- <link rel="stylesheet" href="fonts/tabler-icons/tabler-icons.min.css" type="text/css"/>
- <!-- WebGPU (For Chrome 94-101), expires 09/01/2022 -->
- <meta http-equiv="origin-trial" content="AoS1pSJwCV3KRe73TO0YgJkK9FZ/qhmvKeafztp0ofiE8uoGrnKzfxGVKKICvoBfL8dgE0zpkp2g/oEJNS0fDgkAAABeeyJvcmlnaW4iOiJodHRwczovL3RocmVlanMub3JnOjQ0MyIsImZlYXR1cmUiOiJXZWJHUFUiLCJleHBpcnkiOjE2NTI4MzE5OTksImlzU3ViZG9tYWluIjp0cnVlfQ==">
- <style>
- body {
- overflow: hidden;
- width: 100%;
- height: 100%;
- }
- .renderer {
- position: absolute;
- top: 0;
- left: 0;
- height: 50%;
- width: 100%;
- }
- flow {
- position: absolute;
- top: 50%;
- left: 0;
- height: 50%;
- width: 100%;
- background: #222;
- box-shadow: inset 0 0 20px 0px #000000;
- }
- </style>
- </head>
- <body>
- <div id="info">
- <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> - WebGPU - 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"
- }
- }
- </script>
- <script type="module">
- import * as THREE from 'three';
- import WebGPU from './jsm/capabilities/WebGPU.js';
- import WebGPURenderer from './jsm/renderers/webgpu/WebGPURenderer.js';
- import { NodeEditor } from './jsm/node-editor/NodeEditor.js';
- import { StandardMaterialEditor } from './jsm/node-editor/materials/StandardMaterialEditor.js';
- import { MeshEditor } from './jsm/node-editor/scene/MeshEditor.js';
- import * as Nodes from './jsm/renderers/nodes/Nodes.js';
- import Stats from './jsm/libs/stats.module.js';
- import { OrbitControls } from './jsm/controls/OrbitControls.js';
- import { FBXLoader } from './jsm/loaders/FBXLoader.js';
- let stats;
- let camera, scene, renderer;
- let model;
- let nodeLights;
- init().then( animate ).catch( error => console.error( error ) );
- async function init() {
- if ( WebGPU.isAvailable() === false ) {
- document.body.appendChild( WebGPU.getErrorMessage() );
- throw new Error( 'No WebGPU support' );
- }
- 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 );
- // Lights
- const topLight = new THREE.PointLight( 0xF4F6F0, 1 );
- topLight.position.set( 0, 100000, 100000 );
- scene.add( topLight );
- const backLight = new THREE.PointLight( 0x0c1445, 1.4 );
- backLight.position.set( - 100, 20, - 260 );
- scene.add( backLight );
- nodeLights = Nodes.LightsNode.fromLights( [ topLight, backLight ] );
- renderer = new WebGPURenderer();
- renderer.setPixelRatio( window.devicePixelRatio );
- renderer.setSize( window.innerWidth, window.innerHeight );
- document.body.appendChild( renderer.domElement );
- renderer.outputEncoding = THREE.sRGBEncoding;
- renderer.domElement.className = 'renderer';
- //
- stats = new Stats();
- document.body.appendChild( stats.dom );
- const controls = new OrbitControls( camera, renderer.domElement );
- controls.minDistance = 500;
- controls.maxDistance = 3000;
- window.addEventListener( 'resize', onWindowResize );
- onWindowResize();
- initEditor();
- return renderer.init();
- }
- function initEditor() {
- const nodeEditor = new NodeEditor( scene );
- nodeEditor.addEventListener( 'new', () => {
- const materialEditor = new MeshEditor( model );
- nodeEditor.add( materialEditor );
- nodeEditor.centralizeNode( materialEditor );
- } );
- nodeEditor.addEventListener( 'add', ( e ) => {
- const node = e.node;
- if ( node.value !== null && node.value.isMaterial === true ) {
- const material = node.value;
- material.lightNode = nodeLights;
- }
- } );
- document.body.appendChild( nodeEditor.domElement );
- const loaderFBX = new FBXLoader();
- loaderFBX.load( 'models/fbx/stanford-bunny.fbx', ( object ) => {
- const defaultMaterial = new Nodes.MeshBasicNodeMaterial();
- defaultMaterial.colorNode = new Nodes.FloatNode( 0 );
- 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 box = new THREE.Mesh( new THREE.BoxGeometry( 200, 200, 200 ), defaultMaterial ) ;
- box.name = 'Box';
- box.position.set( -500, 0, -500 );
- scene.add( box );
- const defaultPointsMaterial = new Nodes.PointsNodeMaterial();
- defaultPointsMaterial.colorNode = new Nodes.FloatNode( 0 );
- 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 );
- model = object.children[ 0 ];
- model.position.set( 0, 0, 10 );
- model.scale.setScalar( 1 );
- model.material = defaultMaterial;
- scene.add( model );
- const materialEditor = new MeshEditor( model );
- nodeEditor.add( materialEditor );
- nodeEditor.centralizeNode( materialEditor );
- } );
- }
- function onWindowResize() {
- const width = window.innerWidth;
- const height = window.innerHeight / 2;
- camera.aspect = width / height;
- camera.updateProjectionMatrix();
- renderer.setSize( width, height );
- }
- //
- function animate() {
- requestAnimationFrame( animate );
- render();
- stats.update();
- }
- function render() {
- //if ( model ) model.rotation.y = performance.now() / 5000;
- renderer.render( scene, camera );
- }
- </script>
- </body>
- </html>
|