当前位置: 首页 > article >正文

Threejs 实现3D 地图(01)创建基本场景

"d3": "^7.9.0",
"three": "^0.169.0",
"vue": "^3.5.10"
<script setup>
import { onMounted,ref } from 'vue'
import * as THREE from 'three'
import * as d3 from "d3";  //莫开托坐标 矫正地图坐标
import map from './constant/map.json'
// 引入轨道控制器扩展库OrbitControls.js
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
// 拿到页面的宽高
const width = window.innerWidth, height = window.innerHeight;

// 创建场景
const scene = new THREE.Scene();
// 将背景颜色设置为白色
scene.background = new THREE.Color("#000000");

// 创建相机
const camera = new THREE.PerspectiveCamera(70, width / height, 0.01, 10000);
// 设置相机位置
camera.position.z = 1000;

// // 辅助线 AxesHelper
const axesHelper = new THREE.AxesHelper( 500 );
scene.add( axesHelper );

// 初始化渲染器
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(width, height);

// 设置相机控件轨道控制器OrbitControls
const controls = new OrbitControls(camera, renderer.domElement);
//阻尼 更真实
controls.enableDamping = true

const initGeom = () => {
  // 添加一个物体(测试是否显示)
  const geometry = new THREE.BoxGeometry( 200, 200,200 );
  const material = new THREE.MeshBasicMaterial( {color: 0x00ff00} );
  const cube = new THREE.Mesh( geometry, material );
  scene.add( cube );
}

// 渲染页面
const render = () => {
  // 将场景(scene)和摄像机(camera 加入进来)
  renderer.render(scene, camera)
  // 渲染下一帧的时候会调用render函数
  requestAnimationFrame(render)
  controls.update()
}

const initLight = () => {
  // 基本光源
  const ambLight = new THREE.AmbientLight('#ffffff', 0.3)
  /**
   * 设置聚光灯相关的的属性
   */
  const spotLight = new THREE.SpotLight(0xFFFFFF); // 聚光灯
  spotLight.position.set(40, 200, 10);
  spotLight.castShadow = true; // 只有该属性为true时,该点光源允许产生阴影,并且下列属性可用
  scene.add(ambLight, spotLight); // 向场景中添加光源
}

onMounted(() => {
  // 添加物体到场景
  initGeom()
  // 渲染
  render()
  // 设置环境光
  initLight()
  // 将渲染加入到页面上
  document.body.appendChild(renderer.domElement);
})
</script>

<template>
  <div id="info"></div>
</template>

<style scoped>

</style>

下一篇:Threejs 实现3D 地图(02)创建3d 地图-CSDN博客 


http://www.kler.cn/news/355500.html

相关文章:

  • Parameter-Efficient Fine-Tuning for Large Models: A Comprehensive Survey阅读笔记
  • LeetCode1658.将x减到0的最小操作数
  • PHP爬虫API:获取商品详情的新利器
  • uniapp uni.uploadFile errMsg: “uploadFile:fail
  • PTA L1系列题解(C语言)(L1_073 -- L1_080)
  • php常用设计模式之单例模式
  • HikariPool连接池报错(Possibly consider using a shorter maxLifetime value)
  • 健康推荐新动力:SpringBoot智能系统
  • PostgreSQL与MySQL在语法上的区别
  • 【飞腾加固服务器】全国产化解决方案:飞腾FT2000+/64核,赋能关键任务保驾护航
  • 链动2+1芸众商城421+全插件独立版源码
  • C++ 在项目中使用GDB
  • element设置时间和日期框早于现在的时间和日期禁用
  • 微积分复习笔记 Calculus Volume 1 - 3.1 Defining the Derivative
  • 随机抽取学号
  • Spring Boot 3新特性@RSocketExchange轻松实现消息实时推送
  • LlamaIndex核心概念查询管道(Query Pipelines)简介
  • java-poi实现自定义注解excel生成合并单元格数据导出
  • VScode运行C语言终端输出中文乱码问题解决方案
  • qt+opengl 实现一个3D立体体