コード例 #1
0
ファイル: Main.cs プロジェクト: ARLM-Attic/babylon
        private void Scene11()
        {
            this.scene = new BABYLON.Scene(engine);
            var camera = new BABYLON.ArcRotateCamera("Camera", 0, 0, 10, BABYLON.Vector3.Zero(), scene);
            var sun    = new BABYLON.PointLight("Omni0", new BABYLON.Vector3(60, 100, 10), scene);

            camera.setPosition(new BABYLON.Vector3(-20, 20, 0));

            // Skybox
            var skybox         = BABYLON.Mesh.CreateBox("skyBox", 100.0, scene);
            var skyboxMaterial = new BABYLON.StandardMaterial("skyBox", scene);

            skyboxMaterial.backFaceCulling   = false;
            skyboxMaterial.reflectionTexture = new BABYLON.CubeTexture("skybox", scene);
            skyboxMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
            skyboxMaterial.diffuseColor  = new BABYLON.Color3(0, 0, 0);
            skyboxMaterial.specularColor = new BABYLON.Color3(0, 0, 0);
            skybox.material = skyboxMaterial;

            // Ground
            var ground         = BABYLON.Mesh.CreateGroundFromHeightMap("ground", "heightMap.png", 100, 100, 100, 0, 10, scene, false);
            var groundMaterial = new BABYLON.StandardMaterial("ground", scene);
            var texture1       = new BABYLON.Texture("ground.jpg", scene);

            texture1.uScale = 6;
            texture1.vScale = 6;
            groundMaterial.diffuseTexture = texture1;
            groundMaterial.specularColor  = new BABYLON.Color3(0, 0, 0);
            ground.position.y             = -2.05;
            ground.material = groundMaterial;

            System.Action beforeRenderFunction = () =>
            {
                // Camera
                if (camera.beta < 0.1)
                {
                    camera.beta = 0.1;
                }
                else if (camera.beta > (Math.PI / 2) * 0.9)
                {
                    camera.beta = (Math.PI / 2) * 0.9;
                }

                if (camera.radius > 50)
                {
                    camera.radius = 50;
                }

                if (camera.radius < 5)
                {
                    camera.radius = 5;
                }
            };

            scene.registerBeforeRender(beforeRenderFunction);

            this.scene.activeCamera.attachControl(this.canvas);
        }
コード例 #2
0
ファイル: Main.cs プロジェクト: ARLM-Attic/babylon
        private void Scene10()
        {
            this.scene = new BABYLON.Scene(engine);
            var camera  = new BABYLON.FreeCamera("Camera", new BABYLON.Vector3(0, 0, -20), scene);
            var light   = new BABYLON.PointLight("Omni", new BABYLON.Vector3(20, 100, 2), scene);
            var sphere0 = BABYLON.Mesh.CreateSphere("Sphere0", 16, 3, scene);
            var sphere1 = BABYLON.Mesh.CreateSphere("Sphere1", 16, 3, scene);
            var sphere2 = BABYLON.Mesh.CreateSphere("Sphere2", 16, 3, scene);

            var material0 = new BABYLON.StandardMaterial("mat0", scene);

            material0.diffuseColor = new BABYLON.Color3(1, 0, 0);
            sphere0.material       = material0;
            sphere0.position       = new BABYLON.Vector3(-10, 0, 0);

            var material1 = new BABYLON.StandardMaterial("mat1", scene);

            material1.diffuseColor = new BABYLON.Color3(1, 1, 0);
            sphere1.material       = material1;

            var material2 = new BABYLON.StandardMaterial("mat2", scene);

            material2.diffuseColor = new BABYLON.Color3(1, 0, 1);
            sphere2.material       = material2;
            sphere2.position       = new BABYLON.Vector3(10, 0, 0);

            sphere1.convertToFlatShadedMesh();

            camera.setTarget(new BABYLON.Vector3(0, 0, 0));

            // Fog
            scene.fogMode    = BABYLON.Scene.FOGMODE_EXP;
            scene.fogDensity = 0.1;

            // Animations
            var alpha = 0.0;

            scene.registerBeforeRender(() =>
            {
                sphere0.position.z = 4 * Math.Cos(alpha);
                sphere1.position.z = 4 * Math.Sin(alpha);
                sphere2.position.z = 4 * Math.Cos(alpha);

                alpha += 0.1;
            });

            this.scene.activeCamera.attachControl(this.canvas);
        }
コード例 #3
0
ファイル: Main.cs プロジェクト: ARLM-Attic/babylon
        private void Scene8()
        {
            this.scene = new BABYLON.Scene(engine);
            var camera = new BABYLON.ArcRotateCamera("Camera", 0, 0, 10, BABYLON.Vector3.Zero(), scene);
            var light  = new BABYLON.PointLight("Omni", new BABYLON.Vector3(20, 100, 2), scene);


            var material0 = new BABYLON.StandardMaterial("mat0", scene);

            material0.diffuseColor = new BABYLON.Color3(1, 0, 0);
            material0.bumpTexture  = new BABYLON.Texture("normalMap.jpg", scene);

            var material1 = new BABYLON.StandardMaterial("mat1", scene);

            material1.diffuseColor = new BABYLON.Color3(0, 0, 1);

            var material2 = new BABYLON.StandardMaterial("mat2", scene);

            material2.emissiveColor = new BABYLON.Color3(0.4, 0, 0.4);

            var multimat = new BABYLON.MultiMaterial("multi", scene);

            multimat.subMaterials.Add(material0);
            multimat.subMaterials.Add(material1);
            multimat.subMaterials.Add(material2);

            var sphere = BABYLON.Mesh.CreateSphere("Sphere0", 16, 3, scene);

            sphere.material = multimat;

            sphere.subMeshes = new Array <SubMesh>();
            ;
            var verticesCount = sphere.getTotalVertices();

            sphere.subMeshes.Add(new BABYLON.SubMesh(0, 0, verticesCount, 0, 900, sphere));
            sphere.subMeshes.Add(new BABYLON.SubMesh(1, 0, verticesCount, 900, 900, sphere));
            sphere.subMeshes.Add(new BABYLON.SubMesh(2, 0, verticesCount, 1800, 2088, sphere));

            camera.setPosition(new BABYLON.Vector3(-3, 3, 0));

            // Animations
            scene.registerBeforeRender(
                () => { sphere.rotation.y += 0.01; });

            this.scene.activeCamera.attachControl(this.canvas);
        }
コード例 #4
0
        private void Scene18()
        {
            this.scene = new BABYLON.Scene(engine);
            var camera = new BABYLON.ArcRotateCamera("Camera", 0, 0, 10, BABYLON.Vector3.Zero(), scene);
            var light0 = new BABYLON.PointLight("Omni0", new BABYLON.Vector3(21.84, 50, -28.26), scene);

            camera.alpha = 2.8;
            camera.beta  = 2.25;

            // Creating light sphere
            var lightSphere0 = BABYLON.Mesh.CreateSphere("Sphere0", 16, 0.5, scene);

            var material0 = new BABYLON.StandardMaterial("white", scene);

            material0.diffuseColor  = new BABYLON.Color3(0, 0, 0);
            material0.specularColor = new BABYLON.Color3(0, 0, 0);
            material0.emissiveColor = new BABYLON.Color3(1, 1, 1);
            lightSphere0.material   = material0;

            lightSphere0.position = light0.position;

            var lensFlareSystem = new BABYLON.LensFlareSystem("lensFlareSystem", light0, scene);
            var flare00         = new BABYLON.LensFlare(0.2, 0, new BABYLON.Color3(1, 1, 1), "lens5.png", lensFlareSystem);
            var flare01         = new BABYLON.LensFlare(0.5, 0.2, new BABYLON.Color3(0.5, 0.5, 1), "lens4.png", lensFlareSystem);
            var flare02         = new BABYLON.LensFlare(0.2, 1.0, new BABYLON.Color3(1, 1, 1), "lens4.png", lensFlareSystem);
            var flare03         = new BABYLON.LensFlare(0.4, 0.4, new BABYLON.Color3(1, 0.5, 1), "Flare.png", lensFlareSystem);
            var flare04         = new BABYLON.LensFlare(0.1, 0.6, new BABYLON.Color3(1, 1, 1), "lens5.png", lensFlareSystem);
            var flare05         = new BABYLON.LensFlare(0.3, 0.8, new BABYLON.Color3(1, 1, 1), "lens4.png", lensFlareSystem);

            // Skybox
            var skybox         = BABYLON.Mesh.CreateBox("skyBox", 100.0, scene);
            var skyboxMaterial = new BABYLON.StandardMaterial("skyBox", scene);

            skyboxMaterial.backFaceCulling   = false;
            skyboxMaterial.reflectionTexture = new BABYLON.CubeTexture("skybox", scene);
            skyboxMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
            skyboxMaterial.diffuseColor  = new BABYLON.Color3(0, 0, 0);
            skyboxMaterial.specularColor = new BABYLON.Color3(0, 0, 0);
            skybox.material = skyboxMaterial;

            this.scene.activeCamera.attachControl(this.canvas);
        }
コード例 #5
0
ファイル: Main.cs プロジェクト: ARLM-Attic/babylon
        private void Scene7()
        {
            this.scene = new BABYLON.Scene(engine);
            var camera   = new BABYLON.ArcRotateCamera("Camera", 0, 0, 10, BABYLON.Vector3.Zero(), scene);
            var light    = new BABYLON.PointLight("Omni", new BABYLON.Vector3(20, 100, 2), scene);
            var sphere   = BABYLON.Mesh.CreateSphere("Sphere", 16, 3, scene);
            var material = new BABYLON.StandardMaterial("kosh", scene);

            material.bumpTexture  = new BABYLON.Texture("normalMap.jpg", scene);
            material.diffuseColor = new BABYLON.Color3(1, 0, 0);

            sphere.material = material;

            camera.setPosition(new BABYLON.Vector3(-5, 5, 0));

            // Animations
            scene.registerBeforeRender(() =>
            {
                sphere.rotation.y += 0.02;
            });

            this.scene.activeCamera.attachControl(this.canvas);
        }
コード例 #6
0
ファイル: Main.cs プロジェクト: ARLM-Attic/babylon
        private void Scene13()
        {
            this.scene = new BABYLON.Scene(engine);
            var camera   = new BABYLON.ArcRotateCamera("Camera", 0, 0, 10, BABYLON.Vector3.Zero(), scene);
            var light0   = new BABYLON.PointLight("Omni0", new BABYLON.Vector3(0, 10, 0), scene);
            var material = new BABYLON.StandardMaterial("kosh", scene);
            var sphere   = BABYLON.Mesh.CreateSphere("sphere0", 16, 1, scene);

            camera.setPosition(new BABYLON.Vector3(-10, 10, 0));

            // Sphere material
            material.diffuseColor          = new BABYLON.Color3(0.5, 0.5, 0.5);
            material.specularColor         = new BABYLON.Color3(1.0, 1.0, 1.0);
            material.specularPower         = 32;
            material.checkReadyOnEveryCall = false;
            sphere.material = material;

            // Fog
            scene.fogMode    = BABYLON.Scene.FOGMODE_EXP;
            scene.fogDensity = 0.05;

            // Clone spheres
            var random         = new Random();
            var playgroundSize = 50.0;

            for (var index = 0; index < 8000; index++)
            {
                var clone = sphere.clone("sphere" + (index + 1), null, true);
                var scale = random.NextDouble() * 0.8 + 0.6;
                clone.scaling  = new BABYLON.Vector3(scale, scale, scale);
                clone.position = new BABYLON.Vector3(random.NextDouble() * 2.0 * playgroundSize - playgroundSize, random.NextDouble() * 2.0 * playgroundSize - playgroundSize, random.NextDouble() * 2.0 * playgroundSize - playgroundSize);
            }
            sphere.setEnabled(false);
            scene.createOrUpdateSelectionOctree();

            this.scene.activeCamera.attachControl(this.canvas);
        }
コード例 #7
0
ファイル: Main.cs プロジェクト: ARLM-Attic/babylon
        private void Scene9()
        {
            this.scene = new BABYLON.Scene(engine);
            var camera   = new BABYLON.ArcRotateCamera("Camera", 0, 0, 10, BABYLON.Vector3.Zero(), scene);
            var light0   = new BABYLON.PointLight("Omni0", new BABYLON.Vector3(0, 10, 0), scene);
            var light1   = new BABYLON.PointLight("Omni1", new BABYLON.Vector3(0, -10, 0), scene);
            var light2   = new BABYLON.PointLight("Omni2", new BABYLON.Vector3(10, 0, 0), scene);
            var light3   = new BABYLON.DirectionalLight("Dir0", new BABYLON.Vector3(1, -1, 0), scene);
            var material = new BABYLON.StandardMaterial("kosh", scene);
            var sphere   = BABYLON.Mesh.CreateSphere("Sphere", 16, 3, scene);

            camera.setPosition(new BABYLON.Vector3(-10, 10, 0));

            light3.parent = camera;

            // Creating light sphere
            var lightSphere0 = BABYLON.Mesh.CreateSphere("Sphere0", 16, 0.5, scene);
            var lightSphere1 = BABYLON.Mesh.CreateSphere("Sphere1", 16, 0.5, scene);
            var lightSphere2 = BABYLON.Mesh.CreateSphere("Sphere2", 16, 0.5, scene);

            var material1 = new BABYLON.StandardMaterial("red", scene);

            material1.diffuseColor  = new BABYLON.Color3(0, 0, 0);
            material1.specularColor = new BABYLON.Color3(0, 0, 0);
            material1.emissiveColor = new BABYLON.Color3(1, 0, 0);
            lightSphere0.material   = material1;

            var material2 = new BABYLON.StandardMaterial("green", scene);

            material2.diffuseColor  = new BABYLON.Color3(0, 0, 0);
            material2.specularColor = new BABYLON.Color3(0, 0, 0);
            material2.emissiveColor = new BABYLON.Color3(0, 1, 0);
            lightSphere1.material   = material2;

            var material3 = new BABYLON.StandardMaterial("blue", scene);

            material3.diffuseColor  = new BABYLON.Color3(0, 0, 0);
            material3.specularColor = new BABYLON.Color3(0, 0, 0);
            material3.emissiveColor = new BABYLON.Color3(0, 0, 1);
            lightSphere2.material   = material3;

            // Sphere material
            material.diffuseColor = new BABYLON.Color3(1, 1, 1);
            sphere.material       = material;

            // Lights colors
            light0.diffuse  = new BABYLON.Color3(1, 0, 0);
            light0.specular = new BABYLON.Color3(1, 0, 0);

            light1.diffuse  = new BABYLON.Color3(0, 1, 0);
            light1.specular = new BABYLON.Color3(0, 1, 0);

            light2.diffuse  = new BABYLON.Color3(0, 0, 1);
            light2.specular = new BABYLON.Color3(0, 0, 1);

            light3.diffuse  = new BABYLON.Color3(1, 1, 1);
            light3.specular = new BABYLON.Color3(1, 1, 1);

            // Skybox
            var skybox         = BABYLON.Mesh.CreateBox("skyBox", 100.0, scene);
            var skyboxMaterial = new BABYLON.StandardMaterial("skyBox", scene);

            skyboxMaterial.backFaceCulling   = false;
            skyboxMaterial.reflectionTexture = new BABYLON.CubeTexture("skybox", scene);
            skyboxMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
            skyboxMaterial.diffuseColor  = new BABYLON.Color3(0, 0, 0);
            skyboxMaterial.specularColor = new BABYLON.Color3(0, 0, 0);
            skybox.material         = skyboxMaterial;
            skybox.infiniteDistance = true;

            // Animations
            var alpha = 0.0;

            scene.registerBeforeRender(() =>
            {
                light0.position = new BABYLON.Vector3(10 * Math.Sin(alpha), 0, 10 * Math.Cos(alpha));
                light1.position = new BABYLON.Vector3(10 * Math.Sin(alpha), 0, -10 * Math.Cos(alpha));
                light2.position = new BABYLON.Vector3(10 * Math.Cos(alpha), 0, 10 * Math.Sin(alpha));

                lightSphere0.position = light0.position;
                lightSphere1.position = light1.position;
                lightSphere2.position = light2.position;

                alpha += 0.01;
            });

            this.scene.activeCamera.attachControl(this.canvas);
        }
コード例 #8
0
        private void Scene19()
        {
            this.scene = new BABYLON.Scene(engine);
            var camera   = new BABYLON.ArcRotateCamera("Camera", 0, 0, 10, BABYLON.Vector3.Zero(), scene);
            var material = new BABYLON.StandardMaterial("kosh", scene);

            material.diffuseColor = BABYLON.Color3.Purple();
            var light = new BABYLON.PointLight("Omni0", new BABYLON.Vector3(-17.6, 18.8, -49.9), scene);

            camera.setPosition(new BABYLON.Vector3(-15, 10, -20));
            camera.minZ = 1.0;
            camera.maxZ = 120.0;

            // Skybox
            var skybox         = BABYLON.Mesh.CreateBox("skyBox", 100.0, scene);
            var skyboxMaterial = new BABYLON.StandardMaterial("skyBox", scene);

            skyboxMaterial.backFaceCulling   = false;
            skyboxMaterial.reflectionTexture = new BABYLON.CubeTexture("skybox", scene);
            skyboxMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
            skyboxMaterial.diffuseColor  = new BABYLON.Color3(0, 0, 0);
            skyboxMaterial.specularColor = new BABYLON.Color3(0, 0, 0);
            skybox.material = skyboxMaterial;

            // depth material
            BABYLON.Effect.ShadersStore["depthVertexShader"] =
                "#ifdef GL_ES\n" +
                "precision highp float;\n" +
                "#endif\n" +
                "attribute vec3 position;\n" +
                "uniform mat4 worldViewProjection;\n" +
                "void main(void) {\n" +
                "gl_Position = worldViewProjection * vec4(position, 1.0);\n" +
                "}";
            BABYLON.Effect.ShadersStore["depthPixelShader"] =
                "#ifdef GL_ES\n" +
                "precision highp float;\n" +
                "#endif\n" +

                "void main(void) {\n" +
                "float depth =  1.0 - (2.0 / (100.0 + 1.0 - gl_FragCoord.z * (100.0 - 1.0)));\n" +
                "gl_FragColor = vec4(depth, depth, depth, 1.0);\n" +
                "}\n" +
                "";

            var depthMaterial = new BABYLON.ShaderMaterial(
                "depth",
                scene,
                "depth",
                new ShaderMaterialOptions()
            {
                attributes = new Array <string>("position"),
                uniforms   = new Array <string>("worldViewProjection")
            });

            depthMaterial.backFaceCulling = false;

            // Plane
            var plane = BABYLON.Mesh.CreatePlane("map", 10, scene);

            plane.billboardMode = BABYLON.AbstractMesh.BILLBOARDMODE_ALL;
            plane.scaling.y     = 1.0 / engine.getAspectRatio(scene.activeCamera);

            // Render target
            var renderTarget = new BABYLON.RenderTargetTexture(
                "depth",
                new BABYLON.Size()
            {
                width = 1024, height = 1024
            },
                scene);

            renderTarget.renderList.Add(skybox);
            scene.customRenderTargets.Add(renderTarget);

            renderTarget.onBeforeRender = () =>
            {
                for (var index = 0; index < renderTarget.renderList.Length; index++)
                {
                    renderTarget.renderList[index]._savedMaterial = renderTarget.renderList[index].material;
                    renderTarget.renderList[index].material       = depthMaterial;
                }
            };

            renderTarget.onAfterRender = () =>
            {
                // Restoring previoux material
                for (var index = 0; index < renderTarget.renderList.Length; index++)
                {
                    renderTarget.renderList[index].material = renderTarget.renderList[index]._savedMaterial;
                }
            };

            // Spheres
            var spheresCount = 20;
            var alpha        = 0.0;

            for (var index = 0; index < spheresCount; index++)
            {
                var sphere = BABYLON.Mesh.CreateSphere("Sphere" + index, 32, 3, scene);
                sphere.position.x = 10 * Math.Cos(alpha);
                sphere.position.z = 10 * Math.Sin(alpha);
                sphere.material   = material;

                alpha += (2 * Math.PI) / spheresCount;

                renderTarget.renderList.Add(sphere);
            }

            // Plane material
            var mat = new BABYLON.StandardMaterial("plan mat", scene);

            mat.diffuseColor    = BABYLON.Color3.Black();
            mat.specularColor   = BABYLON.Color3.Black();
            mat.emissiveTexture = renderTarget;

            plane.material = mat;

            // Animations
            var isReady = false;

            scene.registerBeforeRender(() =>
            {
                camera.alpha += 0.01 * scene.getAnimationRatio();

                if (!isReady && scene.isReady())
                {
                    isReady = true;
                }
            });

            this.scene.activeCamera.attachControl(this.canvas);
        }