Three js Blender exporter, how to specify type of texture - three.js

So my question is, when creating textures inside blender how can i configure those textures so that when I export mesh with Three.js exporter they get assigned as specific textures (map, aoMap).
So far I have one mesh with two textures and one textures is map(diffuse) and other texture is lightMap. ( That's what I figured out from generated .json file)
I want to set one texture to remain to be map, and another one to be aoMap insted of lightMap.

So I figured it out by looking at python scripts for Three.js exporter.
If you want texture to be map (diffuse) you need to set "Blend" property on texture inside Blender to be "Color". If you want texture to be map (light) you need to set texture "Blend" property inside blender to "Multiply".
It appears that exporter does not support map (ambient occlusion). I guess I will have to hack it up so it does.

Related

Move a camera inside a GLTF exported with blender using ThreeJS

I'm working with game dev. He has implemented all the boardgame using Blender. He also added some sprites inside directly and linked the sprite to the Camera inside Blender so that when this camera moves, all the sprites will move accordingly to always face the Camera.
Now my question is, how can I implement this using react-three-js. I see that I can export the Camera object from blender (after exporting the GLTF with the Camera inside) and see it in my GLTF in threejs (under gltf.cameras[0])
My question is, How can I change the camera position of the GLTF (not a copy in threejs) so that I can keep the rules he added for the sprite to always face the camera?
Any constraints created in Blender will not be included when exporting files to other formats. Those would need to be recreated in three.js. In this case I'd recommend using gltfjsx to create a JSX representation of your model, and then using the <Billboard /> component to keep objects facing the camera.
If you have many (100+) sprites, it may be necessary to export them as points, and then assign a THREE.PointsMaterial that applies whatever appearance you need with a texture. Those points will face the camera automatically, as shown in this example.

I can't get the aoMap showing in three.js using a glb/gltf asset

I’m having a hard time getting an aoMap working in three.js…
I have a glb asset with an aoMap on the red channel or something. When I bring it into to the babylon viewer, I can see the ao just fine, but it wont show up in the three.js viewer or my project. I think this has something to do with a second set of uvs, but I can't find a resource that involves doing that on top of using the gltf loader… I really don't know what to do here. Any response would be greatly appreciated!
Here is my code (I’m using a html-canvas as the texture)
And I get the model’s geometry and diffuse texture (all white) as desired, but the aomap isnt showing…
code
babylon viewer
three.js viewer
working application with shadows included in diffuse
not working, diffuse is just white, and aoMap is not showing
You're right about needing a second set of UVs. The reason behind this is that diffuse textures often repeat (think of a brick wall, or checkered t-shirt). AO shading, however, is more likely to be unique on each part of the geometry, so it's almost never repetitive. Since this often would need an alternative UV mapping method, the default is to use a second set of UVs.
You could do 2 things:
Re-export your GLTF asset with a duplicate set of UVs.
Duplicate existing UVs in Three.js by creating a new BufferAttribute in your geometry:
// Get existing `uv` data array
const uv1Array = mesh.geometry.getAttribute("uv").array;
// Use this array to create new attribute named `uv2`
mesh.geometry.setAttribute( 'uv2', new THREE.BufferAttribute( uv1Array, 2 ) );
.getAttribute and .setAttribute are methods of BufferGeometry, if you want to read more about them.

blender2.8 gltf export for three.js with bumpmap or normalmap or roughnessmap?

I saw some discussions saying gltf does not export bumpmap but if I look into my exported gltf file (separate files mode) there is a bumpmap file with a bumpscale (and also normal map). After loading into three.js I get a meshstandard material with bumpmap object and scale value and also normalmap object. But they seem to have no effect on the rendered object. What is exactly allowed to do to export relief effect from Blender to Three.js with gltf ?
The only relief effect available in glTF is a tangent-space normal map, as shown here:
Blender does have the ability to convert height maps and other kinds of bump maps to tangent-space normal maps, by way of the "Bake" function in Cycles. There are also online utilities that can do this as well.

Importing a downloaded .obj file to blender, how do I add textures that are provided in .png format?

So, as a starter on Blender, I've downloaded a 3d file from the internet. I've been able to import the object (.obj file) to the scene, but noticed one thing: There are 12 pictures in a folder called "Textures" that come with the downloaded object. How do I import these textures to the scene and apply them to the object? It is a good note that the object itself is not a whole, it is a combination of other objects.
Blender objects use materials to add color and shading to each mesh face. We assign textures to each material. The UV map image textures are assigned to a material in a process called skinning. You might just need to select the object and then look in the Material and Texture properties. Each Texture will have a folder icon to set the location of the texture image file.
YouTube offers many how-to videos about how to UV wrap an object. Just don't make your task too difficult. You probably only need to set the correct image texture png for each UV texture.
Hang in there and good luck.

Messed up UVs and Lightmap

I want to bake my model lightmap in blender then load them all in three.js.
So in blender i set two uvs for each objects and baked ambient occlusion in second uv. finally i exported whole scene via three.js exporter into js file.
(exporter has problem that the baked texture goes for diffuse-map not light-map which is correctable by editing exported js file).
But the problem is when i load js with SceneLoader, the textures especially for my floor goes wrong, like upside down.
here is my test files: Test Light Map
So is there something wrong with my blender file or ...? Which loader i should use for it?
Thanks.
I just upload some images to see what i mean:
Messed up textures:
After edit js file, it's get better. but still there is problem at the edges:
And specially at floor, the light-map goes wrong:
Ok, i don't know why, but it seems my uvs was messed up in blender. i did some recaculate normals and flip normals in blender and now textures map fine on objects.
But i still need to edit exported scene to change map:texture.png to lightMap:texture.png.
[EDIT]
Actually this is a bug related to three.js scene exporter: Blender Exporter - Scene Exporting
[Final Answer]
The problem was about my model which had a negative scale in blender. i select my model, hit crtl+a then choose scale. now everything's fine.

Resources