当前位置:网站首页>Three. JS introductory learning notes 08:orbitcontrols JS plug-in - mouse control model rotation, zoom in, zoom out, translation, etc
Three. JS introductory learning notes 08:orbitcontrols JS plug-in - mouse control model rotation, zoom in, zoom out, translation, etc
2022-07-07 15:48:00 【Jiang Duoduo_ Mostly Harmless 】
Learning reference
https://blog.csdn.net/qq_30100043/article/details/79606355
One . introduce
1. introduce OrbitControls.js file , stay three.js Found in the official download package
<script type="text/javascript" src="js/OrbitControls.js"></script>
Two . add to
// User interaction plug-ins Press and hold the left mouse button to rotate , Right click and hold the pan , Scroll wheel zoom
var controls = new THREE.OrbitControls( camera, renderer.domElement );
// If you use animate When the method is used , Delete this function
//controls.addEventListener( 'change', render );
// Make the animation rotate or damp when cycling Does the meaning have inertia
controls.enableDamping = true;
// Dynamic damping coefficient It's the mouse drag rotation sensitivity
//controls.dampingFactor = 0.25;
// Can I zoom
controls.enableZoom = true;
// Whether to rotate automatically
controls.autoRotate = true;
// Set the maximum distance from the camera to the origin
controls.minDistance = 1;
// Set the maximum distance from the camera to the origin
controls.maxDistance = 200;
// Whether to turn on right-click drag and drop
controls.enablePan = true;
3、 ... and . effect
Four . Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>3d_camera0313</title>
<script type="text/javascript" src="js/three.js"></script>
<script type="text/javascript" src="js/OrbitControls.js"></script>
<script type="text/javascript" src="js/stats.min.js"></script>
<script type="text/javascript" src="js/dat.gui.min.js"></script>
<script type="text/javascript" src="js/AxesHelper.js"></script>
<style>
* {
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<script type="text/javascript">
//renderer
var renderer = new THREE.WebGLRenderer({
antialias:true});
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0xd2d2d2,1.0);
document.getElementsByTagName("body")[0].appendChild(renderer.domElement);
//scene
var scene = new THREE.Scene();
//camera
var camera = new THREE.PerspectiveCamera(45, window.innerWidth/window.innerHeight, 0.1, 1000);
camera.position.set(0, 4, 5);
camera.lookAt(new THREE.Vector3(0,0,0));
//light
var light = new THREE.PointLight(0xffffff);
scene.add(new THREE.AmbientLight(0x444444));// The ambient light
light.position.set(0,10,10);
scene.add(light);
//tool
var helper = new THREE.AxesHelper(50);// Shaft assist , The parameter is axis size
scene.add(helper);
//model
var loader = new THREE.ObjectLoader();
loader.load("json/test0313.json",function (obj) {
scene.add(obj);
});
//stats
var stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.right = '0px';
stats.domElement.style.top = '0px';
document.body.appendChild(stats.domElement);
//document.getElementsByTagName("body")[0].appendChild(stats.domElement);// Both writing methods can be
//OrbitControls Press and hold the left mouse button to rotate , Right click and hold the pan , Scroll wheel zoom
var controls = new THREE.OrbitControls( camera, renderer.domElement );
// If you use animate When the method is used , Delete this function
//controls.addEventListener( 'change', render );
// Make the animation rotate or damp when cycling Does the meaning have inertia
controls.enableDamping = true;
// Dynamic damping coefficient It's the mouse drag rotation sensitivity
//controls.dampingFactor = 0.25;
// Can I zoom
controls.enableZoom = true;
// Whether to rotate automatically
controls.autoRotate = true;
// Set the maximum distance from the camera to the origin
controls.minDistance = 1;
// Set the maximum distance from the camera to the origin
controls.maxDistance = 200;
// Whether to turn on right-click drag and drop
controls.enablePan = true;
//render
id = setInterval(draw, 20);
function draw() {
stats.begin();
renderer.render(scene, camera);
stats.end();
}
</script>
</body>
</html>
边栏推荐
- When opening the system window under UE4 shipping, the problem of crash is attached with the plug-in download address
- Yunxiaoduo software internal test distribution test platform description document
- Gd32 F3 pin mapping problem SW interface cannot be burned
- Use of SVN
- Whether runnable can be interrupted
- Nacos conformance protocol cp/ap/jraft/distro protocol
- Use cpolar to build a business website (2)
- Mesh merging under ue4/ue5 runtime
- 2022 all open source enterprise card issuing network repair short website and other bugs_ 2022 enterprise level multi merchant card issuing platform source code
- [Lanzhou University] information sharing of postgraduate entrance examination and re examination
猜你喜欢
AB package details in unity (super detail, features, packaging, loading, manager)
Postman generate timestamp, future timestamp
[quick start of Digital IC Verification] 22. Ahb-sramc of SystemVerilog project practice (2) (Introduction to AMBA bus)
webgl_ Enter the three-dimensional world (1)
Window环境下配置Mongodb数据库
Write sequence frame animation with shader
UE4 exports the picture + text combination diagram through ucanvasrendertarget2d
Actually changed from 408 to self proposition! 211 North China Electric Power University (Beijing)
Use of SVN
Vertex shader to slice shader procedure, varying variable
随机推荐
Webcodecs parameter settings -avc1.42e01e meaning
一大波开源小抄来袭
【数字IC验证快速入门】26、SystemVerilog项目实践之AHB-SRAMC(6)(APB协议基本要点)
2.Golang基础知识
【原创】一切不谈考核的管理都是扯淡!
webgl_ Graphic transformation (rotation, translation, zoom)
Points for attention in porting gd32 F4 series programs to gd32 F3 series
numpy--数据清洗
【数字IC验证快速入门】19、SystemVerilog学习之基本语法6(线程内部通信...内含实践练习)
LeetCode3_ Longest substring without duplicate characters
Three. JS introductory learning notes 04: external model import - no material obj model
避坑:Sql中 in 和not in中有null值的情况说明
Annexb and avcc are two methods of data segmentation in decoding
[quickstart to Digital IC Validation] 20. Basic syntax for system verilog Learning 7 (Coverage Driven... Including practical exercises)
Mesh merging under ue4/ue5 runtime
[original] all management without assessment is nonsense!
15. Using the text editing tool VIM
Getting started with webgl (1)
[quick start of Digital IC Verification] 29. Ahb-sramc (9) (ahb-sramc svtb overview) of SystemVerilog project practice
nodejs package. JSON version number ^ and~