-- lua -- Collada 1.4.1 exporter -- v1.01 -- by Richard Rodriguez, 2007 -- -- Additional code: Zoltan Erdokovy -- --[[ --------------------------------- ------------ Usage------------ --------------------------------- For the default OBJECT mode, run the script without arguments: @collada_exporter.lua For RIGID and SOFT modes, append the proper argument: @collada_exporter.lua rigid @collada_exporter.lua soft Output file will be created in the "ContentDirectory", as defined in the Modo preferences. For a more detailed manual, please visit http://www.sparkingspot.com/a_tutorial09.php ------------------------------------------------ This software is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported License. For more info please visit http://creativecommons.org/licenses/by-sa/3.0/ ------------------------------------------------ Changelog: v1.01: - Changed bone names in SOFT mode: now they are ">UBX_Name" or ">USP_Name" - OBJECT mode collision layers use a more consistent naming convention: ">UBX", ">USP" and ">UCX" - Removed "joint" from bone IDs. - Removed collision primitive name from bone names. - Now the scene's name is the export file name in RIGID and SOFT modes. - RGB map name checking, and default value of 1,1,1. ------------------------------------------------ --]] ------------------------------------------------ ------------ Heirachy tables ------------ ------------------------------------------------ ordered_ids = {} -- ID's ordered by heirarchy id_tabs = {} -- Number of tabs, per mesh ID id_names = {} -- Names, per mesh ID parent_ids = {} -- Parent ID, per mesh ID vert_layers = {} id_vert_counts = {} -- Names, per mesh Vert count id_layers = {} layer_ids = {} id_worldloc = {} id_pivotpos = {} id_mesh_verts = {} id_soft_weights = {} -- for soft mode only id_weight_bias = {} -- for soft mode only world_scale_list = {} ------------------------------------------------ ------------ Constants/Options ------------ ------------------------------------------------ all_weights = true -- if false, it will use simple weights. only 0 or 1 Use_FaceVertNormal = true -- if true, it uses vertex normals per face vert, to preserve smoothing groups. If false it will get polygon normals MergeVerts = false -- if true, it will attempt to merge verts based on MergeTollerance MergeTollerance = 0.00001 meter_per_gunit = lxq("pref.value units.gameScale ?")[1] -- get accurate game units use_item_filename = true -- if true, it will use the mode and root item as the output filename, if false, it will use "test.dae" use_soft_bias = true -- if true, it will apply bias to weights in SOFT mode ------------------------------------------------ ------------ Input Verification Functions ------------ ------------------------------------------------ -- OutputMode options: OBJECT, RIGID, SOFT function getOutputMode(mode_in) test_mode = string.upper(mode_in) if(test_mode == "OBJECT" or test_mode == "RIGID" or test_mode == "SOFT") then return test_mode end return "OBJECT" -- Default OutputMode end -- Unit options: GAMEUNIT, METER, MILLIMETER, FEET, INCH function getUnitSystem(unit_in) test_unit = string.upper(unit_in) if(test_unit == "GAMEUNIT" or test_unit == "METER" or test_unit == "MILLIMETER" or test_unit == "FEET" or test_unit == "INCH") then return test_unit end return "GAMEUNIT" -- Default UnitSystem end -- Unit options: GAMEUNIT, METER, MILLIMETER, FEET, INCH function getUnitScale(unit_in) if(unit_in == "GAMEUNIT") then return (1/meter_per_gunit) --return 53.3 elseif unit_in == "METER" then return 1 elseif unit_in == "MILLIMETER" then return 1000 elseif unit_in == "FEET" then return 3.2808398950131 elseif unit_in == "INCH" then return 39.3700787 end return 1 -- Default UnitScale end -- Checking for UV maps named UVn where n is a number. "UV1", "UV2", and "UV77" are valid UV names. function test_UV_name(name_in) if(string.len(name_in) <= 2) then -- Too small return false end uv_part = string.sub(name_in,1,2) if(uv_part ~= "UV") then -- No UV prefix return false end num_part = string.sub(name_in,3) number = tonumber(num_part) if(number == nil) then -- Not a Number return false end return true end function test_vertexcolor(name_in) if (string.lower(name_in) == "color") then return true end return false end function test_Object_name(name_in, cur_mode) if(cur_mode == "OBJECT") then --[[ if(name_in == ">UBX" or name_in == ">USP" or name_in == ">UCX") then return true elseif(cur_mode == "OBJECT" and name_in == "UCX") then return true end return false ]]-- test_1 = string.find(name_in, ">UBX") test_2 = string.find(name_in, ">USP") test_3 = string.find(name_in, ">UCX") if(test_1 ~= nil or test_2 ~= nil or test_3 ~= nil) then return true end return false elseif(cur_mode=="SOFT") then test_1 = string.find(name_in, ">UBX") test_2 = string.find(name_in, ">USP") if(test_1 ~= nil or test_2 ~= nil) then return true end return false end return true end ------------------------------------------------ ------------ Utility Functions ------------ ------------------------------------------------ -- Create Tabs function tabs(num) outTabs = "" for t=1, num do outTabs = outTabs.."\t" end return outTabs end -- Add leading 0 to numbers less than 10 function add_lead_zero(num) if(num < 10) then return "0" .. num end return num end -- Fix item names. function fix_name(in_name) fixed = string.gsub(in_name, " ", "_") -- Space to underscore fixed = string.gsub(fixed, "%(", "") -- Drop ( fixed = string.gsub(fixed, "%)", "") -- Drop ) fixed = string.gsub(fixed, ">UBX_", "") -- Drop >UBX_ fixed = string.gsub(fixed, ">USP_", "") -- Drop >USP_ return fixed -- string.gsub(in_name, " ", "_") end function round(num, idp) local mult = 10^(idp or 0) return math.floor(num * mult + 0.5) / mult end -- Rounds number to have no more than 6 decimal places, and remove exponentials function fix_float(in_float) return round(in_float, 6) end -- Stream to Text File function output(output_val) if(outputStream == nil) then if(Full_FileName == nil) then Full_FileName = "G:\\dev\\Modo_Collada_exporter\\my_scripts\\test.dae" end -- Open output file outputStream = io.open(Full_FileName, "w") end outputStream:write(output_val) end function getn (t) -- Unused if type(t.n) == "number" then return t.n end local max = 0 for i, _ in t do if type(i) == "number" and i>max then max=i end end return max end function getDistance(ptA, ptB) dif_x = ptB[1] - ptA[1] dif_y = ptB[2] - ptA[2] dif_z = ptB[3] - ptA[3] return math.sqrt(dif_x^2 + dif_y^2 + dif_z^2) end function bias_adjust(in_weight, in_bias) if(in_weight == 1 or in_weight == 0) then return in_weight end rem_bias = 1 - in_bias if(in_weight >= rem_bias) then return 1 end return (in_weight / rem_bias) end function add_3f(ptA, ptB) result_pt = {} result_pt[1] = ptA[1] + ptB[1] result_pt[2] = ptA[2] + ptB[2] result_pt[3] = ptA[3] + ptB[3] return result_pt end ------------------------------------------------ ------------ Collada XML Output Functions ------------ ------------------------------------------------ function output_3f(head, values_3f, scale, tail) if(scale == nil) then scale = 1 end if(tail == nil) then tail = "\n" end output(head .. fix_float(-values_3f[3]*scale) .. "\t" .. fix_float(values_3f[2]*scale) .. "\t" .. fix_float(values_3f[1]*scale) .. tail) end function output_3f_rotate(head, values_3f, tail) if(tail == nil) then tail = "\n" end output(head .. [[1 0 0 ]] .. fix_float(-item_rot[3]) .. tail) output(head .. [[0 1 0 ]] .. fix_float(item_rot[2]) .. tail) output(head .. [[0 0 1 ]] .. fix_float(item_rot[1]) .. tail) end function output_3f_round(head, values_3f, scale, tail) if(scale == nil) then scale = 1 end if(tail == nil) then tail = "\n" end output(head .. round(-values_3f[3]*scale) .. "\t" .. round(values_3f[2]*scale) .. "\t" .. round(values_3f[1]*scale) .. tail) end function output_3f_round_scaled(head, values_3f, scale, w_scale, tail) if(scale == nil) then scale = 1 end if(tail == nil) then tail = "\n" end output(head .. round(-values_3f[3]*scale*w_scale[3]) .. "\t" .. round(values_3f[2]*scale*w_scale[2]) .. "\t" .. round(values_3f[1]*scale*w_scale[1]) .. tail) end function output_matrix(head, trans_values, scale) output(head .. "1\t0\t0\t" .. round(trans_values[3]*scale) .. "\n") output(head .. "0\t1\t0\t" .. round(-trans_values[2]*scale) .. "\n") output(head .. "0\t0\t1\t" .. round(-trans_values[1]*scale) .. "\n") output(head .. "0\t0\t0\t1\n") end -- Stream Asset Tag to Text File function output_asset_tag() output( tabs(1) .. "\n" .. tabs(2) .. "\n") output( tabs(3) .. "Richard Rodriguez (aka. Game Master 770)\n") output( tabs(3) .. "Modo 301\n") output( tabs(3) .. "\n") output( "Custom Modo 301 output, designed for Zoltan Erdokovy and Unreal.\n") output("OutputMode = " .. OutputMode .. " , UnitSystem = " .. UnitSystem .. " , UnitScale = " .. UnitScale .. "\n") output( tabs(3) .. "\n") output( tabs(3) .. "Copyright 2007 Richard Rodriguez. All Rights Reserved.\n") output( tabs(2) .. "\n") cur_date = os.date("*t") date_str = cur_date["year"] .. "-" .. add_lead_zero(cur_date["month"]) .. "-" .. add_lead_zero(cur_date["day"]) .. "T" .. add_lead_zero(cur_date["hour"]) .. ":" .. add_lead_zero(cur_date["min"]) .. ":" .. add_lead_zero(cur_date["sec"]) .. "Z" output( tabs(2) .. "" .. date_str .. "\n") output( tabs(2) .. "" .. date_str .. "\n") output( tabs(2) .. [[]] .. "\n") output( tabs(2) .. "Y_UP\n") output( tabs(1) .. "\n") end -- Material section is not exported, so we export a default white material function output_default_phong() output( [[ 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 20.0 1.0 1.0 1.0 1.0 0.5 1.0 1.0 1.0 1.0 1.0 ]]) end function output_default_physics_material() output( tabs(1) .. "\n") output( tabs(2) .. [[]] .. "\n") output( tabs(3) .. "\n") output( tabs(4) .. "1.0\n") output( tabs(4) .. "0\n") output( tabs(4) .. "1.0\n") output( tabs(3) .. "\n") output( tabs(2) .. "\n") output( tabs(1) .. "\n") end -- --------- Vertex Data --------- function output_vertex_data(mesh_id, vert_table, scale) output( tabs(4) .. [[]] ) VertCount = table.getn(vert_table) output( tabs(5) .. [[]] .. "\n") for i=1,VertCount do temp_vert = vert_table[i] output_3f(tabs(6), temp_vert, scale) end output( tabs(5) .. "\n") output( tabs(5) .. "\n") output( tabs(6) .. [[]] .. "\n") output( tabs(7) .. [[]] .. "\n") output( tabs(7) .. [[]] .. "\n") output( tabs(7) .. [[]] .. "\n") output( tabs(6) .. "\n") output( tabs(5) .. "\n") output( tabs(4) .. "\n") output( tabs(4) .. [[]] .. "\n") output( tabs(5) .. [[]] .. "\n") output( tabs(4) .. "\n") end -- --------- Polygon Normal Data --------- function output_polygon_normal_data(mesh_id, mat_list) output( tabs(4) .. [[]] .. "\n" ) renderPolyNormals = getMeshPolyNormals() PolyCount = table.getn(renderPolyNormals) output( tabs(5) .. [[]] .. "\n" ) for m=1, table.getn(mat_list) do cur_mat_name = mat_list[m] for p=1,(table.getn(renderPolyNormals)) do poly_mat = lxq("query layerservice poly.material ? " .. p-1)[1] if(poly_mat == cur_mat_name) then output_3f(tabs(6), renderPolyNormals[p]) end end end output( tabs(5) .. "\n") output( tabs(5) .. "\n") output( tabs(6) .. [[]] .. "\n" ) output( tabs(7) .. [[]] .. "\n") output( tabs(7) .. [[]] .. "\n") output( tabs(7) .. [[]] .. "\n") output( tabs(6) .. "\n") output( tabs(5) .. "\n") output( tabs(4) .. "\n") end ------------------------------------------------ ------------ Modo Related Functions ------------ ------------------------------------------------ -- Get Layer # for each mesh ID function build_layer_list() local id_layer = {} local id_vert_count = {} local layer_id = {} layers = lxq("query layerservice layer.id ? all") for i,v in ipairs(layers) do id_layer[v] = i layer_id[i] = v mesh_name = lxq("query layerservice layer.index ? " .. i) vert_count = lxq("query layerservice vert.N ? all")[1] id_vert_count[v] = lxq("query layerservice vert.N ? all")[1] end return { id_layer, layer_id, id_vert_count } --, vert_layer } end -- Fill-up Heirachy tables function build_heir_list( start_id, num, cur_mode) if(num == 0) then item_name = lxq("query sceneservice item.name ? " .. start_id)[1] in_list = false for i=1,(table.getn(ordered_ids)) do if(ordered_ids[i] == start_id) then in_list = true end end if(in_list == false) then table.insert(ordered_ids, start_id) parent_ids[start_id] = "0" end id_tabs[start_id] = 0 id_names[start_id] = item_name end local children = lxq("query sceneservice item.children ? " .. start_id) if(children ~= nil) then c_count = table.getn(children) for c=1, c_count do item_type = lxq("query sceneservice item.type ? " .. children[c])[1] if(item_type == "mesh") then item_name = lxq("query sceneservice item.name ? " .. children[c])[1] if(test_Object_name(item_name, cur_mode) == true) then in_list = false for i=1,(table.getn(ordered_ids)) do if(ordered_ids[i] == children[c]) then in_list = true end end if(in_list == false) then table.insert(ordered_ids, children[c]) parent_ids[children[c]] = start_id end id_tabs[children[c]] = num+1 id_names[children[c]] = item_name end end build_heir_list( children[c], num+1, cur_mode) end end end -- Sums up parent's scale, to get world scale function getWorldScaleList(id_list, parent_id_list) transform_list = {} for i in id_list do id = id_list[i] item_siz = lxq("query sceneservice item.scale ? " .. id) item_sx = item_siz[1] item_sy = item_siz[2] item_sz = item_siz[3] id = parent_id_list[id] while id ~= "0" do parent_siz = lxq("query sceneservice item.scale ? " .. id) item_sx = item_sx * parent_siz[1] item_sy = item_sy * parent_siz[2] item_sz = item_sz * parent_siz[3] id = parent_id_list[id] end transform_list[ id_list[i] ] = { item_sx, item_sy, item_sz } end return transform_list end -- Copying Render data, and world verts to a new scene -- function build_render_scene(output_mode, id_list, root_id, vert_counts) --, id_layer) if(output_mode == "RIGID") then render_layers = id_list else render_layers = {root_id} end lxout("- Copying data to a new scene. -") OriginalScene = lxq("query sceneservice scene.index ? current")[1] -- Store the index of the source scene. lx("scene.new") NewScene = lxq("query sceneservice scene.index ? current")[1] -- Store the index of the new scene. lx("item.name [Collada Render Mesh] mesh") -- Set proper name. lx("select.type polygon") for i=1,(table.getn(render_layers)) do lx("scene.set "..OriginalScene) -- Go back from the new scene to the original. item_id = render_layers[i] vert_count = vert_counts[item_id] for vert=1, vert_count do table.insert(vert_layers, i) end lx("select.item [" .. item_id .. "]") lx("select.type polygon") lx("select.copy") -- Copy layer contents. lx("scene.set "..NewScene) -- Go to the new scene. if(i ~= 1) then lx("select.polygon add 0 face 0") end lx("select.paste") -- Paste stuff. if(output_mode == "RIGID") then -- Label source objects lx("select.invert") lx("poly.setPart {" .. id_names[item_id] .. "}") end end render_id = lxq("query sceneservice selection ? mesh")[1] convex_count = 0 -- Convex Hull Section if(output_mode == "OBJECT" and table.getn(id_list) > 1) then lxout("- Copying Convex Hull Mesh to a new scene. - " .. table.getn(id_list)) lx("layer.newItem mesh") convex_id = lxq("query sceneservice selection ? mesh")[1] lx("item.name [Convex Hull Mesh] mesh") for i=2, (table.getn(id_list)) do lx("scene.set "..OriginalScene) item_id = id_list[i] lx("select.item [" .. item_id .. "]") lx("select.type polygon") item_name = lxq("query sceneservice item.name ? " .. item_id)[1] lx("select.copy") -- Copy layer contents. lx("scene.set "..NewScene) -- Go to the new scene. lx("select.item [" .. convex_id .. "]") if(item_name == "UCX") then lx("select.paste") -- Paste stuff. convex_count = convex_count +1 end end end -- Collect World position of items, and pivots, and store as a vert cloud in new scene lxout("- Copying World Positions as verts, to a new scene. -") lx("layer.newItem mesh") lx("item.name [World Pos Mesh] mesh") -- Set proper name. world_verts_id = lxq("query sceneservice selection ? mesh")[1] lx("layer.newItem mesh") lx("item.name [World Pivot Mesh] mesh") -- Set proper name. world_pivots_id = lxq("query sceneservice selection ? mesh")[1] for i=1, (table.getn(id_list)) do lx("scene.set "..OriginalScene) item_id = id_list[i] lx("select.item [" .. item_id .. "]") lx("select.typeFrom vertex") vert_count = vert_counts[item_id] lx("vert.new 0 0 0") lx("select.element [" .. id_layers[item_id] .. "] vertex set [" .. vert_count .. "]") lx("select.cut") lx("scene.set "..NewScene) lx("select.item [" .. world_verts_id .. "]") lx("select.paste") lxq("query layerservice layer.index ? 2") id_worldloc[item_id] = lxq("query layerservice vert.pos ? last") lx("scene.set "..OriginalScene) item_id = id_list[i] lx("select.item [" .. item_id .. "]") lx("select.typeFrom vertex") id_pivotpos[item_id] = lxq("query sceneservice item.pivPos ? " .. item_id) lx("vert.new " .. id_pivotpos[item_id][1] .. " " .. id_pivotpos[item_id][2] .. " " .. id_pivotpos[item_id][3]) lx("select.element [" .. id_layers[item_id] .. "] vertex set [" .. vert_count .. "]") lx("select.cut") lx("scene.set "..NewScene) lx("select.item [" .. world_pivots_id .. "]") lx("select.paste") lxq("query layerservice layer.index ? 3") id_pivotpos[item_id] = lxq("query layerservice vert.pos ? last") end lx("scene.set "..NewScene) -- Go to the new scene. if(output_mode == "SOFT" and table.getn(id_list) > 1) then lx("select.item [" .. render_id .. "]") lx("select.typeFrom vertex") lx("select.copy") lxq("query layerservice layer.index ? 1") mesh_name = lxq("query layerservice layer.name ? 1")[1] id_mesh_verts[id_list[1] ] = getMeshVerts() lx("scene.set "..OriginalScene) for i=2,(table.getn(id_list)) do item_id = id_list[i] mesh_name = id_names[item_id] test_name = string.find(mesh_name, ">UBX") lx("select.item [" .. item_id .. "]") id_weight_bias[item_id] = lxq("mesh.spatchSubdiv ?")[1] if(test_name ~= nil) then lx("select.typeFrom vertex") lx("select.vertex add 0 all 0") lx("select.paste") lx("select.invert") lxq("query layerservice layer.index ? " .. id_layers[item_id]) id_mesh_verts[item_id] = getMeshVerts() lx("select.cut") end end world_scale_list = getWorldScaleList(ordered_ids, parent_ids) build_weights(world_scale_list) lx("scene.set "..NewScene) -- Go to the new scene. end if(convex_count == 0) then convex_id = nil end lx("select.item [" .. render_id .. "]") -- At the end of running this function, the New scene is the current scene return {OriginalScene, render_id, convex_id, world_verts_id} end -- Build weight array for Soft mode, apply bias if option is enabled function build_weights(scale_list) for i=2, table.getn(ordered_ids) do weights = {} item_id = ordered_ids[i] name = id_names[item_id] bias_ratio = id_weight_bias[item_id] / 100 -- Falloff for Cubic primitives if(string.find(name, ">UBX") ~= nil and id_mesh_verts[item_id] ~= nil) then count = id_vert_counts[item_id] verts = id_mesh_verts[item_id] for n=count+1,table.getn(verts) do v_max = 0 vert = verts[n] vx = math.abs(vert[1]*UnitScale) if(vx > v_max) then v_max = vx end vy = math.abs(vert[2]*UnitScale) if(vy > v_max) then v_max = vy end vz = math.abs(vert[3]*UnitScale) if(vz > v_max) then v_max = vz end if(v_max > 0.5) then weight = 0 else weight = (0.5 - v_max)*2 if(use_soft_bias == true) then weight = bias_adjust(weight, bias_ratio) end end table.insert(weights, weight) end -- Falloff for Sphere primitives elseif(string.find(name, ">USP") ~= nil) then wloc = id_worldloc[item_id] verts = id_mesh_verts[ordered_ids[1]] item_siz = scale_list[item_id] s_max = 0 sx = math.abs(item_siz[1] ) if(sx > s_max) then s_max = sx end sy = math.abs(item_siz[2] ) if(sy > s_max) then s_max = sy end sz = math.abs(item_siz[3] ) if(sz > s_max) then s_max = sz end for n=1,table.getn(verts) do dist = getDistance(wloc, verts[n]) * UnitScale if(dist > (s_max/2) ) then weight = 0 else weight = (1-(dist / s_max)*2) if(use_soft_bias == true) then weight = bias_adjust(weight, bias_ratio) end end table.insert(weights, weight) end end id_soft_weights[item_id] = weights end end function getMeshVerts() outVerts = {} vertexCount = lxq("query layerservice vert.N ? all")[1] for v=1, vertexCount do vertex_xyz = lxq("query layerservice vert.pos ? " .. v-1) table.insert(outVerts, vertex_xyz) end return outVerts end function getVert_MergeTable(vert_list, vert_list_b, scale) merge_table = {} for m=1, table.getn(vert_list) do for v=1, table.getn(vert_list_b) do if(fix_float(vert_list[m][1]) == fix_float(vert_list_b[v][1]) and fix_float(vert_list[m][2]) == fix_float(vert_list_b[v][2]) and fix_float(vert_list[m][3]) == fix_float(vert_list_b[v][3]) ) then merge_table[m] = v break end end end return merge_table end function getVert_MergeTables_OldNew(vert_list, scale) merge_table = {} no_repeat_table = {} new_merge_table = {} for m=1, table.getn(vert_list) do for v=1, table.getn(vert_list) do dif_x = math.abs(fix_float(vert_list[m][1]*scale) - fix_float(vert_list[v][1]*scale) ) dif_y = math.abs(fix_float(vert_list[m][2]*scale) - fix_float(vert_list[v][2]*scale) ) dif_z = math.abs(fix_float(vert_list[m][3]*scale) - fix_float(vert_list[v][3]*scale) ) if(MergeTollerance >= dif_x and MergeTollerance >= dif_y and MergeTollerance >= dif_z) then no_repeat_table[m] = v break end end end for m=1, table.getn(no_repeat_table) do in_table = false for v=1, table.getn(new_merge_table) do if(no_repeat_table[m] == new_merge_table[v]) then in_table = true break end end if(in_table == false) then table.insert(new_merge_table, no_repeat_table[m]) end end for m=1, table.getn(no_repeat_table) do for v=1, table.getn(new_merge_table) do if(no_repeat_table[m] == new_merge_table[v]) then merge_table[m] = v end end end return {merge_table, new_merge_table} end function getMeshPolyNormals(material_name) outNormals = {} polyCount = lxq("query layerservice poly.N ? all")[1] for p=1, polyCount do normal_xyz = lxq("query layerservice poly.normal ? " .. p-1) table.insert(outNormals, normal_xyz) end return outNormals end function getPolygonVerts(material_name) polys = {} polyCount = lxq("query layerservice poly.N ? all")[1] poly_indexs = {} for p=1, polyCount do m_name = lxq("query layerservice poly.material ? " .. p-1)[1] if(m_name == material_name or material_name == nil) then vert_list = lxq("query layerservice poly.vertList ? " .. p-1) verts={} for i=1,(table.getn(vert_list)) do table.insert(verts, (vert_list[i]) ) --+offset) ) end table.insert(polys, verts) table.insert(poly_indexs, p-1) end end return {polys, poly_indexs} end function getMaterialPolys() mats = {} polyCount = lxq("query layerservice poly.N ? all")[1] for p=1, polyCount do mat_name = lxq("query layerservice poly.material ? " .. p-1)[1] if (mats[mat_name] == nil) then mats[mat_name] = {p} else polys = mats[mat_name] table.insert (polys, p) --+offset) mats[mat_name] = polys end end return mats end ------------------------------------------------ ------------ Start of Main Program ------------ ------------------------------------------------ -- Test for a Mesh selected (Root Mesh) root_mesh = lxq("query sceneservice selection ? mesh") if(root_mesh == nil or table.getn(root_mesh) ~= 1) then error("Must Select 1 Mesh as the Root Mesh") end root_mesh_id = root_mesh[1] root_mesh_name = lxq("query layerservice layer.name ? " .. root_mesh_id)[1] lxout("Selected Mesh = " .. root_mesh_name .. " [" .. root_mesh_id .. "]") ------------------------------------------------ ------------ More Constants ------------ ------------------------------------------------ OutputMode = getOutputMode(tostring(arg[1])) UnitSystem = getUnitSystem("GAME") UnitScale = getUnitScale(UnitSystem) lxout("OutputMode = " .. OutputMode) lxout("UnitSystem = " .. UnitSystem) lxout("UnitScale = " .. UnitScale) -- Setup Output File ContentDir = lxq("pref.value lwio.lwoContentDir ?") if(ContentDir == nil or string.len(ContentDir[1]) == 0) then error("Enter Content Dir in Modo Preferences") end fileName = "test.dae" if ((OutputMode == "RIGID") or (OutputMode == "SOFT")) then sceneName = lxq("query sceneservice scene.name ? 0")[1] fileName = string.sub(sceneName, 1, string.len(sceneName)-4) -- Drop the last four chars. (Usually ",lxo".) fileName = fix_name(fileName) .. ".dae" else -- In OBJECT mode, filename is the root mesh's name. fileName = fix_name(root_mesh_name) .. ".dae" end --[[if(use_item_filename == true) then -- fileName = string.lower(OutputMode) .. "_" .. fix_name(root_mesh_name) .. ".dae" fileName = fix_name(root_mesh_name) .. ".dae" end]]-- Full_FileName = ContentDir[1] .. "\\" .. fileName lxout("Output to: " .. Full_FileName) build_heir_list(root_mesh_id, 0, OutputMode) layer_list = build_layer_list() -- Modo Layer #, per mesh ID & vertcount id_layers = layer_list[1] -- Modo Layer #, per mesh ID layer_ids = layer_list[2] id_vert_counts = layer_list[3] -- Modo Layer #, per mesh Vertcount heir_scene = lxq("query sceneservice scene.index ? current")[1] -- Store the index of the source scene. -- Builds Render Scene, and sets it as current scene. render_scene_output = build_render_scene(OutputMode, ordered_ids, root_mesh_id, id_vert_counts) render_scene = lxq("query sceneservice scene.index ? current")[1] -- Store the index of the render scene. mesh_name = lxq("query layerservice layer.name ? first")[1] -- Header Info output( [[ ]] .. "\n") output_asset_tag() output_default_phong() -- Material Instances output(tabs(1) .. "\n") mat_names = {} mat_count = lxq("query layerservice material.N ?")[1] for m=1, mat_count do mat_name = lxq("query layerservice material.name ? " .. m-1)[1] table.insert(mat_names, mat_name) output(tabs(2) .. [[]] .. "\n") output(tabs(3) .. [[]] .. "\n") output(tabs(2) .. "\n") end output(tabs(1) .. "\n") -- Mesh Data output( tabs(1) .. "\n") output( tabs(2) .. [[ ]] ) output( tabs(3) .. "\n") -- --------- Vertex Data --------- renderVerts = getMeshVerts() VertCount = table.getn(renderVerts) merge_tables = getVert_MergeTables_OldNew(renderVerts, UnitScale) merge_table = merge_tables[1] new_vert_table = merge_tables[2] new_VertCount = VertCount if(MergeVerts == true) then new_VertCount = table.getn(new_vert_table) lxout("Merged " .. (VertCount - new_VertCount) .. " Vertices") end output( tabs(4) .. [[]].. "\n") output( tabs(5) .. [[]] .. "\n") for i=1,new_VertCount do if(MergeVerts == true) then temp_vert = renderVerts[new_vert_table[i] ] else temp_vert = renderVerts[i] end output_3f(tabs(6), temp_vert, UnitScale) end output( tabs(5) .. "\n") output( tabs(5) .. "\n") output( tabs(6) .. [[]] .. "\n") output( tabs(7) .. [[]] .. "\n") output( tabs(7) .. [[]] .. "\n") output( tabs(7) .. [[]] .. "\n") output( tabs(6) .. "\n") output( tabs(5) .. "\n") output( tabs(4) .. "\n") -- --------- Face/Vertex Normal Data --------- if(Use_FaceVertNormal == true) then output( tabs(4) .. [[]] .. "\n" ) output( tabs(5) .. [[]] .. "\n" ) for v=1, VertCount do normal_list = lxq("query layerservice vert.normal ? " .. v-1) output_3f(tabs(6), normal_list) end output( tabs(5) .. "\n") output( tabs(5) .. "\n") output( tabs(6) .. [[]] .. "\n") output( tabs(7) .. [[]] .. "\n") output( tabs(7) .. [[]] .. "\n") output( tabs(7) .. [[]] .. "\n") output( tabs(6) .. "\n") output( tabs(5) .. "\n") output( tabs(4) .. "\n") end -- --------- UV Data --------- uv_map_names = {} uv_map_datas = {} polyCount = lxq("query layerservice poly.N ? all")[1] vertex_maps = lxq("query layerservice vmap.N ? all")[1] for vmap=1, vertex_maps do vm_type = lxq("query layerservice vmap.type ? " .. vmap-1)[1] if vm_type == "texture" then vm_name = lxq("query layerservice vmap.name ? " .. vmap-1)[1] if(test_UV_name(vm_name) == true) then table.insert (uv_map_names, vm_name) uv_map_data = {} for m=1, mat_count do cur_mat_name = mat_names[m] for p=1, polyCount do poly_mat = lxq("query layerservice poly.material ? " .. p-1)[1] if(poly_mat == cur_mat_name) then vmap_val = lxq("query layerservice poly.vmapValue ? " .. p-1) for i=1,(table.getn(vmap_val)) do if(math.mod(i,2) == 0) then table.insert (uv_map_data, {vmap_val[i-1],vmap_val[i]}) end end end end end table.insert (uv_map_datas, uv_map_data) end end end for i=1,(table.getn(uv_map_names)) do output( tabs(4) .. [[]] .. "\n") uv_data = uv_map_datas[i] UV_Count = table.getn(uv_data) output( tabs(5) .. [[]] .. "\n") for j=1,(table.getn(uv_data)) do uv_pair = uv_data[j] output( tabs(6) .. fix_float(uv_pair[1]) .. "\t" .. fix_float(uv_pair[2]) .. "\n" ) end output( tabs(5) .. "\n") output( tabs(5) .. "\n") output( tabs(6) .. [[]] .. "\n" ) output( tabs(7) .. [[]] .. "\n") output( tabs(7) .. [[]] .. "\n") output( tabs(6) .. "\n") output( tabs(5) .. "\n") output( tabs(4) .. "\n") end -- --------- Color Data --------- c_map_names = {} color_map_datas = {} polyCount = lxq("query layerservice poly.N ? all")[1] vertex_maps = lxq("query layerservice vmap.N ? all")[1] for vmap=1, vertex_maps do vm_type = lxq("query layerservice vmap.type ? " .. vmap-1)[1] if(vm_type == "rgb") then vm_name = lxq("query layerservice vmap.name ? " .. vmap-1)[1] table.insert (c_map_names, vm_name) color_data = {} for m=1, mat_count do cur_mat_name = mat_names[m] for p=1, polyCount do poly_mat = lxq("query layerservice poly.material ? " .. p-1)[1] if(poly_mat == cur_mat_name) then if test_vertexcolor(vm_name) then -- Get actual vertex color only from the porperly named vmap. vmap_val = lxq("query layerservice poly.vmapValue ? " .. p-1) for i=1,(table.getn(vmap_val)) do if(math.mod(i,3) == 0) then table.insert (color_data, {vmap_val[i-2],vmap_val[i-1],vmap_val[i]}) end end else -- If no properly named vertex map is available then fill the table with 1,1,1. for i=1,(table.getn(vmap_val)) do table.insert (color_data, {1,1,1}) end end end end end table.insert (color_map_datas, color_data) end end for i=1,(table.getn(c_map_names)) do output( tabs(4) .. [[]] .. "\n") color_data = color_map_datas[i] Color_Count = table.getn(color_data) output( tabs(5) .. [[]] .. "\n") for j=1,(table.getn(color_data)) do color_set = color_data[j] output( tabs(6) .. fix_float(color_set[1]) .. "\t" .. fix_float(color_set[2]) .. "\t" .. fix_float(color_set[3]).. "\n" ) end output( tabs(5) .. "\n") output( tabs(5) .. "\n") output( tabs(6) .. [[]] .. "\n" ) output( tabs(7) .. [[]] .. "\n") output( tabs(7) .. [[]] .. "\n") output( tabs(7) .. [[]] .. "\n") output( tabs(6) .. "\n") output( tabs(5) .. "\n") output( tabs(4) .. "\n") end -- --------- Polygon Normal Data --------- if(Use_FaceVertNormal == false) then output_polygon_normal_data(root_mesh_id, mat_names) end -- --------- Vertex Binding --------- output( tabs(4) .. [[]] .. "\n") output( tabs(5) .. [[]] .. "\n") output( tabs(4) .. "\n") -- --------- Polygon Data Header --------- count = 0 for m=1, mat_count do mat_name = mat_names[m] poly_info = getPolygonVerts(mat_name) polygonVerts = poly_info[1] polygonIndexes = poly_info[2] PolyCount = table.getn(polygonVerts) output( tabs(4) .. [[]] .. "\n") output( tabs(5) .. [[]] .. "\n") for i=1,(table.getn(uv_map_names)) do output( tabs(5) .. [[]] .. "\n") end for i=1,(table.getn(c_map_names)) do output( tabs(5) .. [[]] .. "\n") end output( tabs(5) .. [[]] .. "\n") output( tabs(5) .. "") for i=1,(table.getn(polygonVerts)) do vert_list = polygonVerts[i] if(i ~= 1) then output(" ") end output(table.getn(vert_list)) end output("\n") -- --------- Polygon Data --------- output( tabs(5) .. "

\n") for i=1,(table.getn(polygonVerts)) do vert_list = polygonVerts[i] output( tabs(6) ) for j=1,(table.getn(vert_list)) do -- Vertex Data if(MergeVerts == true) then face_vert = vert_list[j] output(merge_table[face_vert +1] -1 .. " ") else output(vert_list[j] .. " ") end -- UV Data for k=1,(table.getn(uv_map_datas)) do output(count .. " ") end -- Color Data for k=1,(table.getn(color_map_datas)) do output(count .. " ") end -- Normal Data if(Use_FaceVertNormal == true) then output(vert_list[j] .. " \t") else output(polygonIndexes[i] .. " \t") end count = count +1 end output("\n") end output( tabs(5) .. "

\n") output( tabs(4) .. "
\n") end output( tabs(3) .. "
\n") output( tabs(2) .. "
\n") -- --------- Convex Hull: Data --------- if(OutputMode == "OBJECT" and convex_id ~= nil) then output( tabs(2) .. [[]] .. "\n") output( tabs(3) .. "\n") lx("select.item [" .. convex_id .. "]") hull_name = lxq("query layerservice layer.name ? first")[1] lxout(hull_name) -- --------- Convex Hull: Vertex Data --------- convexHullVerts = getMeshVerts() --renderLayers) output_vertex_data("Convex_Hull", convexHullVerts, UnitScale) -- --------- Convex Hull: Polygon Data Header --------- polygonVerts = getPolygonVerts()[1] PolyCount = table.getn(polygonVerts) output( tabs(4) .. [[]] .. "\n") output( tabs(5) .. [[]] .. "\n") output( tabs(5) .. "") for i=1,(table.getn(polygonVerts)) do vert_list = polygonVerts[i] if(i ~= 1) then output(" ") end output(table.getn(vert_list)) end output("\n") -- --------- Convex Hull: Polygon Data --------- output( tabs(5) .. "

\n") count = 0 for i=1,(table.getn(polygonVerts)) do vert_list = polygonVerts[i] output( tabs(6) ) for j=1,(table.getn(vert_list)) do output(vert_list[j] .. " ") end output("\n") end output( tabs(5) .. "

\n") output( tabs(4) .. "
\n") output( tabs(3) .. "
\n") output( tabs(2) .. "
\n") end output( tabs(1) .. "
\n") -- --------- Joint and Weight Data --------- if(OutputMode == "RIGID" or OutputMode == "SOFT") then if(OutputMode == "RIGID") then item_count = table.getn(render_layers) elseif(OutputMode == "SOFT") then item_count = table.getn(ordered_ids) -1 end output( tabs(1) .. "\n") output( tabs(2) .. [[]] .. "\n") output( tabs(3) .. [[]] .. "\n") -- --------- Whole Bind Matrix Data --------- output( tabs(4) .. "\n") output( tabs(5) .. "1 0 0 0\n") output( tabs(5) .. "0 1 0 0\n") output( tabs(5) .. "0 0 1 0\n") output( tabs(5) .. "0 0 0 1\n") output( tabs(4) .. "\n") -- --------- Joint Names --------- output( tabs(4) .. [[]] .. "\n") output( tabs(5) .. [[]] .. "\n") output(tabs(6)) if(OutputMode == "RIGID") then for j=1,item_count do output(fix_name(id_names[ render_layers[j] ]) .. " ") end elseif(OutputMode == "SOFT" and table.getn(ordered_ids) > 1) then for j=2,table.getn(ordered_ids) do output(fix_name(id_names[ ordered_ids[j] ]) .. " ") end end output( "\n" .. tabs(5) .. "\n") output( tabs(5) .. "\n") output( tabs(6) .. [[]] .. "\n") output( tabs(7) .. [[]] .. "\n") output( tabs(6) .. "\n") output( tabs(5) .. "\n") output( tabs(4) .. "\n") -- --------- Joint to Skin Bind Matrix --------- output( tabs(4) .. [[]] .. "\n") output( tabs(5) .. [[]] .. "\n") if(OutputMode == "RIGID") then for j=1,item_count do joint_pos = id_pivotpos[render_layers[j] ] output_matrix( tabs(6), joint_pos, UnitScale) if(j ~= item_count) then output("\n") end end elseif(OutputMode == "SOFT") then for j=2,table.getn(ordered_ids) do joint_pos = id_pivotpos[ordered_ids[j] ] output_matrix( tabs(6), joint_pos, UnitScale) if(j ~= item_count) then output("\n") end end end output( tabs(5) .. "\n") output( tabs(5) .. "\n") output( tabs(6) .. [[]] .. "\n") output( tabs(7) .. [[]] .. "\n") output( tabs(6) .. "\n") output( tabs(5) .. "\n") output( tabs(4) .. "\n") -- --------- Weight Data --------- output( tabs(4) .. [[]] .. "\n") if(all_weights == false) then output( tabs(5) .. [[]] .. "\n") output( tabs(6) .. "0\t1\n") else count = 1 output( tabs(5) .. [[]] .. "\n") for i=1,new_VertCount do output( tabs(6) ) if(OutputMode == "RIGID") then for j=1,item_count do if(MergeVerts == true) then vert_joint = vert_layers[new_vert_table[i] ] else vert_joint = vert_layers[i] end if(vert_joint == j) then output("1") else output("0") end if(j == item_count) then output("\n") else output("\t") end end elseif(OutputMode == "SOFT") then for j=2,table.getn(ordered_ids) do item_id = ordered_ids[j] weights = id_soft_weights[item_id] if(MergeVerts == true) then vert_weight = weights[new_vert_table[i] ] else vert_weight = weights[i] end output(fix_float(vert_weight) ) if(j == item_count+1) then output("\n") else output("\t") end end end end end output( tabs(5) .. "\n") output( tabs(5) .. "\n") if(all_weights == true) then output( tabs(6) .. [[]] .. "\n") else output( tabs(6) .. [[]] .. "\n") end output( tabs(7) .. [[]] .. "\n") output( tabs(6) .. "\n") output( tabs(5) .. "\n") output( tabs(4) .. "\n") -- --------- Joint to Bind Matrix --------- output( tabs(4) .. "\n") output( tabs(5) .. [[]] .. "\n") output( tabs(5) .. [[]] .. "\n") output( tabs(4) .. "\n") -- --------- Joint to Weight Data --------- output( tabs(4) .. [[]] .. "\n") output( tabs(5) .. [[]] .. "\n") output( tabs(5) .. [[]] .. "\n") output( tabs(5) .. "") for i=1,new_VertCount do output( item_count .. " ") end output( "\n") output( tabs(5) .. "\n") if(all_weights == false) then for i=1,new_VertCount do output( tabs(6) ) if(OutputMode == "RIGID") then for j=1,item_count do if(MergeVerts == true) then vert_joint = vert_layers[new_vert_table[i] ] else vert_joint = vert_layers[i] end if(vert_joint == j) then output((j-1) .. " 1\t") else output((j-1) .. " 0\t") end end elseif(OutputMode == "SOFT") then for j=2,table.getn(ordered_ids) do item_id = ordered_ids[j] weights = id_soft_weights[item_id] if(MergeVerts == true) then vert_weight = weights[new_vert_table[i] ] else vert_weight = weights[i] end if(vert_weight ~= 0) then output((j-2) .. " 1\t") else output((j-2) .. " 0\t") end end end output("\n") end else count = 0 for i=1,new_VertCount do output( tabs(6) ) for j=1,item_count do output((j-1) .. " " .. count .. "\t") if(j == item_count) then output("\n") else output("\t") end count = count +1 end end end output( tabs(5) .. "\n") output( tabs(4) .. "\n") output( tabs(3) .. "\n") output( tabs(2) .. "\n") output( tabs(1) .. "\n") end -- End of: Joint and Weight Data output( tabs(1) .. "\n") output( tabs(2) .. [[]] .. "\n") lx("scene.set "..heir_scene) lx("select.item [" .. root_mesh_id .. "]") renderLayers = {} if(OutputMode ~= "RIGID") then renderLayers = {root_mesh_id} else renderLayers = {root_mesh_id} end opentabs = 0 -- Joint Node Data if(OutputMode == "RIGID" or OutputMode == "SOFT" ) then if(OutputMode == "RIGID") then for i,v in ipairs(ordered_ids) do next_v = ordered_ids[i+1] if(i == 1) then output( tabs(3+id_tabs[v]) .. [[]] .. "\n" ) else output( tabs(3+id_tabs[v]) .. [[]] .. "\n" ) end mesh_name = lxq("query sceneservice scene.name ? " .. v) --ordered_ids[i])[1] item_pos = lxq("query sceneservice item.pos ? " .. v) pivot_pos = lxq("query sceneservice item.pivPos ? " .. v) joint_pos = add_3f(pivot_pos, item_pos) output_3f_round( (tabs(4+id_tabs[v]) .. [[]]), joint_pos, UnitScale, "\n") output( (tabs(4+id_tabs[v]) .. [[1 0 0 0]]) .. "\n") output( (tabs(4+id_tabs[v]) .. [[0 1 0 0]]) .. "\n") output( (tabs(4+id_tabs[v]) .. [[0 0 1 0]]) .. "\n") if(next_v == nil) then for i=0,(id_tabs[v]) do output( tabs(3+id_tabs[v]-i) .. "\n" ) end else tab_dif = id_tabs[v] - id_tabs[next_v] + 1 for j=1,(tab_dif) do output( tabs(3+id_tabs[v]-j) .. "\n" ) end end end elseif(OutputMode == "SOFT") then for i=2, table.getn(ordered_ids) do v = ordered_ids[i] next_v = ordered_ids[i+1] if(i == 2) then output( tabs(3+id_tabs[v]-1) .. [[]] .. "\n" ) else output( tabs(3+id_tabs[v]-1) .. [[]] .. "\n" ) end mesh_name = lxq("query sceneservice scene.name ? " .. ordered_ids[i])[1] item_pos = lxq("query sceneservice item.pos ? " .. v) item_rot = lxq("query sceneservice item.rot ? " .. v) pivot_pos = lxq("query sceneservice item.pivPos ? " .. v) joint_pos = add_3f(pivot_pos, item_pos) output_3f_round_scaled( (tabs(4+id_tabs[v]-1) .. [[]]), joint_pos, UnitScale, world_scale_list[parent_ids[v] ], "\n") output_3f_rotate( tabs(4+id_tabs[v]-1), item_rot, "
\n") if(next_v == nil) then for i=0,(id_tabs[v]-1) do output( tabs(3+id_tabs[v]-i-1) .. "\n" ) end else tab_dif = id_tabs[v] - id_tabs[next_v] + 1 for j=1,(tab_dif) do output( tabs(3+id_tabs[v]-j) .. "\n" ) end end end end output( tabs(3) .. [[]] .. "\n") output( tabs(4) .. [[]] .. "\n") if(OutputMode == "RIGID") then output( tabs(5) .. "#" .. fix_name(id_names[root_mesh_id]) .."\n") elseif(OutputMode == "SOFT") then output( tabs(5) .. "#" .. fix_name(id_names[ordered_ids[2] ]) .."\n") end output( tabs(5) .. "\n" ) output( tabs(6) .. "\n" ) for m=1, mat_count do mat_name = fix_name(mat_names[m]) output( tabs(7) .. [[]] .. "\n" ) end output( tabs(6) .. "\n" ) output( tabs(5) .. "\n" ) output( tabs(4) .. "\n" ) output( tabs(3) .. "\n" ) end -- Object Node Data if(OutputMode == "OBJECT") then for i,v in ipairs(renderLayers) do next_v = renderLayers[i+1] output( tabs(3+id_tabs[v]) .. [[]] .. "\n" ) mesh_name = lxq("query sceneservice scene.name ? " .. ordered_ids[i])[1] item_pos = lxq("query sceneservice item.pos ? " .. v) output_3f_round( (tabs(4+id_tabs[v]) .. [[]]), item_pos, UnitScale, "\n") output( tabs(4+id_tabs[v]) .. [[]] .. "\n" ) if i == 1 then output( tabs(5+id_tabs[v]) .. "\n" ) output( tabs(6+id_tabs[v]) .. "\n" ) for m=1, mat_count do mat_name = fix_name(mat_names[m]) output( tabs(7+id_tabs[v]) .. [[]] .. "\n" ) end output( tabs(6+id_tabs[v]) .. "\n" ) output( tabs(5+id_tabs[v]) .. "\n" ) end output( tabs(4+id_tabs[v]) .. "\n" ) if(next_v ~= nil and id_tabs[next_v] > id_tabs[v]) then opentabs = opentabs +1 elseif(next_v == nil) then for i=0,(id_tabs[v]) do output( tabs(3+id_tabs[v]-i) .. "\n" ) end else for i=0,(opentabs-1) do output( tabs(3+id_tabs[v]-i) .. "\n" ) end opentabs = 0 end end end output( tabs(2) .. "\n") output( tabs(1) .. "\n") -- --------- Physics Section --------- uses_physics = false physics_models = {} if(OutputMode == "OBJECT" and table.getn(ordered_ids) > 1) then uses_physics = true output_default_physics_material() output( tabs(1) .. "\n") output( tabs(2) .. [[]] .. "\n") shapes_box = 0 shapes_sphere = 0 shapes_convex = 0 for x=2, table.getn(ordered_ids) do name = id_names[ordered_ids[x] ] item_pos = lxq("query sceneservice item.pos ? " .. ordered_ids[x]) item_siz = lxq("query sceneservice item.scale ? " .. ordered_ids[x]) item_rot = lxq("query sceneservice item.rot ? " .. ordered_ids[x]) -- Cube Primitive if(name == "UBX") then shapes_box = shapes_box +1 physics_model_name = "RigidBody-Box-" .. shapes_box table.insert(physics_models, physics_model_name) output(tabs(3) .. [[]] .. "\n") output( tabs(4) .. "\n") output( tabs(5) .. [[]] .. "\n") output( tabs(5) .. "\n") output( tabs(6) .. "\n") output( tabs(7) .. "" .. fix_float(item_siz[1]/2) .. " " .. fix_float(item_siz[2]/2) .. " " .. fix_float(item_siz[3]/2) .. "\n") output( tabs(6) .. "\n") output_3f( (tabs(6) .. ""), item_pos, 1, "\n") output( tabs(6) .. [[1 0 0 ]] .. fix_float(math.deg(item_rot[1]) ) .. "\n") output( tabs(6) .. [[0 1 0 ]] .. fix_float(math.deg(item_rot[2]) ) .. "\n") output( tabs(6) .. [[0 0 1 ]] .. fix_float(math.deg(item_rot[3]) ) .. "\n") output( tabs(5) .. "\n") output( tabs(4) .. "\n") output( tabs(3) .. "\n") -- Sphere Primitive elseif(name == "USP") then shapes_sphere = shapes_sphere +1 physics_model_name = "RigidBody-Sphere-" .. shapes_sphere table.insert(physics_models, physics_model_name) output(tabs(3) .. [[]] .. "\n") output( tabs(4) .. "\n") output( tabs(5) .. [[]] .. "\n") output( tabs(5) .. "\n") output( tabs(6) .. "\n") item_rad = item_siz[1] if(item_siz[2] > item_rad) then item_rad = item_siz[2] end if(item_siz[3] > item_rad) then item_rad = item_siz[3] end output( tabs(7) .. "" .. fix_float(item_rad/2) .. "\n") output( tabs(6) .. "\n") output_3f( (tabs(6) .. ""), item_pos, 1, "\n") output( tabs(5) .. "\n") output( tabs(4) .. "\n") output( tabs(3) .. "\n") -- Convex Hull Primitive elseif(name == "UCX") then shapes_convex = shapes_convex +1 physics_model_name = "RigidBody-ConvexHull-" .. shapes_convex table.insert(physics_models, physics_model_name) output(tabs(3) .. [[]] .. "\n") output( tabs(4) .. "\n") output( tabs(5) .. [[]] .. "\n") output( tabs(5) .. "\n") output( tabs(6) .. "true\n") output( tabs(6) .. [[]] .. "\n") output( tabs(5) .. "\n") output( tabs(4) .. "\n") output( tabs(3) .. "\n") end end output( tabs(2) .. "\n") output( tabs(1) .. "\n") output( tabs(1) .. "\n") output( tabs(2) .. [[]] .. "\n") output( tabs(3) .. [[]] .. "\n") for x=1, table.getn(physics_models) do output( tabs(4) .. [[]] .. "\n") output( tabs(5) .. "\n") output( tabs(5) .. "\n") output( tabs(4) .. "\n") end output( tabs(3) .. "\n") output( tabs(2) .. "\n") output( tabs(1) .. "\n") end output( tabs(1) .. "\n") output( tabs(2) .. [[]] .. "\n") if(uses_physics == true) then output( tabs(2) .. [[]] .. "\n") end output( tabs(1) .. "\n") output( "\n" ) ------------------------------------------------ ------------ Finalize and Cleanup ------------ ------------------------------------------------ -- End early if needed. This will automaticly cleanup everything -- error("Export SUCCESSFULL.") -- Close test scene, and return to original scene lx("scene.set "..render_scene) lx("!!scene.close") lx("scene.set "..heir_scene) -- Return to original selection of root item lx("select.item [" .. root_mesh_id .. "]") -- Dialog output lx("dialog.setup info") lx("dialog.title {Collada Exporter, Mode=" .. OutputMode .. "}") lx("dialog.msg {Export Completed. \nOutput to: " .. Full_FileName .. "}") lx("dialog.open")