|
@@ -0,0 +1,242 @@
|
|
|
+<!DOCTYPE html>
|
|
|
+<html xmlns="http://www.w3.org/1999/xhtml">
|
|
|
+<head>
|
|
|
+ <title>Procedural textures Library</title>
|
|
|
+ <script src="refs/dat.gui.min.js"></script>
|
|
|
+ <script src="refs/babylon.max.js"></script>
|
|
|
+ <script src="../dist/babylon.fireProceduralTexture.js"></script>
|
|
|
+
|
|
|
+ <style>
|
|
|
+ html, body {
|
|
|
+ width: 100%;
|
|
|
+ height: 100%;
|
|
|
+ padding: 0;
|
|
|
+ margin: 0;
|
|
|
+ overflow: hidden;
|
|
|
+ }
|
|
|
+
|
|
|
+ #renderCanvas {
|
|
|
+ width: 100%;
|
|
|
+ height: 100%;
|
|
|
+ }
|
|
|
+
|
|
|
+ #fps {
|
|
|
+ position: absolute;
|
|
|
+ background-color: black;
|
|
|
+ border: 2px solid red;
|
|
|
+ text-align: center;
|
|
|
+ font-size: 16px;
|
|
|
+ color: white;
|
|
|
+ top: 15px;
|
|
|
+ left: 10px;
|
|
|
+ width: 60px;
|
|
|
+ height: 20px;
|
|
|
+ }
|
|
|
+ </style>
|
|
|
+</head>
|
|
|
+<body>
|
|
|
+ <div id="fps">0</div>
|
|
|
+ <canvas id="renderCanvas"></canvas>
|
|
|
+
|
|
|
+ <script src="index.js"></script>
|
|
|
+ <script src="add/addFirePT.js"></script>
|
|
|
+ <script>
|
|
|
+ if (BABYLON.Engine.isSupported()) {
|
|
|
+ var canvas = document.getElementById("renderCanvas");
|
|
|
+ var engine = new BABYLON.Engine(canvas, true);
|
|
|
+ var divFps = document.getElementById("fps");
|
|
|
+
|
|
|
+ var scene = new BABYLON.Scene(engine);
|
|
|
+
|
|
|
+ var camera = new BABYLON.ArcRotateCamera("Camera", Math.PI / 2, Math.PI / 6, 50, BABYLON.Vector3.Zero(), scene);
|
|
|
+ camera.attachControl(canvas, true);
|
|
|
+
|
|
|
+ // Lights
|
|
|
+ var hemisphericLight = new BABYLON.HemisphericLight("hemi", new BABYLON.Vector3(0, 1, 0), scene);
|
|
|
+ var pointLight = new BABYLON.PointLight("point", new BABYLON.Vector3(20, 20, 10), scene);
|
|
|
+ pointLight.setEnabled(false);
|
|
|
+ var directionalLight = new BABYLON.DirectionalLight("directional", new BABYLON.Vector3(0,-1, 0), scene);
|
|
|
+ directionalLight.setEnabled(false);
|
|
|
+ var spotLight = new BABYLON.SpotLight("spot", new BABYLON.Vector3(0, -30, 0), new BABYLON.Vector3(0, 1, 0), 1.1, 1, scene);
|
|
|
+ spotLight.setEnabled(false);
|
|
|
+
|
|
|
+ // Create meshes
|
|
|
+ var sphere = BABYLON.Mesh.CreateSphere("sphere", 32, 30.0, scene);
|
|
|
+
|
|
|
+ var plane = BABYLON.MeshBuilder.CreateBox("plane", { width: 30, height: 1, depth:30 }, scene);
|
|
|
+ plane.setEnabled(false);
|
|
|
+
|
|
|
+ var ground = BABYLON.Mesh.CreateGround("ground", 512, 512, 32, scene, false);
|
|
|
+ ground.scaling = new BABYLON.Vector3(0.1, 0.1, 0.1);
|
|
|
+ ground.setEnabled(false);
|
|
|
+
|
|
|
+ var knot = BABYLON.Mesh.CreateTorusKnot("knot", 10, 3, 128, 64, 2, 3, scene);
|
|
|
+ knot.setEnabled(false);
|
|
|
+
|
|
|
+ // Skybox
|
|
|
+ var skybox = BABYLON.Mesh.CreateBox("skyBox", 1000.0, scene);
|
|
|
+ var skyboxMaterial = new BABYLON.StandardMaterial("skyBox", scene);
|
|
|
+ skyboxMaterial.backFaceCulling = false;
|
|
|
+ skyboxMaterial.reflectionTexture = new BABYLON.CubeTexture("textures/skybox/TropicalSunnyDay", scene);
|
|
|
+ skyboxMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
|
|
|
+ skyboxMaterial.diffuseColor = new BABYLON.Color3(0, 0, 0);
|
|
|
+ skyboxMaterial.specularColor = new BABYLON.Color3(0, 0, 0);
|
|
|
+ skyboxMaterial.disableLighting = true;
|
|
|
+ skybox.material = skyboxMaterial;
|
|
|
+ skybox.setEnabled(false);
|
|
|
+
|
|
|
+ var currentMesh = sphere;
|
|
|
+
|
|
|
+ // Rabbit
|
|
|
+ var rabbit;
|
|
|
+ BABYLON.SceneLoader.ImportMesh("Rabbit", "meshes/", "Rabbit.babylon", scene, function (newMeshes, particleSystems, skeletons) {
|
|
|
+ rabbit = newMeshes[1];
|
|
|
+ rabbit.setEnabled(false);
|
|
|
+ rabbit.scaling = new BABYLON.Vector3(0.3, 0.3, 0.3);
|
|
|
+ scene.beginAnimation(skeletons[0], 0, 100, true, 0.8);
|
|
|
+
|
|
|
+ // Shadow caster
|
|
|
+ var shadowCaster = BABYLON.Mesh.CreateTorus("torus", 4, 2, 30, scene, false);
|
|
|
+ shadowCaster.setEnabled(false);
|
|
|
+ shadowCaster.position = new BABYLON.Vector3(0, 30, 0);
|
|
|
+
|
|
|
+ var shadowCaster2 = BABYLON.Mesh.CreateTorus("torus", 4, 2, 30, scene, false);
|
|
|
+ shadowCaster2.setEnabled(false);
|
|
|
+ shadowCaster2.position = new BABYLON.Vector3(0, -30, 0);
|
|
|
+
|
|
|
+ var shadowCaster3 = BABYLON.Mesh.CreateTorus("torus", 4, 2, 30, scene, false);
|
|
|
+ shadowCaster3.setEnabled(false);
|
|
|
+ shadowCaster3.position = new BABYLON.Vector3(20, 20, 10);
|
|
|
+
|
|
|
+ var shadowGenerator = new BABYLON.ShadowGenerator(1024, directionalLight);
|
|
|
+ shadowGenerator.getShadowMap().renderList.push(shadowCaster);
|
|
|
+ shadowGenerator.usePoissonSampling = true;
|
|
|
+
|
|
|
+ var shadowGenerator2 = new BABYLON.ShadowGenerator(1024, spotLight);
|
|
|
+ shadowGenerator2.getShadowMap().renderList.push(shadowCaster2);
|
|
|
+ shadowGenerator2.usePoissonSampling = true;
|
|
|
+
|
|
|
+ var shadowGenerator3 = new BABYLON.ShadowGenerator(1024, pointLight);
|
|
|
+ shadowGenerator3.getShadowMap().renderList.push(shadowCaster3);
|
|
|
+ shadowGenerator3.usePoissonSampling = true;
|
|
|
+
|
|
|
+ // Register a render loop to repeatedly render the scene
|
|
|
+ engine.runRenderLoop(function () {
|
|
|
+ scene.render();
|
|
|
+ divFps.innerHTML = engine.getFps().toFixed() + " fps";
|
|
|
+
|
|
|
+ shadowCaster.rotation.x += 0.01;
|
|
|
+ shadowCaster.rotation.y += 0.01;
|
|
|
+
|
|
|
+ shadowCaster2.rotation.x += 0.01;
|
|
|
+ shadowCaster2.rotation.y += 0.01;
|
|
|
+
|
|
|
+ shadowCaster3.rotation.x += 0.01;
|
|
|
+ shadowCaster3.rotation.y += 0.01;
|
|
|
+ });
|
|
|
+
|
|
|
+ // Resize
|
|
|
+ window.addEventListener("resize", function () {
|
|
|
+ engine.resize();
|
|
|
+ });
|
|
|
+
|
|
|
+ // Fog
|
|
|
+ scene.fogMode = BABYLON.Scene.FOGMODE_NONE;
|
|
|
+ scene.fogDensity = 0.01;
|
|
|
+
|
|
|
+ // Create shaders
|
|
|
+ var std = new BABYLON.StandardMaterial("std", scene);
|
|
|
+ std.diffuseTexture = new BABYLON.Texture("textures/amiga.jpg", scene);
|
|
|
+ std.diffuseTexture.uScale = 5;
|
|
|
+ std.diffuseTexture.vScale = 5;
|
|
|
+
|
|
|
+ // Fire Procedural Texture
|
|
|
+ var firePT = addFirePT();
|
|
|
+ var fireMaterial = new BABYLON.StandardMaterial("fire", scene);
|
|
|
+ fireMaterial.diffuseTexture = firePT;
|
|
|
+
|
|
|
+ // Default to std
|
|
|
+ var currentMaterial = std;
|
|
|
+ sphere.material = std;
|
|
|
+ sphere.receiveShadows = true;
|
|
|
+
|
|
|
+ gui.add(options, 'material', ['none','fire']).onFinishChange(function () {
|
|
|
+ switch (options.material) {
|
|
|
+ case "fire":
|
|
|
+ currentMaterial = fireMaterial;
|
|
|
+ break;
|
|
|
+ case "none":
|
|
|
+ default:
|
|
|
+ currentMaterial = std;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ currentMesh.material = currentMaterial;
|
|
|
+ window.enableMaterial(options.material);
|
|
|
+ });
|
|
|
+
|
|
|
+ gui.add(options, 'mesh', ['sphere', 'knot', 'plane', 'ground', 'rabbit']).onFinishChange(function () {
|
|
|
+ currentMesh.setEnabled(false);
|
|
|
+ switch (options.mesh) {
|
|
|
+ case "sphere":
|
|
|
+ currentMesh = sphere;
|
|
|
+ break;
|
|
|
+ case "knot":
|
|
|
+ currentMesh = knot;
|
|
|
+ break;
|
|
|
+ case "plane":
|
|
|
+ currentMesh = plane;
|
|
|
+ break;
|
|
|
+ case "ground":
|
|
|
+ currentMesh = ground;
|
|
|
+ break;
|
|
|
+ case "rabbit":
|
|
|
+ currentMesh = rabbit;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ currentMesh.setEnabled(true);
|
|
|
+ currentMesh.receiveShadows = true;
|
|
|
+ currentMesh.material = currentMaterial;
|
|
|
+
|
|
|
+ water.mesh = currentMesh;
|
|
|
+ });
|
|
|
+
|
|
|
+ var f1 = gui.addFolder('lights');
|
|
|
+ f1.add(options, 'hemisphericLight').onChange(function () {
|
|
|
+ hemisphericLight.setEnabled(options.hemisphericLight);
|
|
|
+ });
|
|
|
+
|
|
|
+ f1.add(options, 'pointLight').onChange(function () {
|
|
|
+ pointLight.setEnabled(options.pointLight);
|
|
|
+ shadowCaster3.setEnabled(options.pointLight && options.castShadows);
|
|
|
+ });
|
|
|
+
|
|
|
+ f1.add(options, 'spotLight').onChange(function () {
|
|
|
+ spotLight.setEnabled(options.spotLight);
|
|
|
+ shadowCaster2.setEnabled(options.spotLight && options.castShadows);
|
|
|
+ });
|
|
|
+
|
|
|
+ f1.add(options, 'directionalLight').onChange(function () {
|
|
|
+ directionalLight.setEnabled(options.directionalLight);
|
|
|
+ shadowCaster.setEnabled(options.directionalLight && options.castShadows);
|
|
|
+ });
|
|
|
+
|
|
|
+ f1.add(options, 'castShadows').onChange(function () {
|
|
|
+ shadowCaster.setEnabled(options.directionalLight && options.castShadows);
|
|
|
+ shadowCaster2.setEnabled(options.spotLight && options.castShadows);
|
|
|
+ shadowCaster3.setEnabled(options.pointLight && options.castShadows);
|
|
|
+ });
|
|
|
+
|
|
|
+ gui.add(options, 'fog').onChange(function () {
|
|
|
+ scene.fogMode = options.fog ? BABYLON.Scene.FOGMODE_EXP : BABYLON.Scene.FOGMODE_NONE;
|
|
|
+ });
|
|
|
+
|
|
|
+ gui.add(options, 'skybox').onChange(function() {
|
|
|
+ skybox.setEnabled(options.skybox);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ </script>
|
|
|
+</body>
|
|
|
+</html>
|