• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

typescript结合three.js

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
import * as THREE from "three";

// https://github.com/pinqy520/three-typescript-starter/blob/master/src/index.ts
class Game
{
    private _scene: THREE.Scene;
    //private _canvas: HTMLCanvasElement;
    private _camera: THREE.PerspectiveCamera;
    private _renderer: THREE.WebGLRenderer;
    private _axis: THREE.AxisHelper;
    private _light: THREE.DirectionalLight;
    private _light2: THREE.DirectionalLight;
    private _material: THREE.MeshBasicMaterial;
    private _box: THREE.Mesh;

    public constructor()
    {
        //this._canvas = <HTMLCanvasElement>document.getElementById(canvasElement);
        this._scene = new THREE.Scene();
        this._camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
        this._renderer = new THREE.WebGLRenderer();
        this._axis = new THREE.AxisHelper(10);
        this._light = new THREE.DirectionalLight(0xffffff, 1.0);
        this._light2 = new THREE.DirectionalLight(0xffffff, 1.0);
        this._material = new THREE.MeshBasicMaterial({
            color: 0xaaaaaa,
            wireframe: true
        });
        this._box = new THREE.Mesh(new THREE.BoxGeometry(1, 1, 1), this._material);
    }

    public createScene(): void
    {
        this._renderer.setSize(window.innerWidth, window.innerHeight);
        document.body.appendChild(this._renderer.domElement);
        this._scene.add(this._axis);
        this._light.position.set(100, 100, 100);
        this._scene.add(this._light);
        this._light2.position.set(-100, 100, -100)
        this._scene.add(this._light2);
        this._box.position.x = 0.5;
        this._box.rotation.y = 0.5;

        this._camera.position.x = 5;
        this._camera.position.y = 5;
        this._camera.position.z = 5;

        this._camera.lookAt(this._scene.position);
    }

    public animate(): void
    {
        requestAnimationFrame(this.animate);
        this._render();
    }

    private _render(): void
    {
        let timer = 0.002 * Date.now()
        this._box.position.y = 0.5 + 0.5 * Math.sin(timer)
        this._box.rotation.x += 0.1
        this._renderer.render(this._scene, this._camera)
    }
}

window.onload = () =>
{
    let game = new Game();
    game.createScene();
    game.animate();
}


https://stackoverflow.com/questions/35968047/using-webpack-threejs-examples-and-typescript
https://stackoverflow.com/questions/43799041/typescript-error-node-modules-types-three-three-core-d-ts767-24-error-ts230

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Typescript学习笔记发布时间:2022-07-18
下一篇:
Springboot+mybatis+React+redux+React-router+antd+Typescript(二):React+Typescrip ...发布时间:2022-07-18
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap