Exemplo n.º 1
0
        private static void Init()
        {
            container = document.createElement("div");
            document.body.appendChild(container);

            //
            var height = GetAvailableHeight();
            var width  = window.innerWidth;

            camera = new PerspectiveCamera(50, width / height, 1, 10000)
            {
                position = { y = 300 }
            };
            cameraTarget = new Vector3(0, 150, 0);

            scene = new Scene
            {
                background = new Color(0xf0f0f0)
            };

            //
            var light = new DirectionalLight(0xefefff, 1.5);

            light.position.set(1, 1, 1).normalize();
            scene.add(light);

            light = new DirectionalLight(0xffefef, 1.5);
            light.position.set(-1, -1, -1).normalize();
            scene.add(light);

            var loader = new JSONLoader();

            loader.load("https://raw.githubusercontent.com/Retyped/Demos/master/ThreeJsDemo/ThreeJsDemo/dist/models/horse.js", (geometry, materials) =>
            {
                var mesh = new Mesh(geometry, new MeshLambertMaterial(new MeshLambertMaterialParameters
                {
                    vertexColors = FaceColors,
                    morphTargets = true
                }));

                mesh.scale.set(1.5, 1.5, 1.5);
                scene.add(mesh);

                mixer = new AnimationMixer(mesh);

                var clip = AnimationClip.CreateFromMorphTargetSequence("gallop", geometry.morphTargets, 30, false);
                mixer.clipAction(clip).setDuration(1).play();
            });

            //
            renderer = new WebGLRenderer();
            renderer.setPixelRatio(window.devicePixelRatio);
            renderer.setSize(width, height);
            container.appendChild(renderer.domElement);

            //
            window.addEventListener("resize", (dom.Event e) => OnWindowResize(), false);
        }