Hi everyone,
I have some problem with drag object, i just want to move this with the mouse
I have tried to drag with the mouse a gltf file that works well
var loader = new THREE.GLTFLoader();
loader.load(
`models/toaster/scene.gltf`,
( gltf ) => {
this.scene.add(gltf.scene);
gltf.scene.scale.set(5, 5, 5);
//gltf.scene.position.set(400,400,400)
gltf.scene.traverse( function( object ) {
if ( object.isMesh) objects.push( object );
} );
},
null,
null
)
I have tried with geometry, well too
var geometry = new THREE.BoxGeometry( 40, 40, 40 );
var geometry = new THREE.SphereGeometry( 40, 40, 40 );
var shape = new THREE.Mesh( geometry, new THREE.MeshLambertMaterial( { color: Math.random() * 0xffffff } ) );
shape.position.x = Math.random() * 1000 - 500;
shape.position.y = Math.random() * 600 - 300;
shape.position.z = Math.random() * 800 - 400;
shape.castShadow = true;
shape.receiveShadow = true;
scene.add( shape );
But when I try with obj file i got some problem, I have tried like gltf file
var bis;
var mtlLoaderBis = new THREE.MTLLoader();
mtlLoaderBis.setResourcePath('models/doppio/');
mtlLoaderBis.setPath('models/doppio/');
mtlLoaderBis.load('doppio.mtl', function (materials) {
materials.preload();
var objLoader = new THREE.OBJLoader();
objLoader.setMaterials(materials);
objLoader.setPath('models/doppio/');
objLoader.load('doppio.obj', function (object) {
scene.add(object);
object.traverse( function (child ) {
if (child.type === 'Mesh' ){
// bis = child;
objects.push(child);
}
});
});
});
but that break my oject up like that
and when i try like this
var bis;
var mtlLoaderBis = new THREE.MTLLoader();
mtlLoaderBis.setResourcePath('models/doppio/');
mtlLoaderBis.setPath('models/doppio/');
mtlLoaderBis.load('doppio.mtl', function (materials) {
materials.preload();
var objLoader = new THREE.OBJLoader();
objLoader.setMaterials(materials);
objLoader.setPath('models/doppio/');
objLoader.load('doppio.obj', function (object) {
scene.add(object);
object.traverse( function (child ) {
if (child.type === 'Mesh' ){
bis = child;
}
});
objects.push(bis);
});
});
I have only one thing is moving
then when i do this like simple object
var mtlLoaderBis = new THREE.MTLLoader();
mtlLoaderBis.setResourcePath('models/doppio/');
mtlLoaderBis.setPath('models/doppio/');
mtlLoaderBis.load('doppio.mtl', function (materials) {
materials.preload();
var objLoader = new THREE.OBJLoader();
objLoader.setMaterials(materials);
objLoader.setPath('models/doppio/');
objLoader.load('doppio.obj', function (object) {
scene.add(object);
objects.push(object);
});
});
nothing happens
I don’t know how can i do to move all the block, if some one can tell me some advice.
Thanks for your time.