threejs入门示例

1. 渲染一个方块

 

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
		<title>three.js</title>
	</head>
	<body>
		<div id="info"><a href="https://threejs.org" target="_blank" rel="noopener">three.js</a></div>
		<script type="module">
            import * as THREE from 'https://cdn.skypack.dev/three@0.137.0';
            // 场景
            const scene = new THREE.Scene();
            init()
            function init(){
                // render
                let renderer = new THREE.WebGLRenderer();
				renderer.setPixelRatio( window.devicePixelRatio );
				renderer.setSize( window.innerWidth, window.innerHeight );
				document.body.appendChild( renderer.domElement );
                // 透视相机
                let camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.1, 200 );
                // 相机位置
				camera.position.set( 0, 0, 10 );
                // 物体
                let line = new THREE.Mesh(
                    INIT_GEOMETRY(), // 几何体
                    INIT_MATERIAL() // 材质
                )
                // 把物体添加到场景中
                scene.add(line)
                renderer.render( scene, camera );
            }

            function INIT_GEOMETRY(){
                return new THREE.PlaneGeometry( 1, 1 );
            }

            function INIT_MATERIAL () {
                return new THREE.MeshBasicMaterial( {color: 0xffff00, side: THREE.DoubleSide} )
            }
	</script>
	</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值