如果我按以下方式创建对象:
var group = new THREE.Object3D();
for (var i = 0; i < 10; i++) {
geometry = new THREE.BoxGeometry(1, 1, 1);
material = new THREE.MeshNormalMaterial();
mesh = new THREE.Mesh(geometry, material);
group.add(mesh);
}
scene.add(group);
那么,如何从该组中删除这些对象?
我试过这样做......
for (var i = group.children.length - 1; i >= 0; i--) {
scene.remove(group.children[i]);
}
...但输出为'undefined'。我在这里做错了什么?
答案 0 :(得分:12)
for (var i = group.children.length - 1; i >= 0; i--) {
group.remove(group.children[i]);
}
答案 1 :(得分:2)
如果要删除所有子网格物体的最佳解决方案
namespace App\Http\Controllers;
use App\User;
use App\Repositories\UserRepository;
use App\Http\Controllers\Controller;
class UserController extends Controller
{
/**
* The user repository implementation.
*
* @var UserRepository
*/
protected $users;
/**
* Create a new controller instance.
*
* @param UserRepository $users
* @return void
*/
public function __construct(UserRepository $users)
{
$this->users = $users;
}
/**
* Show the profile for the given user.
*
* @param int $id
* @return Response
*/
public function show($id)
{
$user = $this->users->find($id);
return view('user.profile', ['user' => $user]);
}
}
答案 2 :(得分:1)
您可以使用
object.children = [];