neverhood311 / Stop-motion-OBJ

A Blender add-on for importing a sequence of OBJ meshes as frames
GNU General Public License v3.0
679 stars 52 forks source link

Materials do not have image textures applied #103

Closed alter-sachin closed 4 years ago

alter-sachin commented 4 years ago

System Information Operating system:Linux

Addon version

Worked: (latest version of Stop Motion OBJ that worked as expected)

HI, I have an auto generated sequence of faces generated where each obj has its corresponding MTL and image texture png file. The sequence of objs shows up well in the animations but no textures show up in any view. I hope you could help me in ascretaining what the issue is.

The blender view Screenshot from 2020-08-20 06-03-19 My sequence of Obj files with mtl and png Screenshot from 2020-08-20 06-04-05

alter-sachin commented 4 years ago

https://drive.google.com/file/d/1s3rEvrmj7Sqi2_ya87NAsHzEQ_UgM80p/view?usp=sharing

You can download the sequence from the above link

Best Regards

alter-sachin commented 4 years ago

I hacked together a script to be able to this for me :

`import bpy

scene = bpy.context.scene

i = 0

def returnIfObject(passedName=""): try: result = bpy.data.objects[passedName] except: result = None return result

while(True): scene = bpy.context.scene frame_number = "%05d" % i

print(frame_number)

texture_name = str(frame_number)+".png"
object_name = str(frame_number)
#bpy.ops.image.open(filepath="/home/sachin/Desktop/augmented/voca/TF_FLAME/results/out/"+str(texture_name), directory="/home/sachin/Desktop/augmented/voca/TF_FLAME/results/out/", files=[{"name":texture_name, "name":texture_name}], relative_path=True, show_multiview=False)

mat = bpy.data.materials.new(name=texture_name)
mat.use_nodes = True
bsdf = mat.node_tree.nodes["Principled BSDF"]
texImage = mat.node_tree.nodes.new('ShaderNodeTexImage')
texImage.image = bpy.data.images.load("/home/sachin/Desktop/augmented/voca/TF_FLAME/results/out/"+str(texture_name))
mat.node_tree.links.new(bsdf.inputs['Base Color'], texImage.outputs['Color'])
# Assign it to object
bpy.context.scene.frame_set(i)
#bpy.context.scene.frame_current = i
#myObj = returnIfObject(object_name)
#print(myObj)
#if myObj != None:
#scene = bpy.context.scene
#scene.object.active = myObj
ob = bpy.context.object
if ob.data.materials:
    ob.data.materials[0] = mat
else:
    ob.data.materials.append(mat)
i = i +1
#scene.update()
if(i>99):
    break

`

Thankyou for a great addon :)

neverhood311 commented 4 years ago

Thanks for providing the .obj sequence for me to inspect. I tried importing a single mesh from your sequence by doing File > Import > Wavefront (.obj) and Blender still didn't import your material. So I opened up one of your .obj files in a text editor. It looks like you're properly locating the .mtl file with the line: mtllib 00000.mtl, but you're not actually assigning a material to the object, using the line usemtl 00000.

How did you generate these files? If you're creating them with a script, simply add the line usemtl 00000 right after the mtllib 00000.mtl line (obviously you'd replace '00000' with the correct frame number for each frame) and it should import materials automatically without your clever script.

StephenMcAvoy commented 4 years ago

I had a look at the mtl and obj files. They don’t look right for uv mapping. They look right for what is displayed.

Incidentally I have been looking at what the OBJ import module outputs. IYKWIM I have worked out a couple of manual workarounds for transparency maps not being imported correctly. And for bmp maps displaying as if uv mapping was broken. If anyone is interested I’ll write something up.