I have encountered an issue while trying to incorporate a texture into a shader material used in a Blender object loaded through the object loader THREE.OBJLoader
.
The following simple code functions correctly, loading a texture and applying it to the loaded object.
var manager = new THREE.LoadingManager();
var texture = new THREE.Texture();
var imageLoader = new THREE.ImageLoader(manager);
var objLoader = new THREE.OBJLoader(manager);
imageLoader.load("texture.png", function (image) {
texture.image = image;
texture.needsUpdate = true;
});
var material = new THREE.MeshBasicMaterial({ map: texture});
objLoader.load("blenderObject.obj", function (object) {
object.traverse(function (child) {
if (child instanceof THREE.Mesh) {
child.material = material;
}
});
scene.add(object);
However, I wish to utilize my ShaderMaterial
instead of a MeshBasicMaterial
. This shader material functions properly with other objects in my projects. Below is how I initialize my shader material:
var uniforms = {
texture: { type: "t", value: THREE.ImageUtils.loadTexture("texture.png") },
}
var shader = THREE.ShaderLib["shader"];
var material = new THREE.ShaderMaterial({
uniforms: uniforms,
vertexShader: shader.vertexShader,
fragmentShader: shader.fragmentShader,
depthTest: true,
});
When I use this material instead of MeshBasicMaterial
, there are no errors but the object appears entirely black. I am curious about the correct method to apply textures in shader materials with objects created by THREE.OBJLoader
. Applying this shader to other objects yields the expected results. Thank you in advance for any insights.