Replies: 1 comment 3 replies
-
请问引擎版本和运行环境分别是什么,复现步骤是重复调用 |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
import { OrbitControl } from '@galacean/engine-toolkit-controls'
import { Camera, GLTFResource, WebGLEngine, Scene,Vector3 } from '@galacean/engine'
const glbArr = {
'2CylinderEngine':
'https://gw.alipayobjects.com/os/bmw-prod/48a1e8b3-06b4-4269-807d-79274e58283a.glb',
alphaBlendModeTest:
'https://gw.alipayobjects.com/os/bmw-prod/d099b30b-59a3-42e4-99eb-b158afa8e65d.glb',
animatedCube:
'https://gw.alipayobjects.com/os/bmw-prod/d099b30b-59a3-42e4-99eb-b158afa8e65d.glb',
antiqueCamera:
'https://gw.alipayobjects.com/os/bmw-prod/d099b30b-59a3-42e4-99eb-b158afa8e65d.glb',
avocado:
'https://gw.alipayobjects.com/os/bmw-prod/d099b30b-59a3-42e4-99eb-b158afa8e65d.glb',
avocado_draco:
'https://gw.alipayobjects.com/os/bmw-prod/b3b73614-cf06-4f41-940d-c1bc04cf6410.gltf',
avocado_specular:
'https://gw.alipayobjects.com/os/bmw-prod/3cf50452-0015-461e-a172-7ea1f8135e53.gltf',
avocado_quantized:
'https://gw.alipayobjects.com/os/bmw-prod/6aff5409-8e82-4e77-a6ac-55b6adfd0cf5.gltf',
barramundiFish:
'https://gw.alipayobjects.com/os/bmw-prod/79d7935c-404b-4d8d-9ad3-5f8c273f0e4a.glb',
} // 资产列表
let engine = null
let rootEntity = null
let scene = null
nextTick(async () => {
let dom = document.querySelector('#galacean')
engine = await WebGLEngine.create({
canvas: dom, // 渲染节点
graphicDeviceOptions: { alpha: true }, // 开启画布透明
})
engine.canvas.resizeByClientSize()
for (const key in glbArr) {
engine.resourceManager.load(glbArr[key]).then(() => {})
}
scene = engine.sceneManager.activeScene; // 激活场景
})
const changeGlb = (name) => {
rootEntity && scene.removeRootEntity(rootEntity) // 移除根实体
rootEntity = scene.createRootEntity('rootEntity') // 创建新的实体
setCamera()
engine.resourceManager.gc()
engine.resourceManager
.load(glbArr[name])
.then((gltf) => {
loadModel(gltf)
})
engine.run()
}
const loadModel = (gltf)=> {
const {defaultSceneRoot }= gltf
rootEntity.addChild(defaultSceneRoot) // 模型节点加入场景中
}
/** 设置相机*/
const setCamera = () => {
const cameraEntity = rootEntity.createChild("cameraEntity")
cameraEntity.transform.position = new Vector3(0, 1, 50)
cameraEntity.transform.lookAt(new Vector3(0, 0, 0))
const camera = cameraEntity.addComponent(Camera)
camera.nearClipPlane = 0.1
camera.farClipPlane = 10000
cameraEntity.addComponent(OrbitControl)
}
Beta Was this translation helpful? Give feedback.
All reactions