import * as THREE from '../libs/build/three.module.js';

import { OrbitControls } from '../libs/jsm/controls/OrbitControls.js'

import { CSS2DRenderer, CSS2DObject } from '../libs/jsm/renderers/CSS2DRenderer.js'

// 变量声明
let scene,camera,renderer,controls,load

// 场景实例化

scene=new THREE.Scene()

// 相机实例化

camera=new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 200)

// 相机位置

camera.position.set(20,20,20)

// 相机宽高比例

camera.aspect = window.innerWidth / window.innerHeight;

// 更新相机投影

camera.updateProjectionMatrix();

// 相机加入场景

scene.add(camera);

// 渲染器

renderer=new THREE.WebGLRenderer({

// 设置抗锯齿

antialias: true,

// 对数深度缓冲区

logarithmicDepthBuffer: true,

})

// 渲染器宽高

renderer.setSize(window.innerWidth , window.innerHeight)

// 渲染器颜色

 renderer.setClearColor(0xeeeeee,1.0);

// 根据视口调整大小

window.addEventListener("resize", () => {

camera.aspect = window.innerWidth / window.innerHeight;

camera.updateProjectionMatrix();

renderer.setSize(window.innerWidth, window.innerHeight);

});

// 渲染器加入页面

document.body.append(renderer.domElement)

// 控制器实例化

controls=new OrbitControls(camera,renderer.domElement)

// 渲染函数

function render(params) {

renderer.render(scene,camera)

// 引擎自动更新渲染器

requestAnimationFrame(render);

}

// 创建点光源

const dirLight = new THREE.SpotLight(0xffffff);

dirLight.position.set(0, 2, 10);

dirLight.intensity = 5;

dirLight.castShadow = true;

scene.add(dirLight)

// 创建环境光

  const aLight = new THREE.AmbientLight(0xffffff)
aLight.intensity = 3
scene.add(aLight)

render()

// 生成一个路面

load=new THREE.BoxGeometry( 20, 40, 0.8 );

const loadmaterial = new THREE.MeshBasicMaterial( {color: 0x999999} );

const loadMain = new THREE.Mesh(load, loadmaterial);

loadMain.rotation.x = -Math.PI / 2;

loadMain. receiveShadow = true;

scene.add(loadMain)

最新文章

  1. 专业上的常用的工具和类库集 By 老衣
  2. MySQL监控利器-Innotop
  3. touch — 设定文件的访问和修改时间
  4. scanf的一些技巧
  5. 将txt文件数据转成bin文件.
  6. Angular 2 从0到1 (三)
  7. IgnoreRoute——注册路由
  8. CoreProfiler/NanoProfiler
  9. linux远程管理工具
  10. Ajax.ActionLink 用法
  11. USACO Section 1.2 Transformations 解题报告
  12. Thinking in scala (6)----高阶函数----返回一个函数
  13. Spring+JTA+Atomikos+mybatis分布式事务管理
  14. Linux下的crontab定时执行任务命令详解(参考:https://www.cnblogs.com/longjshz/p/5779215.html)
  15. [官网]How to use distributed transactions with SQL Server on Docker
  16. VS2017编译LevelDB
  17. 数字证书及CA介绍
  18. 前端 - js方式Ajax/ jquery方式Ajax / 伪 ajax /伪ajax 进阶方式
  19. 关于Windows 8 合约
  20. 为什么说Thunderbird是最好的桌面RSS阅读器

热门文章

  1. idea 使用JRebel 报1099错误
  2. 快速确定execl 列数
  3. Postman 测试 Web Service 和 WCF
  4. 手机、ESP32单片机、MQTT服务器连接实验
  5. oracle job的使用
  6. Ubuntu 复制粘贴快捷键
  7. Android GNSS模块详解
  8. Linux内核机制—smp_hotplug_thread
  9. 【Java学习Day06】注释种类、符号及用法
  10. 查看linux 用户