123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>Three.js Material Browser</title>
- <link rel="shortcut icon" href="../../files/favicon.ico" />
- <link rel="stylesheet" type="text/css" href="../../files/main.css">
- <style>
- canvas {
- display: block;
- width: 100%;
- height: 100%;
- }
- #newWindow {
- display: block;
- position: absolute;
- bottom: 0.3em;
- left: 0.5em;
- color: #fff;
- }
- </style>
- </head>
- <body>
- <a id='newWindow' href='./material-browser.html' target='_blank'>Open in New Window</a>
- <script type="module">
- import {
- AdditiveBlending, CustomBlending, MultiplyBlending, NormalBlending, NoBlending, SubtractiveBlending,
- AddEquation, ReverseSubtractEquation, SubtractEquation,
- AddOperation, MixOperation, MultiplyOperation,
- AmbientLight,
- Color,
- CubeTextureLoader,
- CubeRefractionMapping,
- DoubleSide, FrontSide, BackSide,
- DstAlphaFactor, DstColorFactor, OneFactor, OneMinusDstAlphaFactor, OneMinusDstColorFactor, OneMinusSrcAlphaFactor, OneMinusSrcColorFactor, SrcAlphaFactor, SrcAlphaSaturateFactor, SrcColorFactor, ZeroFactor,
- Float32BufferAttribute,
- Fog,
- LineBasicMaterial,
- Mesh,
- MeshBasicMaterial,
- MeshDepthMaterial,
- MeshLambertMaterial,
- MeshMatcapMaterial,
- MeshNormalMaterial,
- MeshPhongMaterial,
- MeshPhysicalMaterial,
- MeshStandardMaterial,
- MeshToonMaterial,
- NearestFilter,
- PerspectiveCamera,
- PointLight,
- RepeatWrapping,
- RGBFormat,
- Scene,
- TextureLoader,
- TorusKnotBufferGeometry,
- VertexColors, NoColors,
- WebGLRenderer
- } from "../../build/three.module.js";
- import { GUI } from '../../examples/jsm/libs/dat.gui.module.js';
- /**
- * @author TatumCreative (Greg Tatum) / http://gregtatum.com/
- */
- var constants = {
- combine: {
- 'THREE.MultiplyOperation': MultiplyOperation,
- 'THREE.MixOperation': MixOperation,
- 'THREE.AddOperation': AddOperation
- },
- side: {
- 'THREE.FrontSide': FrontSide,
- 'THREE.BackSide': BackSide,
- 'THREE.DoubleSide': DoubleSide
- },
- colors: {
- 'THREE.NoColors': NoColors,
- 'THREE.VertexColors': VertexColors
- },
- blendingMode: {
- 'THREE.NoBlending': NoBlending,
- 'THREE.NormalBlending': NormalBlending,
- 'THREE.AdditiveBlending': AdditiveBlending,
- 'THREE.SubtractiveBlending': SubtractiveBlending,
- 'THREE.MultiplyBlending': MultiplyBlending,
- 'THREE.CustomBlending': CustomBlending
- },
- equations: {
- 'THREE.AddEquation': AddEquation,
- 'THREE.SubtractEquation': SubtractEquation,
- 'THREE.ReverseSubtractEquation': ReverseSubtractEquation
- },
- destinationFactors: {
- 'THREE.ZeroFactor': ZeroFactor,
- 'THREE.OneFactor': OneFactor,
- 'THREE.SrcColorFactor': SrcColorFactor,
- 'THREE.OneMinusSrcColorFactor': OneMinusSrcColorFactor,
- 'THREE.SrcAlphaFactor': SrcAlphaFactor,
- 'THREE.OneMinusSrcAlphaFactor': OneMinusSrcAlphaFactor,
- 'THREE.DstAlphaFactor': DstAlphaFactor,
- 'THREE.OneMinusDstAlphaFactor': OneMinusDstAlphaFactor
- },
- sourceFactors: {
- 'THREE.DstColorFactor': DstColorFactor,
- 'THREE.OneMinusDstColorFactor': OneMinusDstColorFactor,
- 'THREE.SrcAlphaSaturateFactor': SrcAlphaSaturateFactor
- }
- };
- function getObjectsKeys( obj ) {
- var keys = [];
- for ( var key in obj ) {
- if ( obj.hasOwnProperty( key ) ) {
- keys.push( key );
- }
- }
- return keys;
- }
- var textureLoader = new TextureLoader();
- var cubeTextureLoader = new CubeTextureLoader();
- var envMaps = ( function () {
- var path = '../../examples/textures/cube/SwedishRoyalCastle/';
- var format = '.jpg';
- var urls = [
- path + 'px' + format, path + 'nx' + format,
- path + 'py' + format, path + 'ny' + format,
- path + 'pz' + format, path + 'nz' + format
- ];
- var reflectionCube = cubeTextureLoader.load( urls );
- reflectionCube.format = RGBFormat;
- var refractionCube = cubeTextureLoader.load( urls );
- refractionCube.mapping = CubeRefractionMapping;
- refractionCube.format = RGBFormat;
- return {
- none: null,
- reflection: reflectionCube,
- refraction: refractionCube
- };
- } )();
- var diffuseMaps = ( function () {
- var bricks = textureLoader.load( '../../examples/textures/brick_diffuse.jpg' );
- bricks.wrapS = RepeatWrapping;
- bricks.wrapT = RepeatWrapping;
- bricks.repeat.set( 9, 1 );
- return {
- none: null,
- bricks: bricks
- };
- } )();
- var roughnessMaps = ( function () {
- var bricks = textureLoader.load( '../../examples/textures/brick_roughness.jpg' );
- bricks.wrapT = RepeatWrapping;
- bricks.wrapS = RepeatWrapping;
- bricks.repeat.set( 9, 1 );
- return {
- none: null,
- bricks: bricks
- };
- } )();
- var matcaps = ( function () {
- return {
- none: null,
- porcelainWhite: textureLoader.load( '../../examples/textures/matcaps/matcap-porcelain-white.jpg' )
- };
- } )();
- var alphaMaps = ( function () {
- var fibers = textureLoader.load( '../../examples/textures/alphaMap.jpg' );
- fibers.wrapT = RepeatWrapping;
- fibers.wrapS = RepeatWrapping;
- fibers.repeat.set( 9, 1 );
- return {
- none: null,
- fibers: fibers
- };
- } )();
- var gradientMaps = ( function () {
- var threeTone = textureLoader.load( '../../examples/textures/gradientMaps/threeTone.jpg' );
- threeTone.minFilter = NearestFilter;
- threeTone.magFilter = NearestFilter;
- var fiveTone = textureLoader.load( '../../examples/textures/gradientMaps/fiveTone.jpg' );
- fiveTone.minFilter = NearestFilter;
- fiveTone.magFilter = NearestFilter;
- return {
- none: null,
- threeTone: threeTone,
- fiveTone: fiveTone
- };
- } )();
- var envMapKeys = getObjectsKeys( envMaps );
- var diffuseMapKeys = getObjectsKeys( diffuseMaps );
- var roughnessMapKeys = getObjectsKeys( roughnessMaps );
- var matcapKeys = getObjectsKeys( matcaps );
- var alphaMapKeys = getObjectsKeys( alphaMaps );
- var gradientMapKeys = getObjectsKeys( gradientMaps );
- function generateVertexColors( geometry ) {
- var positionAttribute = geometry.attributes.position;
- var colors = [];
- var color = new Color();
- for ( var i = 0, il = positionAttribute.count; i < il; i ++ ) {
- color.setHSL( i / il * Math.random(), 0.5, 0.5 );
- colors.push( color.r, color.g, color.b );
- }
- geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
- }
- function handleColorChange( color ) {
- return function ( value ) {
- if ( typeof value === 'string' ) {
- value = value.replace( '#', '0x' );
- }
- color.setHex( value );
- };
- }
- function needsUpdate( material, geometry ) {
- return function () {
- material.vertexColors = parseInt( material.vertexColors ); //Ensure number
- material.side = parseInt( material.side ); //Ensure number
- material.needsUpdate = true;
- geometry.attributes.position.needsUpdate = true;
- geometry.attributes.normal.needsUpdate = true;
- geometry.attributes.color.needsUpdate = true;
- };
- }
- function updateTexture( material, materialKey, textures ) {
- return function ( key ) {
- material[ materialKey ] = textures[ key ];
- material.needsUpdate = true;
- };
- }
- function guiScene( gui, scene ) {
- var folder = gui.addFolder( 'Scene' );
- var data = {
- background: '#000000',
- 'ambient light': ambientLight.color.getHex()
- };
- folder.addColor( data, 'ambient light' ).onChange( handleColorChange( ambientLight.color ) );
- guiSceneFog( folder, scene );
- }
- function guiSceneFog( folder, scene ) {
- var fogFolder = folder.addFolder( 'scene.fog' );
- var fog = new Fog( 0x3f7b9d, 0, 60 );
- var data = {
- fog: {
- 'THREE.Fog()': false,
- 'scene.fog.color': fog.color.getHex()
- }
- };
- fogFolder.add( data.fog, 'THREE.Fog()' ).onChange( function ( useFog ) {
- if ( useFog ) {
- scene.fog = fog;
- } else {
- scene.fog = null;
- }
- } );
- fogFolder.addColor( data.fog, 'scene.fog.color' ).onChange( handleColorChange( fog.color ) );
- }
- function guiMaterial( gui, mesh, material, geometry ) {
- var folder = gui.addFolder( 'THREE.Material' );
- folder.add( material, 'transparent' );
- folder.add( material, 'opacity', 0, 1 ).step( 0.01 );
- // folder.add( material, 'blending', constants.blendingMode );
- // folder.add( material, 'blendSrc', constants.destinationFactors );
- // folder.add( material, 'blendDst', constants.destinationFactors );
- // folder.add( material, 'blendEquation', constants.equations );
- folder.add( material, 'depthTest' );
- folder.add( material, 'depthWrite' );
- // folder.add( material, 'polygonOffset' );
- // folder.add( material, 'polygonOffsetFactor' );
- // folder.add( material, 'polygonOffsetUnits' );
- folder.add( material, 'alphaTest', 0, 1 ).step( 0.01 ).onChange( needsUpdate( material, geometry ) );
- folder.add( material, 'visible' );
- folder.add( material, 'side', constants.side ).onChange( needsUpdate( material, geometry ) );
- }
- function guiMeshBasicMaterial( gui, mesh, material, geometry ) {
- var data = {
- color: material.color.getHex(),
- envMaps: envMapKeys[ 0 ],
- map: diffuseMapKeys[ 0 ],
- alphaMap: alphaMapKeys[ 0 ]
- };
- var folder = gui.addFolder( 'THREE.MeshBasicMaterial' );
- folder.addColor( data, 'color' ).onChange( handleColorChange( material.color ) );
- folder.add( material, 'wireframe' );
- folder.add( material, 'wireframeLinewidth', 0, 10 );
- folder.add( material, 'vertexColors', constants.colors ).onChange( needsUpdate( material, geometry ) );
- folder.add( material, 'fog' );
- folder.add( data, 'envMaps', envMapKeys ).onChange( updateTexture( material, 'envMap', envMaps ) );
- folder.add( data, 'map', diffuseMapKeys ).onChange( updateTexture( material, 'map', diffuseMaps ) );
- folder.add( data, 'alphaMap', alphaMapKeys ).onChange( updateTexture( material, 'alphaMap', alphaMaps ) );
- folder.add( material, 'combine', constants.combine );
- folder.add( material, 'reflectivity', 0, 1 );
- folder.add( material, 'refractionRatio', 0, 1 );
- }
- function guiMeshDepthMaterial( gui, mesh, material ) {
- var data = {
- alphaMap: alphaMapKeys[ 0 ]
- };
- var folder = gui.addFolder( 'THREE.MeshDepthMaterial' );
- folder.add( material, 'wireframe' );
- folder.add( material, 'wireframeLinewidth', 0, 10 );
- folder.add( data, 'alphaMap', alphaMapKeys ).onChange( updateTexture( material, 'alphaMap', alphaMaps ) );
- }
- function guiMeshNormalMaterial( gui, mesh, material, geometry ) {
- var folder = gui.addFolder( 'THREE.MeshNormalMaterial' );
- folder.add( material, 'flatShading' ).onChange( needsUpdate( material, geometry ) );
- folder.add( material, 'wireframe' );
- folder.add( material, 'wireframeLinewidth', 0, 10 );
- }
- function guiLineBasicMaterial( gui, mesh, material, geometry ) {
- var data = {
- color: material.color.getHex()
- };
- var folder = gui.addFolder( 'THREE.LineBasicMaterial' );
- folder.addColor( data, 'color' ).onChange( handleColorChange( material.color ) );
- folder.add( material, 'linewidth', 0, 10 );
- folder.add( material, 'linecap', [ 'butt', 'round', 'square' ] );
- folder.add( material, 'linejoin', [ 'round', 'bevel', 'miter' ] );
- folder.add( material, 'vertexColors', constants.colors ).onChange( needsUpdate( material, geometry ) );
- folder.add( material, 'fog' );
- }
- function guiMeshLambertMaterial( gui, mesh, material, geometry ) {
- var data = {
- color: material.color.getHex(),
- emissive: material.emissive.getHex(),
- envMaps: envMapKeys[ 0 ],
- map: diffuseMapKeys[ 0 ],
- alphaMap: alphaMapKeys[ 0 ]
- };
- var folder = gui.addFolder( 'THREE.MeshLambertMaterial' );
- folder.addColor( data, 'color' ).onChange( handleColorChange( material.color ) );
- folder.addColor( data, 'emissive' ).onChange( handleColorChange( material.emissive ) );
- folder.add( material, 'wireframe' );
- folder.add( material, 'wireframeLinewidth', 0, 10 );
- folder.add( material, 'vertexColors', constants.colors ).onChange( needsUpdate( material, geometry ) );
- folder.add( material, 'fog' );
- folder.add( data, 'envMaps', envMapKeys ).onChange( updateTexture( material, 'envMap', envMaps ) );
- folder.add( data, 'map', diffuseMapKeys ).onChange( updateTexture( material, 'map', diffuseMaps ) );
- folder.add( data, 'alphaMap', alphaMapKeys ).onChange( updateTexture( material, 'alphaMap', alphaMaps ) );
- folder.add( material, 'combine', constants.combine );
- folder.add( material, 'reflectivity', 0, 1 );
- folder.add( material, 'refractionRatio', 0, 1 );
- }
- function guiMeshMatcapMaterial( gui, mesh, material ) {
- var data = {
- color: material.color.getHex(),
- matcap: matcapKeys[ 1 ],
- alphaMap: alphaMapKeys[ 0 ]
- };
- var folder = gui.addFolder( 'THREE.MeshMatcapMaterial' );
- folder.addColor( data, 'color' ).onChange( handleColorChange( material.color ) );
- folder.add( data, 'matcap', matcapKeys ).onChange( updateTexture( material, 'matcap', matcaps ) );
- folder.add( data, 'alphaMap', alphaMapKeys ).onChange( updateTexture( material, 'alphaMap', alphaMaps ) );
- }
- function guiMeshPhongMaterial( gui, mesh, material, geometry ) {
- var data = {
- color: material.color.getHex(),
- emissive: material.emissive.getHex(),
- specular: material.specular.getHex(),
- envMaps: envMapKeys[ 0 ],
- map: diffuseMapKeys[ 0 ],
- alphaMap: alphaMapKeys[ 0 ]
- };
- var folder = gui.addFolder( 'THREE.MeshPhongMaterial' );
- folder.addColor( data, 'color' ).onChange( handleColorChange( material.color ) );
- folder.addColor( data, 'emissive' ).onChange( handleColorChange( material.emissive ) );
- folder.addColor( data, 'specular' ).onChange( handleColorChange( material.specular ) );
- folder.add( material, 'shininess', 0, 100 );
- folder.add( material, 'flatShading' ).onChange( needsUpdate( material, geometry ) );
- folder.add( material, 'wireframe' );
- folder.add( material, 'wireframeLinewidth', 0, 10 );
- folder.add( material, 'vertexColors', constants.colors ).onChange( needsUpdate( material, geometry ) );
- folder.add( material, 'fog' );
- folder.add( data, 'envMaps', envMapKeys ).onChange( updateTexture( material, 'envMap', envMaps ) );
- folder.add( data, 'map', diffuseMapKeys ).onChange( updateTexture( material, 'map', diffuseMaps ) );
- folder.add( data, 'alphaMap', alphaMapKeys ).onChange( updateTexture( material, 'alphaMap', alphaMaps ) );
- }
- function guiMeshToonMaterial( gui, mesh, material ) {
- var data = {
- color: material.color.getHex(),
- map: diffuseMapKeys[ 0 ],
- gradientMap: gradientMapKeys[ 1 ],
- alphaMap: alphaMapKeys[ 0 ]
- };
- var folder = gui.addFolder( 'THREE.MeshToonMaterial' );
- folder.addColor( data, 'color' ).onChange( handleColorChange( material.color ) );
- folder.add( data, 'map', diffuseMapKeys ).onChange( updateTexture( material, 'map', diffuseMaps ) );
- folder.add( data, 'gradientMap', gradientMapKeys ).onChange( updateTexture( material, 'gradientMap', gradientMaps ) );
- folder.add( data, 'alphaMap', alphaMapKeys ).onChange( updateTexture( material, 'alphaMap', alphaMaps ) );
- }
- function guiMeshStandardMaterial( gui, mesh, material, geometry ) {
- var data = {
- color: material.color.getHex(),
- emissive: material.emissive.getHex(),
- envMaps: envMapKeys[ 0 ],
- map: diffuseMapKeys[ 0 ],
- roughnessMap: roughnessMapKeys[ 0 ],
- alphaMap: alphaMapKeys[ 0 ]
- };
- var folder = gui.addFolder( 'THREE.MeshStandardMaterial' );
- folder.addColor( data, 'color' ).onChange( handleColorChange( material.color ) );
- folder.addColor( data, 'emissive' ).onChange( handleColorChange( material.emissive ) );
- folder.add( material, 'roughness', 0, 1 );
- folder.add( material, 'metalness', 0, 1 );
- folder.add( material, 'flatShading' ).onChange( needsUpdate( material, geometry ) );
- folder.add( material, 'wireframe' );
- folder.add( material, 'wireframeLinewidth', 0, 10 );
- folder.add( material, 'vertexColors', constants.colors ).onChange( needsUpdate( material, geometry ) );
- folder.add( material, 'fog' );
- folder.add( data, 'envMaps', envMapKeys ).onChange( updateTexture( material, 'envMap', envMaps ) );
- folder.add( data, 'map', diffuseMapKeys ).onChange( updateTexture( material, 'map', diffuseMaps ) );
- folder.add( data, 'roughnessMap', roughnessMapKeys ).onChange( updateTexture( material, 'roughnessMap', roughnessMaps ) );
- folder.add( data, 'alphaMap', alphaMapKeys ).onChange( updateTexture( material, 'alphaMap', alphaMaps ) );
- // TODO metalnessMap
- }
- function guiMeshPhysicalMaterial( gui, mesh, material, geometry ) {
- var data = {
- color: material.color.getHex(),
- emissive: material.emissive.getHex(),
- envMaps: envMapKeys[ 0 ],
- map: diffuseMapKeys[ 0 ],
- roughnessMap: roughnessMapKeys[ 0 ],
- alphaMap: alphaMapKeys[ 0 ]
- };
- var folder = gui.addFolder( 'THREE.MeshPhysicalMaterial' );
- folder.addColor( data, 'color' ).onChange( handleColorChange( material.color ) );
- folder.addColor( data, 'emissive' ).onChange( handleColorChange( material.emissive ) );
- folder.add( material, 'roughness', 0, 1 );
- folder.add( material, 'metalness', 0, 1 );
- folder.add( material, 'reflectivity', 0, 1 );
- folder.add( material, 'clearcoat', 0, 1 ).step( 0.01 );
- folder.add( material, 'clearcoatRoughness', 0, 1 ).step( 0.01 );
- folder.add( material, 'flatShading' ).onChange( needsUpdate( material, geometry ) );
- folder.add( material, 'wireframe' );
- folder.add( material, 'wireframeLinewidth', 0, 10 );
- folder.add( material, 'vertexColors', constants.colors ).onChange( needsUpdate( material, geometry ) );
- folder.add( material, 'fog' );
- folder.add( data, 'envMaps', envMapKeys ).onChange( updateTexture( material, 'envMap', envMaps ) );
- folder.add( data, 'map', diffuseMapKeys ).onChange( updateTexture( material, 'map', diffuseMaps ) );
- folder.add( data, 'roughnessMap', roughnessMapKeys ).onChange( updateTexture( material, 'roughnessMap', roughnessMaps ) );
- folder.add( data, 'alphaMap', alphaMapKeys ).onChange( updateTexture( material, 'alphaMap', alphaMaps ) );
- // TODO metalnessMap
- }
- function chooseFromHash( gui, mesh, geometry ) {
- var selectedMaterial = window.location.hash.substring( 1 ) || 'MeshBasicMaterial';
- var material;
- switch ( selectedMaterial ) {
- case 'MeshBasicMaterial' :
- material = new MeshBasicMaterial( { color: 0x2194CE } );
- guiMaterial( gui, mesh, material, geometry );
- guiMeshBasicMaterial( gui, mesh, material, geometry );
- return material;
- break;
- case 'MeshLambertMaterial' :
- material = new MeshLambertMaterial( { color: 0x2194CE } );
- guiMaterial( gui, mesh, material, geometry );
- guiMeshLambertMaterial( gui, mesh, material, geometry );
- return material;
- break;
- case 'MeshMatcapMaterial' :
- material = new MeshMatcapMaterial( { matcap: matcaps.porcelainWhite } );
- guiMaterial( gui, mesh, material, geometry );
- guiMeshMatcapMaterial( gui, mesh, material, geometry );
- return material;
- break;
- case 'MeshPhongMaterial' :
- material = new MeshPhongMaterial( { color: 0x2194CE } );
- guiMaterial( gui, mesh, material, geometry );
- guiMeshPhongMaterial( gui, mesh, material, geometry );
- return material;
- break;
- case 'MeshToonMaterial' :
- material = new MeshToonMaterial( { color: 0x2194CE, gradientMap: gradientMaps.threeTone } );
- guiMaterial( gui, mesh, material, geometry );
- guiMeshToonMaterial( gui, mesh, material, geometry );
- // only use a single point light
- lights[ 0 ].visible = false;
- lights[ 2 ].visible = false;
- return material;
- break;
- case 'MeshStandardMaterial' :
- material = new MeshStandardMaterial( { color: 0x2194CE } );
- guiMaterial( gui, mesh, material, geometry );
- guiMeshStandardMaterial( gui, mesh, material, geometry );
- return material;
- break;
- case 'MeshPhysicalMaterial' :
- material = new MeshPhysicalMaterial( { color: 0x2194CE } );
- guiMaterial( gui, mesh, material, geometry );
- guiMeshPhysicalMaterial( gui, mesh, material, geometry );
- return material;
- break;
- case 'MeshDepthMaterial' :
- material = new MeshDepthMaterial();
- guiMaterial( gui, mesh, material, geometry );
- guiMeshDepthMaterial( gui, mesh, material, geometry );
- return material;
- break;
- case 'MeshNormalMaterial' :
- material = new MeshNormalMaterial();
- guiMaterial( gui, mesh, material, geometry );
- guiMeshNormalMaterial( gui, mesh, material, geometry );
- return material;
- break;
- case 'LineBasicMaterial' :
- material = new LineBasicMaterial( { color: 0x2194CE } );
- guiMaterial( gui, mesh, material, geometry );
- guiLineBasicMaterial( gui, mesh, material, geometry );
- return material;
- break;
- }
- }
- //
- document.getElementById( 'newWindow' ).href += window.location.hash;
- var gui = new GUI();
- var scene = new Scene();
- scene.background = new Color( 0x444444 );
- var camera = new PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 10, 50 );
- camera.position.z = 30;
- var renderer = new WebGLRenderer( { antialias: true } );
- renderer.setPixelRatio( window.devicePixelRatio );
- renderer.setSize( window.innerWidth, window.innerHeight );
- document.body.appendChild( renderer.domElement );
- var ambientLight = new AmbientLight( 0x000000 );
- scene.add( ambientLight );
- var lights = [];
- lights[ 0 ] = new PointLight( 0xffffff, 1, 0 );
- lights[ 1 ] = new PointLight( 0xffffff, 1, 0 );
- lights[ 2 ] = new PointLight( 0xffffff, 1, 0 );
- lights[ 0 ].position.set( 0, 200, 0 );
- lights[ 1 ].position.set( 100, 200, 100 );
- lights[ 2 ].position.set( - 100, - 200, - 100 );
- scene.add( lights[ 0 ] );
- scene.add( lights[ 1 ] );
- scene.add( lights[ 2 ] );
- guiScene( gui, scene, camera );
- var geometry = new TorusKnotBufferGeometry( 10, 3, 100, 16 );
- geometry = geometry.toNonIndexed();
- generateVertexColors( geometry );
- var mesh = new Mesh( geometry );
- mesh.material = chooseFromHash( gui, mesh, geometry );
- scene.add( mesh );
- var prevFog = false;
- var render = function () {
- requestAnimationFrame( render );
- mesh.rotation.x += 0.005;
- mesh.rotation.y += 0.005;
- if ( prevFog !== scene.fog ) {
- mesh.material.needsUpdate = true;
- prevFog = scene.fog;
- }
- renderer.render( scene, camera );
- };
- window.addEventListener( 'resize', function () {
- camera.aspect = window.innerWidth / window.innerHeight;
- camera.updateProjectionMatrix();
- renderer.setSize( window.innerWidth, window.innerHeight );
- }, false );
- render();
- </script>
- </body>
- </html>
|