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

news/2024/10/19 11:51:57/

"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 = trueconst 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.ppmy.cn/news/1540245.html

相关文章

mysql学习教程,从入门到精通,SQL 约束(Constraints)(41)

在数据库设计中&#xff0c;约束&#xff08;Constraints&#xff09;用于确保数据的准确性和完整性。它们通过限制可以插入到数据库表中的数据类型来防止无效数据。SQL 中有几种常见的约束类型&#xff0c;包括主键约束&#xff08;Primary Key&#xff09;、外键约束&#xf…

M3D: Advancing 3D Medical Image Analysis with Multi-Modal Large Language Models

原文链接&#xff1a;https://arxiv.org/abs/2404.00578 研究背景 背景介绍: 这篇文章的研究背景是医学图像分析在临床诊断和治疗中至关重要&#xff0c;尤其是多模态大语言模型&#xff08;MLLMs&#xff09;在这一领域的应用。然而&#xff0c;现有的研究主要集中在2D医学图…

目标检测——Libra R-CNN算法解读

论文&#xff1a;Libra R-CNN: Towards Balanced Learning for Object Detection (2019.4.4) 作者&#xff1a;Jiangmiao Pang, Kai Chen, Jianping Shi, Huajun Feng, Wanli Ouyang, Dahua Lin 链接&#xff1a;https://arxiv.org/abs/1904.02701 代码&#xff1a;https://git…

如何给手机换ip地址

在当今数字化时代&#xff0c;IP地址作为设备在网络中的唯一标识&#xff0c;扮演着举足轻重的角色。然而&#xff0c;有时出于隐私保护、网络访问需求或其他特定原因&#xff0c;我们可能需要更改手机的IP地址。本文将详细介绍几种实用的方法&#xff0c;帮助您轻松实现手机IP…

2024-10-18 问AI: [AI面试题] 神经网络有哪些不同类型?

文心一言 神经网络有多种不同类型&#xff0c;每种类型都有其特定的结构和应用场景。以下是一些主要的神经网络类型&#xff1a; 前馈神经网络&#xff08;FNN&#xff09;&#xff1a; 也称为全连接神经网络或感知器网络。由输入层、隐藏层和输出层组成&#xff0c;信息流是单…

20201017-【C、C++】跳动的爱心

效果图片 代码 #include "graphics.h" #include <conio.h> #include <time.h> #include <math.h> #include <stdlib.h>struct Point {double x, y;COLORREF color; };COLORREF colors[256] {RGB(255,32,83),RGB(252,222,250),RGB(255,0,0)…

启动service报错ORA-44317: database open read-only

ADG&#xff08;RAC&#xff09;备库环境&#xff0c;srvctl添加service服务成功&#xff0c;启动service时报错ORA-44317: database open read-only。 这是预期行为&#xff0c; 使用“srvctl add service -d <db_name> -s <service_name>”创建服务时&#xff0c…

【c++/C#】 混编的多线程,thread_local,

C 通过 thread_local 变量来实现线程局部存储&#xff08;Thread-Local Storage, TLS&#xff09;&#xff0c;而 C 动态库并不需要直接感知线程是从 C 还是 C# 端创建的。线程的管理、调度等由操作系统处理&#xff0c;而 thread_local 的工作机制是与具体的编程语言无关的。让…