1. Пользоваться форумом на планшетах и телефонах стало удобнее благодаря Tapatalk

Экспорт точек веса, в текстовом формате (помогите)

Тема в разделе "MAXScript", создана пользователем ОА, 27 май 2012.

Модераторы: Savin Denis
  1. ОА

    ОА Активный участник

    С нами с:
    15.03.2012
    Сообщения:
    28
    Симпатии:
    0
    Баллы:
    12
    Здравствуйте, товарищи.
    Прошу помощи, в решении следующего вопроса.

    Есть модель (человека), с костями и модификатором skin, проблема в экспорте данных. Нужно получить текстовый файл, с индексом точки и его веса к кости. 100% аналог Weight Table в модификаторе skin только в тексте.

    Если кто то знает как это сделать, прошу помочь.

    С уважением, Олег.
     

    Вложения:

    • 2732427.jpg
      2732427.jpg
      Размер файла:
      258,7 КБ
      Просмотров:
      83
  2. ОА

    ОА Активный участник

    С нами с:
    15.03.2012
    Сообщения:
    28
    Симпатии:
    0
    Баллы:
    12
    хелп, сос, аухтунг
     
  3. Savin Denis vip

    Savin Denis Moderator Команда форума

    С нами с:
    05.05.2005
    Сообщения:
    1.633
    Симпатии:
    0
    Баллы:
    210

    Код:
    -- Written by Sean Soh @ April 2007--
    -- Tiny Island Productions --
    rollout SkinToolRollout "Skin Tools" width:160 height:315
    (
    groupBox grpImpSkin "Import Skin" pos:[0,0] width:160 height:100
    label lblImpFile "File:" pos:[10,25] width:30 height:15
    button btnImpSKF "Pick Import SkinFile" pos:[40,20] width:110 height:20
    checkbox chkVertex "Load By Vertex ID" pos:[20,45] width:130 height:15
    button btnImport "Import!!!" pos:[10,70] width:140 height:20
    
    groupBox grpExpSkin "Export Skin" pos:[0,100] width:160 height:215
    multilistBox mlbExpBones "Bones:" pos:[5,120] width:150 height:8
    button btnExpBoneList "Get Bone List" pos:[70,115] width:80 height:20
    label lblExpFile "File:" pos:[10,260] width:30 height:15
    button btnExpSKF "Pick Export SkinFile" pos:[40,255] width:110 height:20
    button btnExport "Export!!!" pos:[10,280] width:140 height:20
    
    on btnImpSKF pressed do
    (
    btnImpSKF.caption = getOpenFileName caption:"Export Skin Files" types:"Skin Files (*.skf)|*.skf|All Files (*.*)|*.*|"
    )
    
    on btnImport pressed do
    (
    input_name = btnImpSKF.caption
    in_file = openFile input_name
    if in_file != undefined then
    (
    -- loading the bone name, original Bone ID etc
    if ((readDelimitedString in_file ":") == "B") then
    (
    numImpBones = (readDelimitedString in_file ":") as Integer
    tempBoneID = readDelimitedString in_file ";"
    tempBoneName = readDelimitedString in_file "\n"
    
    oBoneIDArray = filterString tempBoneID ","
    oBoneNameArray = filterString tempBoneName ","
    )
    -- Construct the new bone ID mapping array
    numBones = skinOps.GetNumberBones $.modifiers[#Skin]
    modPanel.setCurrentObject $.modifiers[#Skin]
    nBoneIDArray = #()
    
    for x = 1 to oBoneIDArray.count do
    (
    oBoneIDArray[x] = oBoneIDArray[x] as Integer
    for y = 1 to numBones do
    (
    nBoneName = skinOps.GetBoneName $.modifiers[#Skin] y 1
    if (nBoneName == oBoneNameArray[x]) then
    (
    nBoneIDArray = append nBoneIDArray y
    exit
    )
    )
    )
    -- loading vertex skinning info
    while not eof in_file do
    (
    vID = (readDelimitedString in_file ":") as Integer
    vBoneCount = (readDelimitedString in_file ":") as Integer
    vWeighting = readDelimitedString in_file "\n"
    
    tempBoneIDArray = #()
    tempBoneWeightArray = #()
    temptotalweight = 0.0
    tempVertexWeight = filterString vWeighting ",;"
    
    -- construct temp array for holding vertex skinning data in new skin
    for x = 1 to vBoneCount do
    (
    print tempVertexWeight[x]
    oBoneID = tempVertexWeight[x * 2 - 1] as Integer
    oBoneWeight = tempVertexWeight[x * 2] as Float
    
    nBoneIDInd = finditem oBoneIDArray oBoneID
    tempBoneIDArray = append tempBoneIDArray nBoneIDArray[nBoneIDInd]
    tempBoneWeightArray = append tempBoneWeightArray oBoneWeight
    temptotalweight += oBoneWeight
    )
    
    -- load in the current vertex weighting
    cBoneCount = skinOps.GetVertexWeightCount $.modifiers[#Skin] vID
    
    cBoneIDArray = #()
    cBoneWeightArray = #()
    ctemptotalweight = 0
    
    -- construct the retained weight part
    for x = 1 to cBoneCount do
    (
    cBoneID = skinOps.GetVertexWeightBoneID $.modifiers[#Skin] vID x
    if ((findItem tempBoneIDArray cBoneID) == 0) then
    (
    cBoneIDArray = append cBoneIDArray cBoneID
    cBoneWeight = skinOps.GetVertexWeight $.modifiers[#Skin] vID x
    cBoneWeightArray = append cBoneWeightArray cBoneWeight
    ctemptotalweight += cBoneWeight
    )
    )
    
    -- readjust the weighting
    for x = 1 to cBoneIDArray.count do
    (
    cBoneWeightArray[x] = (cBoneWeightArray[x] / ctemptotalweight) * (1 - temptotalweight)
    )
    -- joint the array
    newBoneIDArray = cBoneIDArray + tempBoneIDArray
    newBoneWeightArray = cBoneWeightArray + tempBoneWeightArray
    
    -- finally set weight!!!
    skinOps.ReplaceVertexWeights $.modifiers[#Skin] vID newBoneIDArray newBoneWeightArray
    )
    )
    )
    on btnExpBoneList pressed do
    (
    modPanel.setCurrentObject $.modifiers[#Skin]
    numBones = skinOps.GetNumberBones $.modifiers[#Skin]
    for y = 1 to numBones do
    (
    tempBoneName = skinOps.GetBoneName $.modifiers[#Skin] y 1
    mlbExpBones.items = append mlbExpBones.items tempBoneName
    )
    modPanel.setCurrentObject $.modifiers[1]
    )
    
    on btnExpSKF pressed do
    (
    btnExpSKF.caption = getSaveFileName caption:"Export Skin Files" types:"Skin Files (*.skf)|*.skf|All Files (*.*)|*.*|"
    )
    
    on btnExport pressed do
    (
    output_name = btnExpSKF.caption
    modPanel.setCurrentObject $.modifiers[#Skin]
    
    if output_name != undefined then
    (
    output_file = createfile output_name
    numBones = mlbExpBones.selection.count
    numExpBones = mlbExpBones.selection.numberset
    numVerts = skinOps.GetNumberVertices $.modifiers[#Skin]
    selVerts = #()
    selBones = #()
    selBonesName = #()
    
    -- create vertex collection flag array
    selVerts.count = numVerts
    
    -- cycle thru the system bones list, construct Verts list
    for x = 1 to numBones do
    (
    -- if this bone is being selected for export
    if mlbExpBones.selection[x] == true then
    (
    -- record the selected bone ID & name
    append selBones x
    append selBonesName mlbExpBones.items[x]
    
    -- select the bone, and the affected vertice that's gonna export out
    skinOps.selectBone $.modifiers[#Skin] x
    skinOps.selectVerticesByBone $.modifiers[#Skin]
    
    -- go thru the vertices see if they are selected, and marked them to export later on
    for y in 1 to numVerts do
    (
    if (skinOps.IsVertexSelected $.modifiers[#Skin] y) == 1 then
    (
    selVerts[y] = 1
    )
    )
    )
    )
    format "B:%:" numExpBones to:output_file
    for x = 1 to numExpBones do
    (
    format "%," selBones[x] to:output_file
    )
    format ";" to:output_file
    for x = 1 to numExpBones do
    (
    format "%," selBonesName[x] to:output_file
    )
    format "\n" to:output_file
    for x = 1 to numVerts do
    (
    if selVerts[x] == 1 then
    (
    selBoneCount = skinOps.GetVertexWeightCount $.modifiers[#Skin] x
    ExpBoneCount = 0
    selBoneString = ""
    
    for y = 1 to selBoneCount do
    (
    selBoneID = skinOps.GetVertexWeightBoneID $.modifiers[#Skin] x y
    selBoneWeight = skinOps.GetVertexWeight $.modifiers[#Skin] x y
    
    if ((findItem selBones selBoneID) > 0) then
    (
    ExpBoneCount += 1
    selBoneString = selBoneString + (selBoneID as String) + "," + (selBoneWeight as String) + ";"
    )
    )
    format "%:%:" x ExpBoneCount to:output_file
    format "%" selBoneString to:output_file
    format "\n" to:output_file
    )
    )
    close output_file
    edit output_name
    )
    )
    )
    SKF_Floater = newRolloutFloater "Tiny Skin Tools" 180 345
    addRollout SkinToolRollout SKF_Floater
     
  4. Фигли

    Фигли Пользователь сайта

    С нами с:
    20.01.2012
    Сообщения:
    23
    Симпатии:
    0
    Баллы:
    2
    Код:
    max modify mode
    skinOps.saveEnvelopeAsASCII $.modifiers[#Skin] 	"C:\\tmp.txt"
    Меш должен быть выделен. Если в сцене больше одного меша, дописать циклы не проблема.
    И все дела :0)
     
Модераторы: Savin Denis

Поделиться этой страницей