当前位置:网站首页>Threejs Internet of things, 3D visualization of farms (II)
Threejs Internet of things, 3D visualization of farms (II)
2022-07-05 04:02:00 【Zuo Ben】
1, Introduce
This example uses r95 edition Three.js library .
Main functions : Quote the farm model for display . The renderings are as follows :

2, Main description
farm 3D Show main use OBJLoader and MTLLoader Load the model and directly assign materials to display .
The imported model code is as follows :

3, Source code
var camera;
var renderer;
var mesh;
function init() {
// Create a scene , It will contain all our elements , Like an object , Cameras and lights .
var scene = new THREE.Scene();
var urls = [
'assets/textures/posx.jpg',
'assets/textures/negx.jpg',
'assets/textures/posy.jpg',
'assets/textures/negy.jpg',
'assets/textures/posz.jpg',
'assets/textures/negz.jpg'
];
var cubeLoader = new THREE.CubeTextureLoader();
scene.background = cubeLoader.load(urls);
// Create a camera , It defines where we are looking
camera = new THREE.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 0.1, 30000);
// Aim the camera at the center of the scene
camera.position.x = 5500;
camera.position.y = 3000;
camera.position.z = 2000;
camera.lookAt(scene.position);
var orbit = new THREE.OrbitControls(camera);
// Create a renderer and set the size ,WebGLRenderer The computer graphics card will be used to render the scene
// initialize basic renderer
renderer = new THREE.WebGLRenderer({
antialias: true,
logarithmicDepthBuffer: true,
});
renderer.setSize(window.innerWidth, window.innerHeight);
// Add ambient light
scene.add(new THREE.AmbientLight("#ffffff", 1.5));
// Add the output of the renderer to HTML Elements
document.getElementById("dom").appendChild(renderer.domElement);
// Display the coordinate axis on the screen
var axes = new THREE.AxesHelper(10000);
// scene.add(axes);
initModel();
// Start animation
renderScene();
// Add model
function initModel() {
var mtlLoader = new THREE.MTLLoader();
mtlLoader.setPath("assets/models/obj_mtl/")
mtlLoader.load('yangzhichang.mtl', function(materials) {
materials.preload();
var objLoader = new THREE.OBJLoader();
objLoader.setMaterials(materials);
objLoader.load('assets/models/obj_mtl/yangzhichang.obj', function(object) {
mesh = object;
object.traverse(function(node) {
if (node.material) {
node.material.side = THREE.DoubleSide;
}
});
scene.add(mesh);
});
});
}
document.addEventListener('click', onDocumentMouseDown, false);
function onDocumentMouseDown(event) {
// Click on the screen to create a vector
var vector = new THREE.Vector3((event.clientX / window.innerWidth) * 2 - 1, -(event.clientY / window
.innerHeight) * 2 + 1, 0.5);
vector = vector.unproject(camera); // Convert the coordinates of the screen into coordinates in the 3D scene
var raycaster = new THREE.Raycaster(camera.position, vector.sub(camera.position).normalize());
var intersects = raycaster.intersectObjects(mesh, true);
if (intersects.length > 0) {
var name = intersects[0].object.name;
var obj = scene.getObjectByName(name);
console.log(obj)
scene.remove(obj);
}
}
function renderScene() {
orbit.update();
requestAnimationFrame(renderScene);
renderer.render(scene, camera);
}
// Rendered scenes
renderer.render(scene, camera);
}
window.onload = init;4, download
Use threejs Rendering farm model source code , Farm model obj+mtl Format ,threejs Model , Model upgrade -Web Develop document resources -CSDN download Upgraded farm model , Use threejs Rendering model source code Threejs Rendering obj+mtl Model ,Threej More download resources 、 For learning materials, please visit CSDN Download channel .https://download.csdn.net/download/baidu_29701003/54824377 Need other source code 、 Please leave a message or contact me on wechat :1171053128
边栏推荐
- provide/inject
- Enterprise level: spire Office for . NET:Platinum|7.7. x
- How about programmers' eyesight| Daily anecdotes
- 在线SQL转Excel(xls/xlsx)工具
- How to use jedis of redis
- This article takes you to understand the relationship between the past and present of Bi and the digital transformation of enterprises
- NEW:Devart dotConnect ADO.NET
- The order of LDS links
- [array]566 Reshape the matrix - simple
- UI自動化測試從此告別手動下載瀏覽器驅動
猜你喜欢
![[web Audit - source code disclosure] obtain source code methods and use tools](/img/ea/84e67a1fca0e12cc4452c744c242b4.png)
[web Audit - source code disclosure] obtain source code methods and use tools

Threejs factory model 3DMAX model obj+mtl format, source file download

UE4 DMX和grandMA2 onPC 3.1.2.5的操作流程

Uni app common functions /api
![[understand series after reading] 6000 words teach you to realize interface automation from 0 to 1](/img/eb/c944d4a71ce30589e71059ed848899.png)
[understand series after reading] 6000 words teach you to realize interface automation from 0 to 1

线上故障突突突?如何紧急诊断、排查与恢复

DMX parameter exploration of grandma2 onpc 3.1.2.5

laravel8 导出Excle文件

Threejs realizes sky box, panoramic scene, ground grass

【web審計-源碼泄露】獲取源碼方法,利用工具
随机推荐
Why is there a reincarnation of 60 years instead of 120 years in the tiangan dizhi chronology
官宣!第三届云原生编程挑战赛正式启动!
On the day 25K joined Tencent, I cried
Plasticscm enterprise crack
[数组]566. 重塑矩阵-简单
C语言课设:影院售票管理系统
陇原战“疫“2021网络安全大赛 Web EasyJaba
【看完就懂系列】一文6000字教你从0到1实现接口自动化
How about programmers' eyesight| Daily anecdotes
长度为n的入栈顺序的可能出栈顺序
grandMA2 onPC 3.1.2.5的DMX参数摸索
Analysis of glibc strlen implementation mode
C # use awaiter
Why do big companies such as Baidu and Alibaba prefer to spend 25K to recruit fresh students rather than raise wages by 5K to retain old employees?
[understand series after reading] 6000 words teach you to realize interface automation from 0 to 1
lds链接的 顺序问题
[punch in questions] integrated daily 5-question sharing (phase III)
UI automation test farewell to manual download of browser driver
Alibaba cloud ECS uses cloudfs4oss to mount OSS
Online sql to excel (xls/xlsx) tool