mirror of
https://github.com/jiawanlong/Cesium-Examples.git
synced 2025-07-04 15:17:36 +00:00
103 lines
3.1 KiB
HTML
103 lines
3.1 KiB
HTML
<!--********************************************************************
|
|
* by 优雅永不过时 https://github.com/z2586300277
|
|
*********************************************************************-->
|
|
<!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": "./../../libs/three/build/three.module.js",
|
|
"three/addons/": "./../../libs/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'
|
|
import { FBXLoader } from 'three/addons/loaders/FBXLoader.js'
|
|
import { OBJLoader } from 'three/addons/loaders/OBJLoader.js'
|
|
import { MTLLoader } from 'three/addons/loaders/MTLLoader.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.setDRACOLoader(new DRACOLoader().setDecoderPath(`https://file.threehub.cn/` + 'js/three/draco/'))
|
|
loader.load('./航空母舰.gltf', (gltf) => {
|
|
scene.add(gltf.scene)
|
|
}, function (xhr) {
|
|
const percent = xhr.loaded / xhr.total;
|
|
// 加载进度
|
|
console.log(percent)
|
|
})
|
|
|
|
// 加载模型 fbx
|
|
new FBXLoader().load('./tom/tom.FBX', (object3d) => {
|
|
scene.add(object3d)
|
|
object3d.scale.set(0.005, 0.005, 0.005)
|
|
})
|
|
|
|
// 加载模型 obj/ mtl
|
|
const objLoader = new OBJLoader()
|
|
const mtlLoader = new MTLLoader()
|
|
mtlLoader.load('./woman1/091_W_Aya_10K.mtl', (mtl) => {
|
|
mtl.preload()
|
|
objLoader.setMaterials(mtl)
|
|
objLoader.load('./woman1/091_W_Aya_10K.obj', (obj) => {
|
|
scene.add(obj)
|
|
obj.scale.set(0.002, 0.002, 0.002)
|
|
obj.position.x += 2
|
|
})
|
|
})
|
|
|
|
|
|
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> |