Open jyy1082 opened 6 years ago
Hey, @jyy1082 , sorry for delayed answer. TL;DR: It's possible, and here's how:
const object = new WHS.Importer({
loader: new THREE.OBJLoader(), // you need to provide obj loader there
// ...
});
You may write your own module, which can be reusable then, but the simplest way is to use three-mtl-loader and then:
mtlLoader.load('model.mtl', function(matl) {
const object = new WHS.Importer({
material: matl
// ...
});
// ...
});
And the final stage, add this to app:
object.addTo(app);
Hi, Thanks for your replay! My obj and mtl files are for one model. Can I import them together as a object using one WHS.Importer?
multiple obj files, right?
On Wed, Dec 27, 2017 at 8:20 PM jyy1082 notifications@github.com wrote:
Hi, Thanks for your replay! My obj and mtl files are for one model. Can I import them together as a object using one WHS.Importer?
— You are receiving this because you commented.
Reply to this email directly, view it on GitHub https://github.com/WhitestormJS/whs.js/issues/363#issuecomment-354154207, or mute the thread https://github.com/notifications/unsubscribe-auth/AHTX1XTFSSHPdFDxae5vR1d0Husnf1BGks5tEoppgaJpZM4RL3GU .
I mean one obj and one mtl files together for one model.
https://www.learnthreejs.com/load-3d-model-using-three-js-obj-loader/
This is the way to use THREEJS to implement. How should I use WHS to do that? Thanks.
@jyy1082 See the code above, it's pretty similar with what you need
I will try it. Thanks again!
does it work @jyy1082 ?
I'm also struggling a bit with this. This snippet works when using with vanilla ThreeJS loader:
var loader = newTHREE.OBJLoader();
loader.load( 'o.obj', ( object ) => {
this.scene.add( object );
});
However, when doing the 'same' thing with WHS Importer:
new WHS.Importer({
url: 'o.obj',
loader: new OBJLoader(),
parser(geometry, material) { // material comes as undefined since i'm not loading any .mtl file
return new THREE.Mesh(geometry, new THREE.MeshNormalMaterial({
color: 0xff0000,
}));
},
position: [0, 100, 0]
}).addTo(this.app);
I got an error in a three.module.js codebase TypeError: Cannot read property 'center' of undefined at Sphere.copy (three.module.js?8bc5:8345)
Currently I'm using the vanilla approach but would like how to integrate better with WhiteStorm. Cheers
@antoniocapelo, since you’ve moved to OBJLoader, your parser() accept other arguments.
In three.js you have: loader.load(‘o.js’, parser);
and in your code instead of parser
you have an arrow function with object as input data. Same in whs.
parser arguments: JSONLoader: (geometry, material) OBJLoader: (object)
Should look like this:
parser(object) {
return parser;
}
parser(object) {
return object;
}
Correct one. (made a typo in my prev msg)
Sorry for the delay @sasha240100 ! I tried what you described and it does work (not when loading the .mtl
file at the same time though — But the 'vanilla' way I described is looking good until now, so that's covered).
Thanks!
@sasha240100 I am once again volunteering myself to create a more permanent module for loading these models in (unless someone's already done it?).
I could share MTLModule source with you and maybe we could easily combine it with obj
On Fri, Mar 2, 2018 at 4:41 PM Noah notifications@github.com wrote:
@sasha240100 https://github.com/sasha240100 I am once again volunteering myself to create a more permanent module for loading these models in (unless someone's already done it?).
— You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub https://github.com/WhitestormJS/whs.js/issues/363#issuecomment-369938692, or mute the thread https://github.com/notifications/unsubscribe-auth/AHTX1X4mT_vSZplmzAPawJyC-TiQtmXDks5taVolgaJpZM4RL3GU .
Yeah, that sounds great! Where's the source?
@TheCodeCrafter Sorry for late response. I wasn't able to find the source code (probably lost it because of not using git for that project). I could help you in development, just point me
Ok, I will try to remember to do this in the near future. My programming world is a hellish nightmare of projects (abandoned and current) everywhere right now. Will return when ready, sir! ;)
This issue should be closed as it looks solved
Agreed @zardilior but it would be nice to add an example to illustrate how to do it, anyone volunteers to add a simple example?
I'm unable to at the moment, as I'm super busy with school. I'll get back to you during late December!
Does whs.js support to import obj and mtl files with image resource? If yes, is there anyone can guide me how to use WHS.Importer to add those into WHS.App?
Thank you!
Version:
Issue type:
Desktop