dir = @"D:\internet evaluation\3FO4L4J6SN3M\"
-----------------deal furnitures---------------------------------
furnitureDir = dir + "furniture_config.xml"
furnitureDoc = dotNetObject "system.xml.xmlDocument"
furnitureDoc.load furnitureDir
meshElements = furnitureDoc.GetElementsByTagName "mesh"
for i=0 to meshElements.count-1 do(
local curMesh = meshElements.item i
local trans = curMesh.GetAttribute "trans"
local mPos = GetTransform trans "pos"
local mRotation = GetTransform trans "rotation"
local mScale = GetTransform trans "scale"
local furnitureNameNode = (curMesh.GetElementsByTagName "Name").item 0
local furnitureId = furnitureNameNode.InnerText
modelFileDir = dir+"models/"+furnitureId+"/models_baked.obj"
materialFileDir = dir+"models/"+furnitureId+"/material_map.xml"
importFile modelFileDir #noPrompt
for i=1 to $selection.count do(
local cMat= CreateVrayMtl materialFileDir furnitureId $selection[i].name
$selection[i].material = cMat
$selection[i].name += "_"+furnitureId
$selection[i].pos = mPos
$selection[i].rotation = mRotation
$selection[i].scale = mScale
)
)
---------------------------------furniture reference functions---------------------------------------
fn GetTransform trans type =
(
local t = FilterString trans ","
if(type == "pos") then return [t[4] as float,t[8] as float,t[12] as float]
if(type == "scale") then return [t[1] as float,t[6] as float,t[11] as float]
if(type == "rotation")then return eulerAngles 0 0 0
)
fn ConveterAttribute type value =
(
if type == "Integer" do
(
return value as integer
)
if type == "Float" do
(
return value as float
)
if type == "Float3" do
(
local tValue = FilterString value ","
local rf = tValue[1] as float * 255.0
local ri = rf as integer
local gf = tValue[2] as float * 255.0
local gi = gf as integer
local bf = tValue[3] as float * 255.0
local bi = bf as integer
return [ri,gi,bi]
)
if type == "Composite" do
(
--return value as float
)
)
fn CreateVrayMtl materialPath meshID subMeshName =
(
local mat = VRayMtl()
mat.name = "Mat_" + subMeshName + "_" + meshID
materialDoc = dotNetObject "system.xml.xmlDocument"
materialDoc.load materialPath
xmlroot = materialDoc.DocumentElement
materialSections = xmlroot.childNodes
for i =0 to materialSections.count-1 do
(
local curSection = materialSections.item i
if curSection.GetAttribute "BakeName" == subMeshName do
(
local paramNodes = curSection.firstChild.childNodes
for k =0 to paramNodes.count-1 do
(
local paramNode = paramNodes.item k
local vrayName = paramNode.getattribute "Name"
local Ttype = paramNode.getattribute "Type"
local Tvalue = paramNode.getattribute "Value"
local result = ConveterAttribute Ttype Tvalue
if vrayName == "diffuse" do
(
mat.Diffuse = result
)
if vrayName == "diffuseTex" do
(
mat.texmap_diffuse = result
)
)
)
)
return mat
)