Textures are not loaded with .obj

Forums: Textures are not loaded with .obj
Forum for OctaneRender Lua scripting examples, discussion and support.

Textures are not loaded with .obj

Postby SamuliKuusisto1 » Mon Apr 25, 2016 8:26 am

SamuliKuusisto1 Mon Apr 25, 2016 8:26 am
Hi,
I'm trying to build a scene and render it via script using lua scripting. Why textures are not loaded to the .obj file? I've tested the script with two different .obj-models, and the textures are loaded only to the other. The script:
Code: Select all
rt = octane.node.create{ type=octane.NT_RENDERTARGET, name="Impl RT" } -- implicit in the root graph
mesh=octane.node.create{type=octane.NT_GEO_MESH, name="mesh1"}
mesh:setAttribute(34,"D:/Projects/visudevel/Octane/VT7/vt7.obj",true)

print(rt:getProperties().graphOwned, rt:getProperties().graphOwner)
daylightEnv=octane.node.create{type=octane.NT_ENV_DAYLIGHT, name="daylight"}
daylightEnv.setPinValue(daylightEnv,"sundir",{63.0,23.4,6.00,20,12.00,2.00})
daylightEnv.setPinValue(daylightEnv,120,0.5)

placement=octane.node.create{type=octane.NT_GEO_PLACEMENT, name="placement1"}
print(placement:getProperties().graphOwned, placement:getProperties().graphOwner)
transform=octane.node.create{type=octane.NT_TRANSFORM_3D, pinOwnerNode=placement, pinOwnerId=octane.P_TRANSFORM}
transform.setPinValue(transform,"rotationOrder",2)
transform.setPinValue(transform,"rotation",{-90,90,0})
placement:connectTo("geometry",mesh)
rt:connectTo("mesh",placement)
rt:connectTo("environment",daylightEnv)
print(transform:getProperties().pinOwned, transform:getProperties().pinOwnerNode)
-- create a panoramic camera in the camera pin of the render target
-- we need to specify both the node that has the pin and the pin itself
rt:setPinValue(198,{8192,2048})
pcam = octane.node.create{ type=octane.NT_CAM_PANORAMIC, pinOwnerNode=rt, pinOwnerId=octane.P_CAMERA}
pcam:setPinValue(228,3)
pcam.setPinValue(pcam,20,0)
pcam.setPinValue(pcam,87,true)
--[[pcam.setPinValue(pcam,133,{-19,410,-353})--]]

-- see if the file exists
function file_exists(file)
  local f = io.open(file, "rb")
  if f then f:close() end
  return f ~= nil
end

function lines_from(file)
  if not file_exists(file) then return {} end
  lines = {}
  for line in io.lines(file) do
    lines[#lines + 1] = line
  end
  return lines
end
lines=lines_from("D:/Projects/visudevel/Octane/VT7/vt7.txt")
function parse(line1)
    --[[file=io.open(filename)
    io.input(file)
    line1=io.read()--]]
    print("line:",line1)
    index1,index2=string.find(line1," / ", 1)
    print(index1,index2)
    name=string.sub(line1,1,index2)
    print(name)
    line2=string.sub(line1,index2+1,string.len(line1))
    print(line2)
    index3,index4=string.find(line2," / ", 1)
    line3=string.sub(line2,index4+1,string.len(line2))
    print(line3)
    index5,index6=string.find(line3," / ", 1)
    x=string.sub(line3,1,index5)
    print(x)
    line4=string.sub(line3,index6+1,string.len(line3))
    index7,index8=string.find(line4," / ",1)
    y=string.sub(line4,1,index7)
    print(y)
    line5=string.sub(line4,index8+1,string.len(line4))
    index9,index10=string.find(line5," / ",1)
    z=string.sub(line5,1,index9)
    print(z)

    return x,y,z
    end
for i=1,#lines,1
do   
    x1,y1,z1=parse(lines[i])
    print(x1,y1,z1)
    pcam.setPinValue(pcam,"pos",{-y1,z1,-x1})
    print("D:/Projects/visudevel/Octane/VT7/vt7_"..i..".png")
    print(pcam.getNodeInfo(pcam).takesPinDefaultValues)
    print(pcam:getProperties().pinOwned, pcam:getProperties().pinOwnerNode, octane.apiinfo.getPinTypeName(8), pcam:getPinValue(20), pcam:getPinCount())
    octane.render.start{renderTargetNode=rt}
    print(octane.render.saveImage("D:/Projects/visudevel/Octane/VT7/vt7_"..i..".png",octane.render.imageType.PNG8,false))
end
SamuliKuusisto1
 
Posts: 1
Joined: Mon Apr 25, 2016 8:19 am
Location: Espoo, Suomi

Re: Textures are not loaded with .obj

Postby jobigoud » Wed Apr 27, 2016 9:00 am

jobigoud Wed Apr 27, 2016 9:00 am
1. Are you positive that the mtl file does reference textures? You should be able to open the .obj and .mtl in a text editor to verify.
2. Does it work when you add the mesh through the UI rather than a script?
3. Does the resulting mesh work if you run just the two relevant lines directly in the script editor?
Code: Select all
mesh=octane.node.create{type=octane.NT_GEO_MESH, name="mesh1"}
mesh:setAttribute(octane.attributeId.A_FILENAME, "D:/Projects/visudevel/Octane/VT7/vt7.obj", true)

If the referenced texture was missing from the disk you would get an "Open file" dialog (even if loaded from script).

There are also global options under menu File > Preferences > Import > OBJ Import > Material types and Texture types. See whether some types are unchecked.
User avatar
jobigoud
OctaneRender Team
OctaneRender Team
 
Posts: 24
Joined: Sat Aug 15, 2015 1:28 pm

Re: Textures are not loaded with .obj

Postby roeland » Mon May 30, 2016 2:35 am

roeland Mon May 30, 2016 2:35 am
Note also that you can use the constants defined in the API to reference attribute and pins, for example octane.A_FILENAME in the code above.
User avatar
roeland
OctaneRender Team
OctaneRender Team
 
Posts: 1741
Joined: Wed Mar 09, 2011 10:09 pm

Return to Lua Scripting


Who is online

Users browsing this forum: No registered users and 1 guest

Sun Nov 17, 2019 4:06 pm [ UTC ]