【发布时间】:2018-08-07 13:02:27
【问题描述】:
我使用map 函数创建了多个场景。在那个map函数中,我创建了一定数量的div(数量根据场景而定)。如何将每个场景附加到每个 div。
当我尝试渲染时,第一个模型(或所有其他模型,除了最后一个)会闪烁显示然后消失,然后是最后一个模型显示。据我了解,它与渲染功能有关。
但我现在不知道该怎么办。任何帮助,将不胜感激。
let cameraInstance = new THREE.PerspectiveCamera(
75,
window.innerWidth / window.innerHeight,
0.1,
1000
)
const rendererInstance = new THREE.WebGLRenderer({ alpha: true })
rendererInstance.setSize(300, 200)
const oControl = new OrbitControls(
cameraInstance,
rendererInstance.domElement
)
const loaderInstance = new THREE.JSONLoader()
let createSceneInstance = tempInstances.map((tempInstance, i) => {
let sceneInstance = new THREE.Scene()
const ambientLight = new THREE.AmbientLight(0x383838)
sceneInstance.add(ambientLight)
const spotLight = new THREE.SpotLight(0xffffff)
spotLight.position.set(300, 300, 300)
spotLight.intensity = 1
sceneInstance.add(spotLight)
let newDiv = document.createElement('div')
newDiv.id = 'instance' + i
document.getElementById('instances').appendChild(newDiv)
loaderInstance.load(
path + tempInstance.json3d,
// eslint-disable-next-line
(geo, mat) => {
let ins1 = new THREE.Mesh(geo, mat)
ins1.scale.set(20, 20, 20)
sceneInstance.add(ins1)
cameraInstance.position.set(30, 35, 40)
cameraInstance.lookAt(sceneInstance.position)
const render = () => {
requestAnimationFrame(render)
oControl.update()
rendererInstance.render(sceneInstance, cameraInstance)
}
render()
}
)
return sceneInstance
})
document
.getElementById('instance0')
.appendChild(rendererInstance.domElement)
【问题讨论】:
-
欢迎来到 Stack Overflow。请花几分钟浏览帮助中心,特别是
How do I ask a good question?。请务必在您的问题中包含所有支持代码和错误。另外,考虑使用snippets 创建一个Minimal, Complete, and Verifiable example。另外,请查看three.js examples,过滤“多个”。
标签: javascript three.js 3d render