public void CreateScene()
        {
            var canvas = Canvas.GetElementById(
                "game-window"
                );
            var engine = new Engine(
                canvas,
                true
                );
            var scene = new Scene(
                engine
                );
            var light0 = new PointLight(
                "Omni",
                new Vector3(
                    0,
                    2,
                    8
                    ),
                scene
                );
            var box1 = Mesh.CreateBox(
                "b1",
                1.0m,
                scene
                );
            var box2 = Mesh.CreateBox(
                "b1",
                1.0m,
                scene
                );

            box2.position = new Vector3(
                2m,
                0,
                0
                );
            var camera = new ArcRotateCamera(
                "ArcRotateCamera",
                (decimal)(System.Math.PI / 2),
                (decimal)(System.Math.PI / 4),
                6,
                new Vector3(1, 0, 0),
                scene
                )
            {
                lowerRadiusLimit     = 2,
                upperRadiusLimit     = 10,
                wheelDeltaPercentage = 0.01m
            };

            scene.activeCamera = camera;
            camera.attachControl(
                canvas,
                false
                );
            engine.runRenderLoop(() => Task.Run(() => scene.render(true, false)));

            _engine = engine;
        }
コード例 #2
0
ファイル: Main.cs プロジェクト: ARLM-Attic/babylon
        private void Scene1()
        {
            var camera = new ArcRotateCamera("Camera", 1, 0.8, 10, new Vector3(0, 0, 0), this.scene);
            var light0 = new PointLight("Omni", new Vector3(0, 0, 10), this.scene);
            var origin = Mesh.CreateSphere("origin", 10, 1.0, this.scene);

            // Attach the camera to the scene
            scene.activeCamera.attachControl(canvas);
        }
コード例 #3
0
ファイル: Main.cs プロジェクト: ARLM-Attic/babylon
 private void Scene5()
 {
     SceneLoader.Load(
         "",
         "Spaceship.babylon",
         engine,
         loadedScene =>
     {
         this.scene = loadedScene;
         var camera = new ArcRotateCamera("Camera", 0, 0.8, 100, this.scene.meshes[0], scene);
         this.scene.meshes[0].scaling = new Vector3(0.04, 0.04, 0.04);
         this.scene.activeCamera.detachControl(this.canvas);
         this.scene.activeCamera = camera;
         this.scene.activeCamera.attachControl(this.canvas);
     });
 }
コード例 #4
0
 private void Scene20()
 {
     SceneLoader.Load(
         "",
         "SSAOcat.babylon",
         engine,
         loadedScene =>
     {
         this.scene = loadedScene;
         // Attach the camera to the scene
         var camera = new ArcRotateCamera("Camera", 0, 0.8, 100, this.scene.meshes[0], scene);
         this.scene.activeCamera.detachControl(this.canvas);
         this.scene.activeCamera = camera;
         this.scene.activeCamera.attachControl(this.canvas);
     });
 }
コード例 #5
0
ファイル: Main.cs プロジェクト: ARLM-Attic/babylon
 private void Scene6()
 {
     SceneLoader.Load(
         "",
         "Viper.babylon",
         engine,
         loadedScene =>
     {
         this.scene = loadedScene;
         var camera = new ArcRotateCamera("Camera", 0, 0.8, 100, this.scene.meshes[0], scene);
         // Attach the camera to the scene
         this.scene.meshes[0].scaling = new Vector3(4.0, 4.0, 4.0);
         this.scene.activeCamera.detachControl(this.canvas);
         this.scene.activeCamera = camera;
         this.scene.activeCamera.attachControl(this.canvas);
     });
 }
コード例 #6
0
        public async ValueTask CreateScene()
        {
            var canvas = await Canvas.GetElementById(
                "game-window"
                );

            var engine = await Engine.NewEngine(
                canvas,
                true
                );

            var scene = await Scene.NewScene(
                engine
                );

            var light0 = await PointLight.NewPointLight(
                "Omni",
                await Vector3.NewVector3(
                    0,
                    100,
                    8
                    ),
                scene
                );

            var light1 = await HemisphericLight.NewHemisphericLight(
                "HemisphericLight",
                await Vector3.NewVector3(
                    0,
                    100,
                    8
                    ),
                scene
                );

            var Player = await SceneLoader.ImportMesh(
                null,
                "assets/",
                "Shark.glb",
                scene,
                new ActionCallback <AbstractMesh[], IParticleSystem[], Skeleton[], AnimationGroup[], TransformNode[], Geometry[], Light[]>(async(arg1, arg2, arg3, arg4, arg5, arg6, arg7) =>
            {
                foreach (var animation in arg4)
                {
                    await animation.stop();
                    _animationMap.Add(await animation.get_name(), animation);
                }

                if (_animationMap.Count > 0)
                {
                    _runningAnimation = _animationMap.First().Value;
                    await _runningAnimation.start(true);
                }
            })
                );

            var camera = await ArcRotateCamera.NewArcRotateCamera(
                "ArcRotateCamera",
                (decimal)(System.Math.PI / 2),
                (decimal)(System.Math.PI / 4),
                0,
                await Vector3.NewVector3(0, 1, 0),
                scene
                );

            // This positions the camera
            await camera.setPosition(await Vector3.NewVector3(30, 10, -30));

            await camera.set_lowerRadiusLimit(2);

            await camera.set_upperRadiusLimit(100);

            await camera.set_wheelDeltaPercentage(0.01m);

            await scene.set_activeCamera(camera);

            await camera.attachControl(
                false
                );

            await engine.runRenderLoop(new ActionCallback(
                                           () => Task.Run(() => scene.render(true, false))
                                           ));

            _engine = engine;
        }
        public async Task CreateSceneAsync()
        {
            var canvas = await Canvas.GetElementById(
                "game-window"
                );

            var engine = await Engine.NewEngine(
                canvas,
                true
                );

            // This creates a basic Babylon Scene object (non-mesh)
            var scene = await Scene.NewScene(engine);

            await scene.set_clearColor(
                await Color4.NewColor4(
                    0.31m,
                    0.48m,
                    0.64m,
                    1
                    )
                );

            //add an arcRotateCamera to the scene
            var camera = await ArcRotateCamera.NewArcRotateCamera(
                "camera",
                await Tools.ToRadians(125),
                await Tools.ToRadians(70), 25,
                await Vector3.NewVector3(0, 3, 0),
                scene
                );

            await camera.set_lowerRadiusLimit(10);

            await camera.set_upperRadiusLimit(40);

            // This attaches the camera to the canvas
            await camera.attachControl(true);

            //array for holding the cannon and "paired" animation group
            var cannonAnimationPairings = new Dictionary <string, string>();

            //array for holding readyToPlay status for the cannons
            var cannonReadyToPlay = new Dictionary <string, int>();

            //Load the tower assets
            var pirateFortImportEntity = await SceneLoader.ImportMeshAsync(
                "",
                "https://models.babylonjs.com/pirateFort/",
                "pirateFort.glb",
                scene
                );

            var pirateFortImport = pirateFortImportEntity.ToEntity <SceneLoaderImportMeshEntity>();
            var meshes           = await pirateFortImport.get_meshes();

            await meshes[0].set_name("pirateFort");
            var   seaMesh = await scene.getMeshByName("sea");

            await(await seaMesh.get_material()).set_needDepthPrePass(true);
            await(await scene.getLightByName("Sun")).set_intensity(12);

            //Load the cannon model and create clones
            var cannonImportResult = (await SceneLoader.ImportMeshAsync(
                                          "",
                                          "https://models.babylonjs.com/pirateFort/",
                                          "cannon.glb",
                                          scene
                                          )).ToEntity <SceneLoaderImportMeshEntity>();
            //remove the top level root node
            var cannonMeshs = await cannonImportResult.get_meshes();

            var cannon = (await cannonMeshs[0].getChildren())[0];
            await cannon.setParent(null);

            await cannonMeshs[0].dispose();

            //set the metadata of each mesh to filter on later
            var cannonMeshes = await cannon.getChildMeshes();

            for (var i = 0; i < cannonMeshes.Length; i++)
            {
                var metadata = await NodeMetadata.NewNodeMetadata();

                await metadata.set_name("cannon");

                await cannonMeshes[i].set_metadata(metadata);
            }

            var importedAnimGroups = await cannonImportResult.get_animationGroups();

            //loop through all imported animation groups and copy the animation curve data to an array.
            var animations = new Animation[importedAnimGroups.Length];

            for (var i = 0; i < importedAnimGroups.Length; i++)
            {
                await importedAnimGroups[i].stop();
                animations[i] = await(await importedAnimGroups[i].get_targetedAnimations())[0].get_animation();
                await importedAnimGroups[i].dispose();
            }

            //create a new animation group and add targeted animations based on copied curve data from the "animations" array.
            var cannonAnimGroup = await AnimationGroup.NewAnimationGroup(
                "cannonAnimGroup"
                );

            await cannonAnimGroup.addTargetedAnimation(
                animations[0],
                (await cannon.getChildMeshes())[1]
                );

            await cannonAnimGroup.addTargetedAnimation(
                animations[1],
                (await cannon.getChildMeshes())[0]
                );

            //create a box for particle emission, position it at the muzzle of the cannon, turn off visibility and parent it to the cannon mesh
            var particleEmitter = await MeshBuilder.CreateBox(
                "particleEmitter",
                new { size = 0.05 },
                scene
                );

            await particleEmitter.set_position(await Vector3.NewVector3(
                                                   0,
                                                   0.76m,
                                                   1.05m
                                                   ));

            await(await particleEmitter.get_rotation()).set_x(await Tools.ToRadians(78.5m));
            await particleEmitter.set_isVisible(false);

            await particleEmitter.setParent(
                (await cannon.getChildMeshes())[1]
                );

            //load particle system from the snippet server and set the emitter to the particleEmitter. Set its stopDuration.
            var baseurl = await Tools.get_BaseUrl();

            var snippetUrl = await ParticleHelper.get_SnippetUrl();

            var smokeBlast = await ParticleHelper.CreateFromSnippetAsync(
                "LCBQ5Y#6",
                scene,
                false,
                await ParticleHelper.get_SnippetUrl()
                );

            await smokeBlast.set_emitter(particleEmitter);

            await smokeBlast.set_targetStopDuration(0.2m);

            //load a cannon blast sound
            var cannonBlastSound = await Sound.NewSound(
                "music",
                "https://assets.babylonjs.com/sound/cannonBlast.mp3",
                scene
                );

            //position and rotation data for the placement of the cannon clones
            var cannonPositionArray = new Vector3[][] {
                new Vector3[]
                {
                    await Vector3.NewVector3(0.97m, 5.52m, 1.79m),
                    await Vector3.NewVector3(await Tools.ToRadians(0), await Tools.ToRadians(0), await Tools.ToRadians(180))
                },

                new Vector3[]
                {
                    await Vector3.NewVector3(1.08m, 2.32m, 3.05m),
                    await Vector3.NewVector3(await Tools.ToRadians(0), await Tools.ToRadians(0), await Tools.ToRadians(180))
                },

                new Vector3[]
                {
                    await Vector3.NewVector3(1.46m, 2.35m, -0.73m),
                    await Vector3.NewVector3(await Tools.ToRadians(0), await Tools.ToRadians(90), await Tools.ToRadians(180))
                },

                new Vector3[]
                {
                    await Vector3.NewVector3(1.45m, 5.52m, -1.66m),
                    await Vector3.NewVector3(await Tools.ToRadians(0), await Tools.ToRadians(90), await Tools.ToRadians(180))
                },

                new Vector3[]
                {
                    await Vector3.NewVector3(1.49m, 8.69m, -0.35m),
                    await Vector3.NewVector3(await Tools.ToRadians(0), await Tools.ToRadians(90), await Tools.ToRadians(180))
                },

                new Vector3[]
                {
                    await Vector3.NewVector3(-1.37m, 8.69m, -0.39m),
                    await Vector3.NewVector3(await Tools.ToRadians(0), await Tools.ToRadians(-90), await Tools.ToRadians(180))
                },

                new Vector3[]
                {
                    await Vector3.NewVector3(0.58m, 4, -2.18m),
                    await Vector3.NewVector3(await Tools.ToRadians(0), await Tools.ToRadians(180), await Tools.ToRadians(180))
                },

                new Vector3[]
                {
                    await Vector3.NewVector3(1.22m, 8.69m, -2.5m),
                    await Vector3.NewVector3(await Tools.ToRadians(0), await Tools.ToRadians(180), await Tools.ToRadians(180))
                },

                new Vector3[]
                {
                    await Vector3.NewVector3(-1.31m, 2.33m, -2.45m),
                    await Vector3.NewVector3(await Tools.ToRadians(0), await Tools.ToRadians(180), await Tools.ToRadians(180))
                },

                new Vector3[]
                {
                    await Vector3.NewVector3(-3.54m, 5.26m, -2.12m),
                    await Vector3.NewVector3(await Tools.ToRadians(0), await Tools.ToRadians(-90), await Tools.ToRadians(180))
                }
            };

            //create 10 cannon clones, each with unique position/rotation data. Note that particle systems are cloned with parent meshes
            //also create 10 new animation groups with targeted animations applied to the newly cloned meshes
            for (var i = 0; i < 10; i++)
            {
                var cannonClone = await cannon.clone <AbstractMesh>(
                    "cannonClone" + i
                    );

                await cannonClone.set_position(cannonPositionArray[i][0]);

                await cannonClone.set_rotation(cannonPositionArray[i][1]);

                var cannonAnimGroupClone = await AnimationGroup.NewAnimationGroup(
                    "cannonAnimGroupClone" + i
                    );

                await cannonAnimGroupClone.addTargetedAnimation(
                    await (await cannonAnimGroup.get_targetedAnimations())[0].get_animation(),
                    (await cannonClone.getChildMeshes())[1]);

                await cannonAnimGroupClone.addTargetedAnimation(
                    await (await cannonAnimGroup.get_targetedAnimations())[1].get_animation(),
                    (await cannonClone.getChildMeshes())[0]);

                //store a key/value pair of each clone name and the name of the associated animation group name.
                cannonAnimationPairings[await cannonClone.get_name()] = await cannonAnimGroupClone.get_name();

                //store key/value pair for the cannon name and it's readyToPlay status as 1;
                cannonReadyToPlay[await cannonClone.get_name()] = 1;
            }
            //dispose of the original cannon, animation group, and particle system
            await cannon.dispose();

            await cannonAnimGroup.dispose();

            await smokeBlast.dispose();

            //create an array for all particle systems in the scene, loop through it and stop all systems from playing.
            var smokeBlasts = await scene.get_particleSystems();

            for (var i = 0; i < smokeBlasts.Length; i++)
            {
                await smokeBlasts[i].stop();
            }

            //logic of what happens on a click
            await(await scene.get_onPointerObservable()).add(async(pointerInfo, eventState) =>
            {
                // PointerEventTypes.POINTERDOWN
                if (await pointerInfo.get_type() != 1)
                {
                    return;
                }
                var pickResult = await pointerInfo.get_pickInfo();
                //check if a mesh was picked and if that mesh has specific metadata
                var pickedMesh = await pickResult.get_pickedMesh();
                if (pickedMesh != null &&
                    await pickedMesh.get_metadata() != null)
                {
                    var metadataNode = (await pickedMesh.get_metadata()).ToEntity <NodeMetadata>();
                    if (await metadataNode.get_name() != "cannon")
                    {
                        return;
                    }
                    //find the top level parent (necessary since the cannon is an extra layer below the clone root)
                    var topParent = await(await pickResult.get_pickedMesh()).get_parent();
                    var parent    = await topParent.get_parent();
                    if (parent != null &&
                        await parent.get_name() != null)
                    {
                        topParent = parent;
                    }
                    var name = await topParent.get_name();
                    //wrap all 'play' elements into a check to make sure the cannon can be played.
                    if (cannonReadyToPlay[name] == 1)
                    {
                        //set the readyToPlay status to 0
                        cannonReadyToPlay[name] = 0;
                        //loop through all of the animation groups in the scene and play the correct group based on the top level parent of the picked mesh.
                        var animationToPlay = cannonAnimationPairings[name];
                        for (var i = 0; i < (await scene.get_animationGroups()).Length; i++)
                        {
                            if (await(await scene.get_animationGroups())[i].get_name() == animationToPlay)
                            {
                                await(await scene.get_animationGroups())[i].play();
                                //after the animation has finished, set the readyToPlay status for this cannon to 1;
                                await(await(await scene.get_animationGroups())[i].get_onAnimationGroupEndObservable()).addOnce(async(_, __) =>
                                {
                                    cannonReadyToPlay[await topParent.get_name()] = 1;
                                });
                            }
                        }
                        //loop through all particle systems in the scene, loop through all picked mesh submeshes. if there is a matching mesh and particle system emitter, start the particle system.
                        var childMeshes = await(await pickResult.get_pickedMesh()).getChildMeshes();
                        for (var i = 0; i < smokeBlasts.Length; i++)
                        {
                            for (var j = 0; j < childMeshes.Length; j++)
                            {
                                if (childMeshes[j].___guid == (await smokeBlasts[i].get_emitter()).___guid)
                                {
                                    await smokeBlasts[i].start();
                                }
                            }
                        }
                        await cannonBlastSound.play();
                    }
                }
            });
            //scene.onPointerDown = function(evt, pickResult) {
            //    //check if a mesh was picked and if that mesh has specific metadata
            //    if (pickResult.pickedMesh && pickResult.pickedMesh.metadata === "cannon")
            //    {
            //        //find the top level parent (necessary since the cannon is an extra layer below the clone root)
            //        var topParent = pickResult.pickedMesh.parent;
            //        if (topParent.parent)
            //        {
            //            topParent = topParent.parent;
            //        }

            //        //wrap all 'play' elements into a check to make sure the cannon can be played.
            //        if (cannonReadyToPlay[topParent.name] === 1)
            //        {
            //            //set the readyToPlay status to 0
            //            cannonReadyToPlay[topParent.name] = 0;
            //            //loop through all of the animation groups in the scene and play the correct group based on the top level parent of the picked mesh.
            //            var animationToPlay = cannonAnimationPairings[topParent.name];
            //            for (var i = 0; i < scene.animationGroups.length; i++)
            //            {
            //                if (scene.animationGroups[i].name === animationToPlay)
            //                {
            //                    scene.animationGroups[i].play();
            //                    //after the animation has finished, set the readyToPlay status for this cannon to 1;
            //                    scene.animationGroups[i].onAnimationGroupEndObservable.addOnce(() =>
            //                    {
            //                        cannonReadyToPlay[topParent.name] = 1;
            //                    });
            //                }
            //            }
            //            //loop through all particle systems in the scene, loop through all picked mesh submeshes. if there is a matching mesh and particle system emitter, start the particle system.
            //            var childMeshes = pickResult.pickedMesh.getChildMeshes();
            //            for (var i = 0; i < smokeBlasts.length; i++)
            //            {
            //                for (var j = 0; j < childMeshes.length; j++)
            //                {
            //                    if (childMeshes[j] === smokeBlasts[i].emitter)
            //                    {
            //                        smokeBlasts[i].start();
            //                    }
            //                }
            //            }
            //            cannonBlastSound.play();
            //        }
            //    }
            //};

            _scene = scene;
            await _scene.set_activeCamera(camera);

            await engine.runRenderLoop(new ActionCallback(
                                           () => Task.Run(() => _scene.render(true, false))
                                           ));

            _engine = engine;
        }
        public void CreateScene()
        {
            var canvas = Canvas.GetElementById(
                "game-window"
                );
            var engine = new Engine(
                canvas,
                true
                );
            var scene = new Scene(
                engine
                );

            scene.clearColor = new Color4(0, 0, 0, 0);
            var light0 = new PointLight(
                "Omni",
                new Vector3(
                    0,
                    100,
                    8
                    ),
                scene
                );
            var light1 = new HemisphericLight(
                "HemisphericLight",
                new Vector3(
                    0,
                    100,
                    8
                    ),
                scene
                );
            var advancedTexture = AdvancedDynamicTexture.CreateFullscreenUI("UI");
            var UiPanel         = new StackPanel("name")
            {
                width               = "220px",
                fontSize            = "14px",
                horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_RIGHT,
                verticalAlignment   = Control.VERTICAL_ALIGNMENT_CENTER
            };

            advancedTexture.addControl(UiPanel);

            var house = SceneLoader.ImportMesh(
                null,
                "assets/",
                "Player.glb",
                scene,
                new Interop.Callbacks.ActionCallback <AbstractMesh[], IParticleSystem[], Skeleton[], AnimationGroup[], TransformNode[], Geometry[], Light[]>((arg1, arg2, arg3, arg4, arg5, arg6, arg7) =>
            {
                foreach (var animation in arg4)
                {
                    animation.stop();
                    _animationMap.Add(animation.name, animation);
                    AddRunAnimationButton(
                        UiPanel,
                        animation.name
                        );
                }
                if (_animationMap.Count > 0)
                {
                    _runningAnimation = _animationMap.First().Value;
                    _runningAnimation.start(true);
                }
                return(Task.CompletedTask);
            })
                );
            var camera = new ArcRotateCamera(
                "ArcRotateCamera",
                (decimal)(System.Math.PI / 2),
                (decimal)(System.Math.PI / 4),
                3,
                new Vector3(0, 1, 0),
                scene
                )
            {
                lowerRadiusLimit     = 2,
                upperRadiusLimit     = 10,
                wheelDeltaPercentage = 0.01m
            };

            scene.activeCamera = camera;
            camera.attachControl(
                false
                );
            engine.runRenderLoop(new ActionCallback(
                                     () => Task.Run(() => scene.render(true, false))
                                     ));

            _engine = engine;
        }
        public async ValueTask CreateScene()
        {
            var canvas = await Canvas.GetElementById(
                "game-window"
                );

            var engine = await Engine.NewEngine(
                canvas,
                true
                );

            var scene = await Scene.NewScene(
                engine
                );

            var light0 = await PointLight.NewPointLight(
                "Omni",
                await Vector3.NewVector3(
                    0,
                    100,
                    8
                    ),
                scene
                );

            var light1 = await HemisphericLight.NewHemisphericLight(
                "HemisphericLight",
                await Vector3.NewVector3(
                    0,
                    100,
                    8
                    ),
                scene
                );

            var advancedTexture = await AdvancedDynamicTexture.CreateFullscreenUI("UI");

            var UiPanel = await StackPanel.NewStackPanel("name");

            await UiPanel.set_width("220px");

            await UiPanel.set_fontSize("14px");

            await UiPanel.set_horizontalAlignment(await Control.get_HORIZONTAL_ALIGNMENT_RIGHT());

            await UiPanel.set_verticalAlignment(await Control.get_VERTICAL_ALIGNMENT_CENTER());

            await advancedTexture.addControl(UiPanel);

            var house = await SceneLoader.ImportMesh(
                null,
                "assets/",
                "Player.glb",
                scene,
                new Server.Interop.Callbacks.ActionCallback <AbstractMesh[], IParticleSystem[], Skeleton[], AnimationGroup[]>(async(arg1, arg2, arg3, arg4) =>
            {
                foreach (var animation in arg4)
                {
                    await animation.stop();
                    _animationMap.Add(await animation.get_name(), animation);
                    await AddRunAnimationButton(
                        UiPanel,
                        await animation.get_name()
                        );
                }
                if (_animationMap.Count > 0)
                {
                    _runningAnimation = _animationMap.First().Value;
                    await _runningAnimation.start(true);
                }
            })
                );

            var camera = await ArcRotateCamera.NewArcRotateCamera(
                "ArcRotateCamera",
                (decimal)(System.Math.PI / 2),
                (decimal)(System.Math.PI / 4),
                3,
                await Vector3.NewVector3(0, 1, 0),
                scene
                );

            await camera.set_lowerRadiusLimit(2);

            await camera.set_upperRadiusLimit(10);

            await camera.set_wheelDeltaPercentage(0.01m);

            await scene.set_activeCamera(camera);

            await camera.attachControl(
                canvas,
                false
                );

            await engine.runRenderLoop(() => Task.Run(() => scene.render(true, false)));

            _engine = engine;
        }
コード例 #10
0
ファイル: Main.cs プロジェクト: ARLM-Attic/babylon
        private void Scene3()
        {
            // Creating a camera looking to the zero point (0,0,0), a light, and a sphere of size 1
            var camera = new ArcRotateCamera("Camera", 0, 0.8, 100, Vector3.Zero(), scene);
            var light0 = new PointLight("Omni", new Vector3(20, 20, 100), scene);

            //Creation of 6 spheres
            var sphere1 = Mesh.CreateSphere("Sphere1", 10, 6.0, scene);
            var sphere2 = Mesh.CreateSphere("Sphere2", 2, 7.0, scene);//Only two segments
            var sphere3 = Mesh.CreateSphere("Sphere3", 10, 9.0, scene);
            var sphere4 = Mesh.CreateSphere("Sphere4", 10, 9.0, scene);
            var sphere5 = Mesh.CreateSphere("Sphere5", 10, 9.0, scene);
            var sphere6 = Mesh.CreateSphere("Sphere6", 10, 9.0, scene);

            //Positioning spheres
            sphere1.position.x = 40;
            sphere2.position.x = 30;
            sphere3.position.x = 10;
            sphere4.position.x = 0;
            sphere5.position.x = -20;
            sphere6.position.x = -30;

            //Creation of a plane
            var plan = Mesh.CreatePlane("plan", 120, scene);

            plan.position.z = -10;
            plan.rotation.y = 3.14;

            //Creation of a material in wireFrame
            var materialSphere1 = new StandardMaterial("texture1", scene);

            materialSphere1.wireframe = true;

            //Creation of a red material with alpha
            var materialSphere2 = new StandardMaterial("texture2", scene);

            materialSphere2.diffuseColor = new Color3(1, 0, 0); //Red
            materialSphere2.alpha        = 0.3;


            //Creation of a material with an image
            var materialSphere3 = new StandardMaterial("texture3", scene);

            materialSphere3.diffuseTexture = new Texture("text.jpg", scene);

            //Creation of a material, with translated texture
            var materialSphere4 = new StandardMaterial("texture4", scene);

            materialSphere4.diffuseTexture = new Texture("text.jpg", scene)
            {
                vOffset = 0.1, uOffset = 0.4
            };
            //Offset of 10% vertical
            //Offset of 40% horizontal

            //Creation of a material with alpha texture
            var materialSphere5 = new StandardMaterial("texture5", scene);

            materialSphere5.diffuseTexture          = new Texture("Planet.png", scene); //Planet
            materialSphere5.diffuseTexture.hasAlpha = true;                             //Have an alpha

            //Creation of a material and allways show all the faces
            var materialSphere6 = new StandardMaterial("texture6", scene);

            materialSphere6.diffuseTexture          = new Texture("Planet.png", scene); //Planet
            materialSphere6.diffuseTexture.hasAlpha = true;                             //Have an alpha
            materialSphere6.backFaceCulling         = false;                            //Allways show all the faces of the element

            //Creation of a repeated textured material
            var materialPlan = new StandardMaterial("texturePlane", scene);

            materialPlan.diffuseTexture = new Texture("grass_texture.jpg", scene)
            {
                uScale = 5.0, vScale = 5.0
            };
            //Wood effect
            //Repeat 5 times on the Vertical Axes
            //Repeat 5 times on the Horizontal Axes
            materialPlan.backFaceCulling = false;//Allways show the front and the back of an element

            //Applying the materials to the mesh
            sphere1.material = materialSphere1;
            sphere2.material = materialSphere2;

            sphere3.material = materialSphere3;
            sphere4.material = materialSphere4;

            sphere5.material = materialSphere5;
            sphere6.material = materialSphere6;

            plan.material = materialPlan;

            // Attach the camera to the scene
            scene.activeCamera.attachControl(canvas);
        }
コード例 #11
0
ファイル: Scene2Provider.cs プロジェクト: r3h0/Demos
        public override Scene CreateScene(dom.HTMLCanvasElement canvas, Engine engine)
        {
            var scene = new Scene(engine);

            // Setup camera
            var camera = new ArcRotateCamera("Camera", 0, 0, 10, Vector3.Zero(), scene);

            camera.setPosition(new Vector3(-10, 10, 0));
            camera.attachControl(canvas, true);

            // Lights
            var light0 = new PointLight("Omni0", new Vector3(0, 10, 0), scene);
            var light1 = new PointLight("Omni1", new Vector3(0, -10, 0), scene);
            var light2 = new PointLight("Omni2", new Vector3(10, 0, 0), scene);
            var light3 = new DirectionalLight("Dir0", new Vector3(1, -1, 0), scene);

            var material = new StandardMaterial("kosh", scene);
            var sphere   = Mesh.CreateSphere("Sphere", 16, 3, scene);

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

            var redMaterial = new StandardMaterial("red", scene)
            {
                diffuseColor  = new Color3(0, 0, 0),
                specularColor = new Color3(0, 0, 0),
                emissiveColor = new Color3(1, 0, 0)
            };

            var greenMaterial = new StandardMaterial("green", scene)
            {
                diffuseColor  = new Color3(0, 0, 0),
                specularColor = new Color3(0, 0, 0),
                emissiveColor = new Color3(0, 1, 0)
            };

            var blueMaterial = new StandardMaterial("blue", scene)
            {
                diffuseColor  = new Color3(0, 0, 0),
                specularColor = new Color3(0, 0, 0),
                emissiveColor = new Color3(0, 0, 1)
            };

            lightSphere0.material = redMaterial;
            lightSphere1.material = greenMaterial;
            lightSphere2.material = blueMaterial;

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

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

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

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

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

            // Animations
            var alpha = 0.0;

            scene.beforeRender = () => {
                light0.position = new Vector3(10 * es5.Math.sin(alpha), 0, 10 * es5.Math.cos(alpha));
                light1.position = new Vector3(10 * es5.Math.sin(alpha), 0, -10 * es5.Math.cos(alpha));
                light2.position = new Vector3(10 * es5.Math.cos(alpha), 0, 10 * es5.Math.sin(alpha));

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

                alpha += 0.01;
            };

            return(scene);
        }
コード例 #12
0
        public override Scene CreateScene(dom.HTMLCanvasElement canvas, Engine engine)
        {
            var scene = new Scene(engine);

            // Create camera and light
            var light  = new PointLight("Point", new Vector3(5, 10, 5), scene);
            var camera = new ArcRotateCamera("Camera", 1, 0.8, 8, new Vector3(0, 0, 0), scene);

            camera.attachControl(canvas, true);

            // Create a sprite manager to optimize GPU ressources
            // Parameters : name, imgUrl, capacity, cellSize, scene
            var spriteManagerTrees = new SpriteManager("treesManager", "https://demos.retyped.com/dist/babylon.js/img/palm.png", 2000, 800, scene);

            //We create 2000 trees at random positions
            for (var i = 0; i < 2000; i++)
            {
                var tree = new Sprite("tree", spriteManagerTrees);
                tree.position.x = es5.Math.random() * 100 - 50;
                tree.position.z = es5.Math.random() * 100 - 50;
                tree.isPickable = true;

                //Some "dead" trees
                if (es5.Math.round(es5.Math.random() * 5) == 0)
                {
                    tree.angle      = es5.Math.PI * 90 / 180;
                    tree.position.y = -0.3;
                }
            }

            //Create a manager for the player's sprite animation
            var spriteManagerPlayer = new SpriteManager("playerManager", "https://demos.retyped.com/dist/babylon.js/img/player.png", 2, 64, scene);

            // First animated player
            var player = new Sprite("player", spriteManagerPlayer);

            player.playAnimation(0, 40, true, 100, null);
            player.position.y = -0.3;
            player.size       = 0.3;
            player.isPickable = true;

            // Second standing player
            var player2 = new Sprite("player2", spriteManagerPlayer);

            player2.stopAnimation(); // Not animated
            player2.cellIndex  = 2;  // Going to frame number 2
            player2.position.y = -0.3;
            player2.position.x = 1;
            player2.size       = 0.3;
            player2.invertU    = -1; //Change orientation
            player2.isPickable = true;

            // Picking
            spriteManagerTrees.isPickable  = true;
            spriteManagerPlayer.isPickable = true;

            scene.onPointerDown = (evt, pickInfo) =>
            {
                var pickResult = (PickingInfo)scene.pickSprite(scene.pointerX, scene.pointerY);
                if (pickResult.hit)
                {
                    var sprite = (Sprite)pickResult.pickedSprite;
                    sprite.angle += 0.5;
                }
            };

            return(scene);
        }
コード例 #13
0
        public void CreateScene()
        {
            var canvas = Canvas.GetElementById(
                "game-window"
                );
            var engine = new Engine(
                canvas,
                true
                );
            var scene = new Scene(
                engine
                );
            var light1 = new HemisphericLight(
                "HemisphericLight",
                new Vector3(1, 1, 0),
                scene
                );

            var columns = 6m;
            var rows    = 1m;

            var faceUV = new Vector4[6];

            for (var i = 0; i < 6; i++)
            {
                faceUV[i] = new Vector4(
                    i / columns,
                    0,
                    (i + 1) / columns,
                    1m / rows
                    );
            }

            var mat = new StandardMaterial(
                "mat",
                scene
                );
            var texture = new Texture(
                scene,
                "https://assets.babylonjs.com/environments/numbers.jpg"
                );

            mat.diffuseTexture = texture;

            var alpha = 1;
            var red   = new Color4(
                1,
                0,
                0,
                alpha
                );
            var blue = new Color4(
                0,
                0,
                1,
                alpha
                );
            var green = new Color4(
                0,
                1,
                0,
                alpha
                );

            var options = new
            {
                faceUV,
                wrap       = true,
                width      = 1,
                height     = 2,
                depth      = 3,
                faceColors = new List <Color4> {
                    green, green, green, green, blue, red
                }
            };

            var box = MeshBuilder.CreateBox(
                "box",
                options,
                scene
                );

            box.material = mat;

            var camera = new ArcRotateCamera(
                "ArcRotateCamera",
                (decimal)(Math.PI / 2),
                (decimal)(Math.PI / 4),
                10,
                new Vector3(0, 1, 0),
                scene
                );

            scene.activeCamera = camera;
            camera.attachControl(
                false
                );

            engine.runRenderLoop(new ActionCallback(
                                     () => Task.Run(() => scene.render(true, false))
                                     ));

            _engine = engine;
        }
コード例 #14
0
        public async ValueTask CreateScene()
        {
            var canvas = await Canvas.GetElementById(
                "game-window"
                );

            var engine = await Engine.NewEngine(
                canvas,
                true
                );

            var scene = await Scene.NewScene(
                engine
                );

            var light0 = await PointLight.NewPointLight(
                "Omni",
                await Vector3.NewVector3(
                    0,
                    2,
                    8
                    ),
                scene
                );

            var box1 = await Mesh.CreateBox(
                "b1",
                1.0m,
                scene
                );

            var box2 = await Mesh.CreateBox(
                "b1",
                1.0m,
                scene
                );

            await box2.set_position(await Vector3.NewVector3(
                                        2m,
                                        0,
                                        0
                                        ));

            var camera = await ArcRotateCamera.NewArcRotateCamera(
                "ArcRotateCamera",
                (decimal)(System.Math.PI / 2),
                (decimal)(System.Math.PI / 4),
                6,
                await Vector3.NewVector3(1, 0, 0),
                scene
                );

            await camera.set_lowerRadiusLimit(2);

            await camera.set_upperRadiusLimit(10);

            await camera.set_wheelDeltaPercentage(0.01m);

            await scene.set_activeCamera(camera);

            await camera.attachControl(
                canvas,
                false
                );

            await engine.runRenderLoop(() => Task.Run(() => scene.render(true, false)));

            _engine = engine;
        }