i need some help with loading and 3D Model stored as .obj with an .mtl File and an jpg texture. With loadModel() I only get the mesh loaded and displayed, but the texture isn’t loaded.
If I also load the Texture with loadImage() and the set the texture on the model, it displays it but not on the correct positions.
Have you tried a matrix transform on the texture, if it can be loaded, then matrix should be able to transform it in any way you want. Alternatively you can code the transformation yourself.
The texture() function seems to ignore the UV data (texture coordinates) from the OBJ file and just wrap it around the model in an arbitrary way. As you can see the face is rendered to the model’s neck, the tail texture ends up on its torso and so on.
Is there an easy way to access the correct info from the model via the p5 library or would I have to read the info from the OBJ file myself and remap the texture using WebGL directly?
I’m sorry if this is a very noob question. I come from using 3D software and engines like Unreal and Unity, so I’ve never been confronted with this issue before. I might have totally misunderstood your answer as well.
Yes this should work in 3d just add a z component, also remember this needs to be done for all misorientated textures unless they all share the same transformation which is unlikely.
Using transforms doesn’t seem to affect the texture wrap in any way at all for me.
It only affects the model.
I can of course move and rotate and scale the mesh using transforms. I’m sure that’s not what you meant.
Using a different graphics buffer and doing the transforms there before applying the texture (or the buffer in this case) to the model solved my problem!
Took me a bit to figure out how it was misaligned. Turned out I just had to mirror it vertically.
Thank you so much!! This was exactly it!
Edit: I can of course just mirror the image in my graphics software from now on. I didn’t realize the issue was so simple.
Here is the corrected code using createGraphics(). Note the inverted commas in the code below must not be curly so please retype them after copy and paste.
let foxTex;
let foxMesh;
function preload(){
foxTex = loadImage("T_Fox_D.png");
foxMesh = loadModel("Fox.obj ", true);
}
function setup() {
createCanvas(400, 400, WEBGL);
noStroke();
graphics = createGraphics(400, 400);
graphics.imageMode(CORNERS);
graphics.scale(1, -1)
graphics.image(foxTex, 0, 0,400,-400);
}
function draw() {
background(220);
rotateZ(PI);
rotateY(0.01 * frameCount);
texture(graphics);
model(foxMesh);
}
P.S. it is of course easier to just vertically flip the texture image as @yzzy has already mentioned above