当前位置:网站首页>Three. JS introductory learning notes 10:three JS grid
Three. JS introductory learning notes 10:three JS grid
2022-07-07 15:48:00 【Jiang Duoduo_ Mostly Harmless 】
Reference learning :
https://www.ituring.com.cn/book/miniarticle/52525
One . Grid concept
One of the most commonly used objects is the grid (Mesh), The mesh is made up of vertices , edge , An object, such as a face . Other objects include line segments (Line), bones (Bone), particle system (ParticleSystem) etc. . Creating objects requires specifying geometry and materials , among , Geometry determines the vertex position and other information of the object , Material determines the color of objects , Texture and other information .
Two . Create grid
Constructors
Mesh(geometry, material)
Example
var material = new THREE.MeshLambertMaterial({
color:0xffff00
});
var geometry = new THREE.CubeGeometry(5,10,20);
var mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);
If material
and geometry
If it will not be reused later , It can also be written together as :
Note that there should be no semicolon at the end of the color statement
var mesh = new THREE.Mesh(new THREE.CubeGeometry(5, 10, 20),
new THREE.MeshLambertMaterial({
color: 0xffff00
})
);
Complete code
<!DOCTYPE html>
<html lang="en">
<head>
<title>3D</title>
<meta charset="utf-8">
</head>
<body>
<script src="js/three.js"></script>
<script src="js/OrbitControls.js"></script>
<script>
var renderer, scene, camera;
var controls, group;
init();
animate();
function init() {
// init renderer
renderer = new THREE.WebGLRenderer( {
antialias: true } );
// renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
// init scene
scene = new THREE.Scene();
scene.background = new THREE.Color( 0xffffff );
// init camera
camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 1, 1000 );
camera.position.set( 15, 15, 15 );
camera.lookAt(new THREE.Vector3(0, 0, 0));
scene.add(camera);
//light
var light = new THREE.DirectionalLight(0xffffff);
light.position.set(3,10,0);
scene.add(light);
//mesh
/* var material = new THREE.MeshLambertMaterial({ color:0xffff00 }); var geometry = new THREE.CubeGeometry(5,10,20); var mesh = new THREE.Mesh(geometry, material); scene.add(mesh);*/
//mesh Another way of writing
var mesh = new THREE.Mesh(new THREE.CubeGeometry(5, 10, 20),
new THREE.MeshLambertMaterial({
color: 0xffff00
})
);
scene.add(mesh);
}
function animate() {
renderer.render( scene, camera );
requestAnimationFrame( animate );
}
</script>
</body>
</html>
3、 ... and . Modify properties
1. texture of material
After the mesh is created , You can also modify the material
Change to red
var geometry = new THREE.CubeGeometry(1,2,3);
var material = new THREE.MeshLambertMaterial({
color:0xffff00;
});
var mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);
mesh.material = new THREE.MeshLambertMaterial({
color:0xff0000
});
2. Location 、 The zoom 、 rotate
THREE.Mesh
Basis since THREE.Object3D
, Include scale,rotation,position
. They are all THREE.Vector3
example , The method of modifying its value is the same .
THREE.Vector3 Yes x,y,z Three attributes , How to set only one of these properties , You can use the following methods :
mesh.position.z=1
Set multiple properties at the same time , There are two ways to do this
mesh.position.set(1.5, -0.5, 0);
or
mesh.position = new THREE.Vector3(1.5, -0.5 ,0);
Example
mesh.position.set(10,10,10);
mesh.scale.set(0.1,0.1,0.1);
mesh.rotation.x = 60;
边栏推荐
- unnamed prototyped parameters not allowed when body is present
- Using eating in cocos Creator
- 使用Scrapy框架爬取网页并保存到Mysql的实现
- Cocos creator collision and collision callback do not take effect
- [Data Mining] Visual Pattern Mining: Hog Feature + cosinus Similarity / K - means Clustering
- Cocos uses custom material to display problems
- Iterator and for of.. loop
- 【數字IC驗證快速入門】26、SystemVerilog項目實踐之AHB-SRAMC(6)(APB協議基本要點)
- [deep learning] image hyperspectral experiment: srcnn/fsrcnn
- [quick start of Digital IC Verification] 22. Ahb-sramc of SystemVerilog project practice (2) (Introduction to AMBA bus)
猜你喜欢
有钱人买房就是不一样
【微信小程序】Chapter(5):微信小程序基础API接口
Wechat applet 01
JS array foreach source code parsing
[quickstart to Digital IC Validation] 20. Basic syntax for system verilog Learning 7 (Coverage Driven... Including practical exercises)
The rebound problem of using Scrollview in cocos Creator
[make a boat diary] [shapr3d STL format to gcode]
Vite path alias @ configuration
LeetCode3_ Longest substring without duplicate characters
Window环境下配置Mongodb数据库
随机推荐
How to understand that binary complement represents negative numbers
It's different for rich people to buy a house
从 1.5 开始搭建一个微服务框架链路追踪 traceId
AB package details in unity (super detail, features, packaging, loading, manager)
How to deploy the super signature distribution platform system?
Whether runnable can be interrupted
Write sequence frame animation with shader
Using eating in cocos Creator
LeetCode3_ Longest substring without duplicate characters
避坑:Sql中 in 和not in中有null值的情况说明
Monthly observation of internet medical field in May 2022
Cocos makes Scrollview to realize the effect of zooming in the middle and zooming out on both sides
Cut ffmpeg as needed, and use emscripten to compile and run
[target detection] yolov5 Runtong voc2007 data set
Postman generate timestamp, future timestamp
jacoco代码覆盖率
[original] all management without assessment is nonsense!
Window环境下配置Mongodb数据库
UE4 exports the picture + text combination diagram through ucanvasrendertarget2d
有一头母牛,它每年年初生一头小母牛。每头小母牛从第四个年头开始,每年年初也生一头小母牛。请编程实现在第n年的时候,共有多少头母牛?