dwqdaiwenqi / react-3d-viewer

A 3D model viewer component based on react.js 一个基于react.js的组件化3d模型查看工具
165 stars 64 forks source link

3d object is gray and not affected with tex file #10

Closed engmagdy87 closed 5 years ago

engmagdy87 commented 5 years ago

the 3d object is gray and not affected with tex file here is the code https://codesandbox.io/embed/determined-lumiere-1omml

aysenurbulbul commented 4 years ago

Hey, did you solve this problem? I get black 3D model without any texture.

lossen commented 4 years ago

Same to me. @dwqdaiwenqi Is this project maintainable?

aysenurbulbul commented 4 years ago

Hey @lossen , I solved this issue by moving 3D model's files from src folder to public folder. Then I modified the code like this:

<MTLModel 
        enableZoom = {false}
        position={{x:0,y:-100,z:0}}
        rotation={this.state.rotation}
        texPath="/3Dmodels/project2/"
        mtl="/3Dmodels/project2/freedom.mtl"
        src="/3Dmodels/project2/freedom.obj"
/>

The mtl and obj files are under public/3Dmodels/project2 folder. You don't have to write public in the code while giving the path. Also, React allows serving static files without using import through public folder. After that, texture loaded correctly for me. I hope this helps.

lossen commented 4 years ago

Hey @aysenurbulbul , thanks for help! Yeah, from public folder textures loaded correctly. Did you try with urls instead of local paths? I need to load model from the server

aysenurbulbul commented 4 years ago

@lossen , in my project I used only local files so I only tried it with dynamically changed local paths but since this package uses three.js and its OBJLoader supports loading from URLs as well, it may work. If your project requires more flexibility with 3D models, I suggest you to use three.js instead of this package. In fact, I used three.js then switched to babylon.js to serve 3D models in my project. Hope this helps.