mirror of
				https://github.com/jiawanlong/Cesium-Examples.git
				synced 2025-11-04 09:14:17 +00:00 
			
		
		
		
	
		
			
	
	
		
			87 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
		
		
			
		
	
	
			87 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
| 
								 | 
							
								<!--********************************************************************
							 | 
						|||
| 
								 | 
							
								* by jiawanlong
							 | 
						|||
| 
								 | 
							
								*********************************************************************-->
							 | 
						|||
| 
								 | 
							
								<!DOCTYPE html>
							 | 
						|||
| 
								 | 
							
								<html>
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								<head>
							 | 
						|||
| 
								 | 
							
								    <meta charset="UTF-8" />
							 | 
						|||
| 
								 | 
							
								    <style>
							 | 
						|||
| 
								 | 
							
								        * {
							 | 
						|||
| 
								 | 
							
								            margin: 0;
							 | 
						|||
| 
								 | 
							
								            padding: 0;
							 | 
						|||
| 
								 | 
							
								            overflow: hidden;
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        body,
							 | 
						|||
| 
								 | 
							
								        #box {
							 | 
						|||
| 
								 | 
							
								            width: 100%;
							 | 
						|||
| 
								 | 
							
								            height: 100%;
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								    </style>
							 | 
						|||
| 
								 | 
							
								</head>
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								<body>
							 | 
						|||
| 
								 | 
							
								    <div id="box"></div>
							 | 
						|||
| 
								 | 
							
								    <script type="importmap">
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            "imports": {
							 | 
						|||
| 
								 | 
							
								                "three": "./../../three/build/three.module.js",
							 | 
						|||
| 
								 | 
							
								                "three/addons/": "./../../three/examples/jsm/"
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								    </script>
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								    <script type="module">
							 | 
						|||
| 
								 | 
							
								        import * as THREE from 'three'
							 | 
						|||
| 
								 | 
							
								        import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
							 | 
						|||
| 
								 | 
							
								        import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js'
							 | 
						|||
| 
								 | 
							
								        import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js'
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        const box = document.getElementById('box')
							 | 
						|||
| 
								 | 
							
								        const scene = new THREE.Scene()
							 | 
						|||
| 
								 | 
							
								        // 相机
							 | 
						|||
| 
								 | 
							
								        const camera = new THREE.PerspectiveCamera(75, box.clientWidth / box.clientHeight, 0.1, 1000)
							 | 
						|||
| 
								 | 
							
								        camera.position.set(5, 5, 5)
							 | 
						|||
| 
								 | 
							
								        // 渲染器
							 | 
						|||
| 
								 | 
							
								        const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true, logarithmicDepthBuffer: true })
							 | 
						|||
| 
								 | 
							
								        // 环境光
							 | 
						|||
| 
								 | 
							
								        scene.add(new THREE.AmbientLight(0xffffff, 4))
							 | 
						|||
| 
								 | 
							
								        // 参考线
							 | 
						|||
| 
								 | 
							
								        scene.add(new THREE.AxesHelper(1000))
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        // 加载模型 gltf/ glb 
							 | 
						|||
| 
								 | 
							
								        const loader = new GLTFLoader()
							 | 
						|||
| 
								 | 
							
								        loader.load('./zhanji.glb', (gltf) => {
							 | 
						|||
| 
								 | 
							
								            scene.add(gltf.scene)
							 | 
						|||
| 
								 | 
							
								            gltf.scene.scale.set(0.005, 0.005, 0.005)
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        })
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        console.log('.up默认值', camera.up);
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        //  y坐标轴朝下
							 | 
						|||
| 
								 | 
							
								        camera.up.set(0, -1, 0)
							 | 
						|||
| 
								 | 
							
								        //渲染效果:红色x轴向上
							 | 
						|||
| 
								 | 
							
								        // camera.up.set(1, 0, 0);
							 | 
						|||
| 
								 | 
							
								        // //渲染效果:蓝色z轴向上
							 | 
						|||
| 
								 | 
							
								        // camera.up.set(0, 0, 1);
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        renderer.setSize(box.clientWidth, box.clientHeight)
							 | 
						|||
| 
								 | 
							
								        box.appendChild(renderer.domElement)
							 | 
						|||
| 
								 | 
							
								        new OrbitControls(camera, renderer.domElement)
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        animate()
							 | 
						|||
| 
								 | 
							
								        function animate() {
							 | 
						|||
| 
								 | 
							
								            requestAnimationFrame(animate)
							 | 
						|||
| 
								 | 
							
								            renderer.render(scene, camera)
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								    </script>
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								</body>
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								</html>
							 |