-- lua --------------------------------- -- Weight to UV converter v0.5 -- --------------------------------- -- AUTHOR: Zoltan Erdokovy (zoltan.erdokovy@gmail.com) -- -- USAGE: At the moment the script copies weight values from a hardwired weightmap -- to a UV set of an also hardwired name. (The names can be changed bellow.) -- Weights go to the U axis, so by using a horizontal grayscale gradient, you can -- emulate a "weight map texture". -- SourceWeightName = "_SourceWeight" TargetUVName = "_TargetUV" SourceWeightMapExist = false SourceWeightMapIndex = nil TargetUVExist = false TargetUVIndex = nil -- -- -- GETPOINTWEIGHT -- -- -- function GetPointWeight (PointIndex) p = nil ActVmapType = lxq("query layerservice vmap.type ? "..SourceWeightMapIndex)[1] ActVmapName = lxq("query layerservice vmap.name ? "..SourceWeightMapIndex)[1] p = lxq("query layerservice vert.vmapValue ? "..PointIndex) if p ~= nil then p = p[1] else p = 0 end return (p) end -- -- -- SETPOINTUV -- -- -- function SetPointUV (PointIndex, value) lx("vertMap.setVertex "..TargetUVName.." texture 0 "..PointIndex.." "..value) end -- -- -- SELECTLAYER -- -- -- function SelectLayer (LayerIndex) lx("select.layer "..LayerIndex.." set") lxq("query layerservice layer.name ? "..LayerIndex) end -- -- -- MAIN -- -- -- MainLayer = lxq("query layerservice layer.index ? fg")[1] SelectLayer (MainLayer) Vertices = lxq("query layerservice verts ? all") -- Getting the list of vertices. VertexNum = table.getn(Vertices) --- Check for required vertex maps. --- lxq("query layerservice vmap_groups ? all") for i = 0, (lxq("query layerservice vmap.n ? all")[1])-1 do ActVmapType = lxq("query layerservice vmap.type ? "..i)[1] ActVmapName = lxq("query layerservice vmap.name ? "..i)[1] if (ActVmapType == "weight") and (ActVmapName == SourceWeightName) then SourceWeightMapExist = true SourceWeightMapIndex = i elseif (ActVmapType == "texture") and (ActVmapName == TargetUVName) then TargetUVExist = true TargetUVIndex = i end end if (SourceWeightMapExist and TargetUVExist) then --- Copy weights to UV "U" values. --- for j = 0, (VertexNum-1) do -- Iterating through the vertices. ActPointWeight = GetPointWeight(j,WeightMapName) if ActPointWeight ~= nil then SetPointUV(j,ActPointWeight) end end else lxout("ERROR: Required vertexmaps not found.") end