• ImportDate


    macroScript ImportGeo category: "HowTo2"
    (
        --从文件中读入某个分割符 后面 的数据
        --FileStream:文件句柄
        --needload :储存读取后的值的变量 (string or value)
        --spliter:分隔符(string)
        --bReadLine: 是否读取分隔符后所有的数据  1表示读取后面所有
        fn LoadData FileStream spliter bReadLine=
        (
            temp=skiptostring FileStream spliter
            if bReadLine==1 then
                needload=readline FileStream
            else
                needload=readvalue FileStream
       
        )
        --***************************************************
        --******************************************************
        --****************************************************
        vert_array = #()
        face_array = #()
        sgroup_array = #()
        matid_array = #()
        edge_array = #()
       
        tm_row1=#()
        tm_row2=#()
        tm_row3=#()
        tm_row4=#()
        nodename=""
        --以下均为material变量
        _Material_Name
        _Material_Type
        _Material_Ambient
        _Material_Diffuse
        _Material_Specular
        _Material_Specular_Lv
        _Material_Glossiness
        _Material_SelfillumColor
        _Material_SelfillumAmount
        _Material_DiffTexPath
        BitmapPath
       
        channel_num
        UVW_Ver_Num
        UVW_Face_Num
        Vert_UV=#()          --所有的顶点的uv都放在这里
        Face_UV=#()          --所有的面的uv都放在这里
        Vert_UV_Size=#()  --用于记录每个channel的顶点的uv总数
        Face_UV_Size=#()  --用语及了每个channel的面uv总数

        in_name=getopenfilename()
        if in_name!=undefined then
        (
            in_file=openfile in_name
            if in_file!=undefined then
            (
                --node name
                temp= readline in_file
                token=filterString temp    " "   
                nodename=(token[token.count] as string)
                --**************************************************
                --material info
                   
                _Material_Name=LoadData in_file  "->" 1
                _Material_Type=LoadData in_file  "->" 1
                _Material_Ambient=LoadData in_file  "->" 0
                _Material_Diffuse=LoadData in_file  "->" 0
                _Material_Specular=LoadData in_file  "->" 0
                _Material_Specular_Lv=LoadData in_file  "->" 0
                _Material_Glossiness=LoadData in_file  "->" 0
                _Material_SelfillumColor=LoadData in_file  "->" 0
                _Material_SelfillumAmount=LoadData in_file  "->" 0
                _Material_DiffTexPath=LoadData in_file  "->" 1
                 --**************************************************

                --node matrix
                --temp= readline in_file
               
                tt=readDelimitedString in_file ":"
                temp=readvalue in_file
                append tm_row1(temp)
               
                tt=readDelimitedString in_file ":"
                temp=readvalue in_file
                append tm_row2(temp)
               
                tt=readDelimitedString in_file ":"
                temp=readvalue in_file
                append tm_row3(temp)
           
                tt=readDelimitedString in_file ":"
                temp=readvalue in_file
                append tm_row4(temp)
               
                --************************************************
                --vertex info
                temp= readline in_file
                token=filterString temp    " "   
                num_vert=token[token.count] as integer
                for i=1 to num_vert do
                (
                    tt=readDelimitedString in_file ":"
                    temp=readvalue in_file
                    append vert_array (temp)
                )
                --************************************************************
                --face info
                temp=readline in_file
                token=filterstring temp " "
                num_face=(token[token.count] as integer)
                for j=1 to num_face do
                (
                    append face_array (readValue in_file)
                    append sgroup_array (readValue in_file)
                    append matid_array (readValue in_file)
                    edge1 = readValue in_file
                    edge2 = readValue in_file
                    edge3 = readValue in_file
                    append edge_array (#(edge1, edge2, edge3))
                   
                )
                 --************************************************************
                --uv info
                -- in max channel begin with 0
                --the channel 0 stores the vertex color info,no uv info
               
                channel_num=LoadData in_file  ":" 0
                for b=1 to (channel_num-1) do
                (
                    --读出Channel id
                    channel_id=LoadData in_file  ":" 0
                   
                    --texture map path
                    BitmapPath=LoadData in_file  "->" 1
                   
                    --读出uv Vertex 的数量
                    temp_size=LoadData in_file ":" 0
                    append Vert_UV_Size temp_size
                   
                    --uv的数据
                    for i=1 to temp_size do
                    (
                        append Vert_UV (readValue in_file)
                    )
                   
                    --uv face的 数量
                    temp_size==LoadData in_file  ":" 0
                    append Face_UV_Size temp_size
                   
                    for i=1 to temp_size do
                    (
                        append Face_uv (readValue in_file)
                    )
                   
                )
            )
            close in_file
           
        )
        meditmaterials[1].ambient=_Material_Ambient
        meditmaterials[1].diffuse=_Material_Diffuse
        meditmaterials[1].shaderbyname=_Material_type
        meditmaterials[1].specular=_material_specular
        meditmaterials[1].specularlevel=_material_specular_lv
        meditmaterials[1].glossiness=_material_glossiness
        meditmaterials[1].selfillumcolor=_Material_SelfillumColor
        meditmaterials[1].selfillumamount=_Material_SelfillumAmount
        meditmaterials[1].diffuseMapEnable=true
        bmp =bitmaptexture filename: _Material_DiffTexPath
        meditmaterials[1].diffusemap=bmp

        new_mesh = mesh vertices:vert_array faces:face_array --materialIDs:#(0,1) tverts:vert_uv
        for f = 1 to num_face do
        (
            setFaceSmoothGroup new_mesh f sgroup_array[f]
            setFaceMatID new_mesh f matid_array[f]
            setEdgeVis new_mesh f 1 edge_array[f][1]
            setEdgeVis new_mesh f 2 edge_array[f][2]
            setEdgeVis new_mesh f 3 edge_array[f][3]
        )
        myTransform = new_mesh.transform
        new_mesh.transform.row1 = tm_row1[1]
        new_mesh.transform.row2 = tm_row2[1]
        new_mesh.transform.row3 = tm_row3[1]
        new_mesh.transform.row4 = tm_row4[1]

        new_mesh.name=(nodename as string)
       
        new_mesh.material=meditmaterials[1]
           
        meshop.setMapSupport new_mesh 0 true
        meshop.setMapSupport new_mesh 1 true
       
        --set vertex uv for every vertex
        meshop.setNumMapVerts new_mesh 1 Vert_UV_Size[1] keep:false
        for i=1 to Vert_UV_Size[1] do
        (
            meshop.setMapVert new_mesh 1 i Vert_UV[i]
        )
       
        --set face uv for every face
        meshop.setnummapfaces new_mesh 1 Face_UV_Size[1] keep:false
        for i=1 to Face_UV_Size[1] do
        (
            meshop.setMapFace new_mesh 1 i Face_UV[i]
        )

        update new_mesh
       
    )

  • 相关阅读:
    DDD 领域驱动设计
    IOC 控制反转
    WCF
    Lucene 全文检索引擎
    Redis
    Cache 缓存
    return
    PHP中empty();和isset();的区别.
    sql 简单用语
    关系型数据库
  • 原文地址:https://www.cnblogs.com/softimagewht/p/1783815.html
Copyright © 2020-2023  润新知