シーン上の古いオブジェクトを削除し、シーンを新しいオブジェクトを追加できるようにします
メッシュに追加された 3D カスタム オブジェクトを持つアプリケーションを開発しました。メッシュがシーンに追加されます。ページにもボタンがあります。クリックすると、既に作成されているオブジェクトがシーンの子であるメッシュから削除され、シーンは最初のように新しいオブジェクトを追加する準備ができているはずです。つまり、可能であればメッシュ全体を削除して、新しいオブジェクト セットを含む新しいメッシュをシーンに追加する必要があります。
function xyz() // Button click function
{
// should remove the objects in the scene if exists and make scene available to add
// new objects
for ex: scene.remove(mesh)....???
// Also needed to clear the renderer??
.
.
.
do something
}
function init()
{
// adds the objects to the scene and instantiate renderer
mesh = New THREE.Mesh({// some material});
cube = new THREE.CubeGeometry(1,1,1);
object = new THREE.Mesh(cube,material);
mesh.add(object);
scene.add(mesh);
}
function animate()
{
requestAnimationFrame(animate);
render();
}
function render()
{
renderer.render(scene, camera);
}