Saving and loading a mesh into a file - javascript

I have several screens on stage, and are slow to load. so I have the idea to put it in a file and then load the meshes and add them to the scene. how can I do this? I have seen examples with
"THREE.JSONLoader()"
but can not find something like that where you see how the mesh is saved in a file and then load the full mesh from file.
My meshes are very big about 9000 vertices per file.

Related

THREE.js FBXLoader treats .png as if it is a .psd, and doesn't load the material

When using the THREE.js FBXLoader to load a .fbx file, it is loading the model partially, with the alpha textured parts of the model not being loaded.
I am getting the error:
FBXLoader: PSD textures are not supported, creating empty placeholder texture for pinebranchColor.psd
Despite there being no .psd files in the materials folder. As you can see from the below screenshot, it seems to think that in the material alphaMap, the texture name is pinebranchColor.psd.
This is what the FBX model is being rendered as:
And this is what it renders as if I load the GLTF version (note: the transparent parts for the leaves are not picked up as transparent) - which is closer to how it should look, but not fully.
This is how the model is supposed to look, according to sketchfab :
Why do you think it says the alpha material is a .psd? Could this be as referenced in the .fbx file itself? The original problem was how do I get the alpha/transparency for the leaves to render correctly, rather than as block colour. Maybe I could set a property in the THREE.js material of the GLTF version and that would work?
This is the first model I have ever imported into THREE.js as I have just started learning, so please explain as best you can.
EDIT:
In dev tools I found a material for the leaves, and set transparent to true. This worked! To an extent. But there are still some rendering issues. So I think this is the route to go down.
I'm not sure why the FBX alpha material could not be loaded, but I solved the transparency problem with the GLTF version by using the THREE.js scene.traverse function, and setting the material transparent property to true, for all leaf materials in the scene.
This solved the core issue, but there were still some artifacts as seen in this picture, where leaves behind are blacked out:
The solution was to also set alphaTest to 0.5 on the material, giving this result:
Here is the code:
gltf.scene.traverse(child => {
if (child.isMesh && child.name.includes('leaf')) {
child.material.alphaTest = 0.5;
child.material.transparent = true;
}
});

Exporting Textures with Offsets to GLTF from Three.js Scene

EDIT:
I had a question about exporting to obj and mtl but discovered that I could export from three.js using GLTFExporter.js and had success getting the geometry and texture out of three.js from that.
The issue I'm having with the GLTF Exporter is that I have textures that have offset and repeat settings that seem to not be exported from three.js when I open the file in Blender. In Blender the whole texture takes up the MeshPlane that used to only have a small part of the texture showing in Three.js scene.
Might anyone know what I could add to the GLTF Exporter to be able to record and keep the repeat and offset texture settings?
Many Thanks :)
I've hit this myself.. and as far as I know, the answer is No.
Offset and Repeat are THREE.js specific features. Some other libraries have equivalents.. some engines use direct texture matrix manipulation to achieve the same effect.
One workaround is to modify your models UV coordinates before exporting to reflect the settings of texture.offset and texture.repeat.
You would basically multiply each vertex UV by the texture.repeat, and then add texture.offset. That would effectively "bake" those parameters into the model UV's, but then would require you to reset .repeat and .offset back to 1,1 and 0,0 respectively, in order to render the model correctly again in THREE.js.
Here's a slightly relevant thread from the GLTF working group:
https://github.com/KhronosGroup/glTF/issues/107

Render an animated fbx model with texture in three.js

I am working to display "animated 3D Models" on webpage. These models are in form of .obj, .mtl & .fbx files with texture and without texture. I successfully displayed .obj 3D Models on webpage (with texture , with mtl file), but i am unable to display .fbx 3D animated models with texture.
I already searched for this topic on Google, SO and also on Github (https://github.com/mrdoob/three.js/issues) but not found any solution.
I want to ask 2 questions here:
Is it possible to display fbx 3D Models with texture via three.js?
If it is possible then how i can do this OR if it is not then what other alternative can i use to render fbx model having texture to webpage?
After spending lots of time i have understood that you can not use .fbx model file directly with three.js (till r82). Alternatively you can convert .fbx file to .json (using three.js maya exporter )or .js (using blender).
So i am moving with .json file format. Thanks for your suggestion #mlkn

When is a Three.js Texture sent to the GPU?

I am building an application that dynamically loads images from a server to use as textures in the scene and I am working on how to load/unload these textures properly.
My simple question is; Where, in the Three.js call graph, does textures get loaded and/or updated into the GPU? Is it when I create a texture (var tex = new THREE.Texture()) or when I apply it to a mesh (var mesh = new THREE.Mesh(geom, mat))? The Texture class of Three suggests that textures are not loaded when creating the texture. But I cannot find anything in Mesh either.
Am I missing something? Are textures loaded in the render loop rather than on object creation? That would probably make sense.
Thanks in advance!
All GPU instructions have been abstracted away to the WebGLRenderer.
This means the creation of any object within three.js will not interact with the GPU in the slightest until you call:
renderer.render(scene, camera);
This call will automatically setup all the relevant WebGL buffers, shaders, attributes, uniforms, textures, etc. So until that point in time, all three.js meshes with their materials and geometries are really just nicely abstracted objects, completely separated from the way they are rendered to the screen (why assume they will be rendered at all?).
The main reason for this is that there are other renderers, such as the CanvasRenderer, which have an entirely different API.

THREE.js: Loading model with JSONLoader loads only half of textures

After making a house model in blender I've exported it to three.js json format as a single object, but when adding it to scene I got half textures displayed and another half are just grey meshes.
JSON URL (with absolute texture images links): http://pobegushki.meetroll.net/inn1.js
Screenshot of what I get in blender and what I get in production:
Also there are two instances of a barrel model which both has a perfectly mapped material. I tried setting barrel image as a material to floor (simple scaled box mesh), but nothing changed, it still remained grey.
Any ideas?
I think there's a bug in the file loaders/Loader.js (Rev56). At line 332, try to replace:
if ( m.mapDiffuse && texturePath ) {
by
if ( m.mapDiffuse && texturePath != null ) {
(same bug for all types of textures of course)
I stumbled upon this bug this week-end, where my textures were not displayed because texturePath = "".
TATATATAAAM! I've solved the problem (the stupid way tbh, but I got fully textured model).
Behold: http://touhou.ru/upload/56e75518ab580497358741bec62491ff.png
Blender three.js export was creating empty textures for all untextured meshes I got, and I tried copy-pasting non-empty materials to empties. After thousands of page refreshes I got right materials assigned to right meshes.
It took pretty much time, I think I should submit a bugreport :(
UPDATE: Here's why those materials were empty on export:
On the first picture I've selected a mesh which had texture in production and on the second is one which didn't.
Thanks for your attention!

Categories