<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: FBX SDK is creating a new mat/texture pair for every mesh??!! in FBX Forum</title>
    <link>https://forums.autodesk.com/t5/fbx-forum/fbx-sdk-is-creating-a-new-mat-texture-pair-for-every-mesh/m-p/5859741#M2342</link>
    <description>&lt;P&gt;Materials are associated with nodes so to reuse them I think you'd need to have all the meshes associated with the same node as the material.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone else confirm this?&lt;/P&gt;</description>
    <pubDate>Tue, 13 Oct 2015 18:02:33 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2015-10-13T18:02:33Z</dc:date>
    <item>
      <title>FBX SDK is creating a new mat/texture pair for every mesh??!!</title>
      <link>https://forums.autodesk.com/t5/fbx-forum/fbx-sdk-is-creating-a-new-mat-texture-pair-for-every-mesh/m-p/5859470#M2341</link>
      <description>&lt;P&gt;Where are the Examples on how to do this correctly?????:?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have spent the last 5 hours searching&amp;nbsp;every part of the Internet&amp;nbsp;to find a clear example of sharing materials and textures with multiple&amp;nbsp;meshes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I export using the FBX SDK&amp;nbsp;It's creating a new material and texture for every single mesh.&lt;/P&gt;&lt;P&gt;379 meshes sections = 379 materials&amp;nbsp;and 379 textures (as shown in the FBX Importer in 3DS)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;File Axis Direction: Y-up&lt;BR /&gt;File Units: Centimeters&lt;BR /&gt;System Axis Direction: Z-up&lt;BR /&gt;System Units: Inches&lt;BR /&gt;System frame rate: 30.0&lt;BR /&gt;File frame rate: 30.0&lt;BR /&gt;File content: 379 Elements, 379 Materials, 379 Textures&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can some one PLEASE put some code up that shows the correct way to create ONLY the textures and materials ONCE for each pair&amp;nbsp;in the scene and bind them to the meshes that uses these?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2015 16:22:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fbx-forum/fbx-sdk-is-creating-a-new-mat-texture-pair-for-every-mesh/m-p/5859470#M2341</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-10-13T16:22:23Z</dc:date>
    </item>
    <item>
      <title>Re: FBX SDK is creating a new mat/texture pair for every mesh??!!</title>
      <link>https://forums.autodesk.com/t5/fbx-forum/fbx-sdk-is-creating-a-new-mat-texture-pair-for-every-mesh/m-p/5859741#M2342</link>
      <description>&lt;P&gt;Materials are associated with nodes so to reuse them I think you'd need to have all the meshes associated with the same node as the material.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone else confirm this?&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2015 18:02:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fbx-forum/fbx-sdk-is-creating-a-new-mat-texture-pair-for-every-mesh/m-p/5859741#M2342</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-10-13T18:02:33Z</dc:date>
    </item>
    <item>
      <title>Re: FBX SDK is creating a new mat/texture pair for every mesh??!!</title>
      <link>https://forums.autodesk.com/t5/fbx-forum/fbx-sdk-is-creating-a-new-mat-texture-pair-for-every-mesh/m-p/5859941#M2343</link>
      <description>&lt;P&gt;Thanks for answering &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code Im using... all of it..&amp;nbsp;&lt;/P&gt;&lt;P&gt;It works other than it's creating many MANY materials and textures.&lt;/P&gt;&lt;P&gt;Its VB.net using Skill.FbxSDK wrapper. (I posted a link to this wrapper else where in the forums)&lt;/P&gt;&lt;P&gt;Its wrapped around&amp;nbsp;version 2009 of the SDK&lt;/P&gt;&lt;PRE&gt;    Public Sub export_fbx()
        'exports FBX   DUH
        Dim mat_main As String = ""
        Dim fbx_location As String = frmMain.SaveFileDialog1.FileName

        '--------------------------------------------------------------------------
        'create manager and scene
        Dim pManager As FbxSdkManager
        Dim scene As FbxScene
        pManager = FbxSdkManager.Create
        scene = FbxScene.Create(pManager, "My Scene")
        Dim rootNode As Skill.FbxSDK.FbxNode
        Dim node_list() = {FbxNode.Create(pManager, "anyName")}
        For id = 0 To Mesh_Count - 1
            ReDim Preserve node_list(id + 1)
            If Not visiblility_list(data(id).part_id) Then
                GoTo we_dont_want_this_one_saved
            End If
            'this will change?
            Dim model_name = "part_" + id.ToString("000")


            mat_main = texture_list(data(id).GL_texture_Id - 1).path

            node_list(id) = FbxNode.Create(pManager, model_name)

            'create mesh node
            Dim mymesh = fbx_create_mesh(model_name, id, pManager)

            rootNode = scene.RootNode
            Dim lMaterial As FbxSurfacePhong
            Dim m_name As String = "Material"
            Dim s_name As String = "Phong"
            Dim black = New FbxDouble3(0.0, 0.0, 0.0)
            Dim light = New FbxDouble3(0.9, 0.9, 0.9)
            Dim light2 = New FbxDouble3(0.7, 0.7, 0.7)
            Dim color As New FbxDouble3(0.8, 0.8, 0.8)
            Dim r_vector As New FbxVector4(0.0, 0.0, 0.0, 0.0)
            Dim t_vector As New FbxVector4(0.0, 0.0, 0.0)
            Dim s_vector As New FbxVector4(1.0, 1.0, 1.0, 0.0)

            node_list(id).NodeAttribute = mymesh
            node_list(id).SetDefaultR(r_vector)
            node_list(id).SetDefaultT(t_vector)
            node_list(id).SetDefaultS(s_vector)
            If node_list(id).IsValid Then
                lMaterial = FbxSurfacePhong.Create(mymesh, m_name + ":" + id.ToString)
                lMaterial.EmissiveColor = black
                lMaterial.AmbientColor = light
                lMaterial.DiffuseColor = color
                lMaterial.SpecularColor = light2
                lMaterial.SpecularFactor = 0.3
                lMaterial.TransparencyFactor = 0.0
                lMaterial.Shininess = 60.0
                lMaterial.ShadingModel = s_name
                CreateTexture(pManager, mymesh, id, lMaterial)   ' get and bind out textures
                node_list(id).AddMaterial(lMaterial)
                '---------------------------------------
                node_list(id).ConnectSrcObject(lMaterial, FbxConnectionType.ConnectionDefault)
            End If
            node_list(id).Shading_Mode = FbxNode.ShadingMode.TextureShading
            rootNode.AddChild(node_list(id))
            rootNode.ConnectSrcObject(node_list(id), FbxConnectionType.ConnectionDefault)

we_dont_want_this_one_saved:
        Next 'Id

        scene.SetCurrentTake("One Take")
        'time to save...
        Dim exporter As Skill.FbxSDK.IO.FbxExporter = Skill.FbxSDK.IO.FbxExporter.Create(pManager, "")
        If Not exporter.Initialize(frmMain.SaveFileDialog1.FileName) Then
            MsgBox("fbx unable to initialize exporter!", MsgBoxStyle.Exclamation, "FBX Error..")
            frmMain.Timer1.Enabled = True
            GoTo outahere
        End If
        Dim version As Version = Skill.FbxSDK.IO.FbxIO.CurrentVersion
        Console.Write(String.Format("FBX version number for this FBX SDK is {0}.{1}.{2}", _
                          version.Major, version.Minor, version.Revision))

        exporter.FileFormat = IO.FileFormat.FbxAscii

        Dim exportOptions As Skill.FbxSDK.IO.FbxStreamOptionsFbxWriter _
                = Skill.FbxSDK.IO.FbxStreamOptionsFbxWriter.Create(pManager, "")
        If pManager.IOPluginRegistry.WriterIsFBX(IO.FileFormat.FbxAscii) Then

            ' Export options determine what kind of data is to be imported.
            ' The default (except for the option eEXPORT_TEXTURE_AS_EMBEDDED)
            ' is true, but here we set the options explictly.
            exportOptions.SetOption(Skill.FbxSDK.IO.FbxStreamOptionsFbx.MATERIAL, True)
            exportOptions.SetOption(Skill.FbxSDK.IO.FbxStreamOptionsFbx.TEXTURE, True)
            exportOptions.SetOption(Skill.FbxSDK.IO.FbxStreamOptionsFbx.EMBEDDED, False)
            exportOptions.SetOption(Skill.FbxSDK.IO.FbxStreamOptionsFbx.LINK, True)
            exportOptions.SetOption(Skill.FbxSDK.IO.FbxStreamOptionsFbx.SHAPE, False)
            exportOptions.SetOption(Skill.FbxSDK.IO.FbxStreamOptionsFbx.GOBO, False)
            exportOptions.SetOption(Skill.FbxSDK.IO.FbxStreamOptionsFbx.ANIMATION, False)
            exportOptions.SetOption(Skill.FbxSDK.IO.FbxStreamOptionsFbx.GLOBAL_SETTINGS, False)
            exportOptions.SetOption(Skill.FbxSDK.IO.FbxStreamOptionsFbx.MEDIA, False)
        End If
        Dim status = exporter.Export(scene, exportOptions)
        exporter.Destroy()
        pManager.Destroy()
outahere:
    End Sub&lt;/PRE&gt;&lt;PRE&gt;    Public Function fbx_create_mesh(model_name As String, id As Integer, pManager As FbxSdkManager) As FbxMesh
        Dim myMesh As FbxMesh
        myMesh = FbxMesh.Create(pManager, model_name)
        Dim v As vec3
        Dim v_2 As New FbxVector2
        Dim v4 As New FbxVector4
        Dim I As Integer

        'first we load all the vertices for the triangles data
        myMesh.InitControlPoints(triangles(id).vert_cnt) ' size of array
        'add in the vertices (or control points as its called in FBX)
        Dim cp_array(myMesh.ControlPointsCount - 1) As FbxVector4
        For I = 0 To myMesh.ControlPointsCount - 1
            cp_array(I) = New FbxVector4
            cp_array(I).X = triangles(id).vertices(I).x
            cp_array(I).Y = triangles(id).vertices(I).y
            cp_array(I).Z = triangles(id).vertices(I).z
        Next
        myMesh.ControlPoints = cp_array ' push it in to the mesh object
        'create or get the layer 0
        Dim layer As FbxLayer = myMesh.GetLayer(0)
        If layer Is Nothing Then
            myMesh.CreateLayer()
            layer = myMesh.GetLayer(0)
        End If

        'normals.. seems to be working ok
        Dim layerElementNormal = FbxLayerElementNormal.Create(myMesh, "Normals")
        layerElementNormal.Mapping_Mode = FbxLayerElement.MappingMode.ByPolygonVertex
        layerElementNormal.Reference_Mode = FbxLayerElement.ReferenceMode.Direct
        'time to assign the normals to each control point.
        'OK.. I have to reverse the winding order be cause 3DS dont like it the way it is
        For I = 0 To (triangles(id).indi_cnt - 1) Step 3
            Dim v3 = triangles(id).indices(I)
            Dim v2 = triangles(id).indices(I + 1)
            Dim v1 = triangles(id).indices(I + 2)
            v = triangles(id).norm(v1)
            v4.X = v.x
            v4.Y = v.y
            v4.Z = v.z
            layerElementNormal.DirectArray.Add(v4)

            v = triangles(id).norm(v2)
            v4.X = v.x
            v4.Y = v.y
            v4.Z = v.z
            layerElementNormal.DirectArray.Add(v4)

            v = triangles(id).norm(v3)
            v4.X = v.x
            v4.Y = v.y
            v4.Z = v.z
            layerElementNormal.DirectArray.Add(v4)
        Next

        '--------------------------------------------------------------------------
        ' Create UV for Diffuse channel
        layer.Normals = layerElementNormal
        Dim UVDiffuseLayer As FbxLayerElementUV = FbxLayerElementUV.Create(myMesh, "DiffuseUV")
        UVDiffuseLayer.Mapping_Mode = FbxLayerElement.MappingMode.ByControlPoint
        UVDiffuseLayer.Reference_Mode = FbxLayerElement.ReferenceMode.Direct
        layer.SetUVs(UVDiffuseLayer, FbxLayerElement.LayerElementType.DiffuseTextures)

        For I = 0 To myMesh.ControlPointsCount - 1
            If frmMain.m_U_Save_Flip.CheckState Then
                v_2.X = triangles(id).uv(I).u * -1
            Else
                v_2.X = triangles(id).uv(I).u
            End If

            If frmMain.m_V_Save_Flip.CheckState Then
                v_2.Y = triangles(id).uv(I).v * -1
            Else
                v_2.Y = triangles(id).uv(I).v
            End If
            UVDiffuseLayer.DirectArray.Add(v_2)
        Next

        '---------------------------------------------------------------------------

        'we should have indi_cnt-1 / 3 triangles
        Dim pos As UInt32 = 0
        Dim n As UInt32 = 0
        Dim j As UInt32 = 0
        For I = 0 To (triangles(id).indi_cnt - 1) Step 3
            myMesh.BeginPolygon(-1, -1, -1, False)

            j = 0
            pos = triangles(id).indices(n + 2)
            myMesh.AddPolygon(pos)
            UVDiffuseLayer.IndexArray.SetAt(pos, j)
            j += 1
            pos = triangles(id).indices(n + 1)
            myMesh.AddPolygon(pos)
            UVDiffuseLayer.IndexArray.SetAt(pos, j)
            j += 1
            pos = triangles(id).indices(n)
            myMesh.AddPolygon(pos)
            UVDiffuseLayer.IndexArray.SetAt(pos, j)
            n += 3
            myMesh.EndPolygon()

        Next
        Return myMesh
    End Function&lt;/PRE&gt;&lt;PRE&gt;    Private Sub CreateTexture(ByVal pManager As FbxSdkManager, ByVal mesh As FbxMesh, _
                              ByVal id As UInt32, ByRef lMaterial As FbxSurfacePhong)
        'note byref in def block
        Dim texture As FbxTexture
        Dim layercontainer As FbxLayerContainer = mesh


        texture = FbxTexture.Create(pManager, "DiffuseMap" + ":" + id.ToString("000"))
        ' Set texture properties.
        texture.SetFileName(texture_list(data(id).GL_texture_Id - 1).path) 'Get the Texture path from the list
        texture.TextureUseType = FbxTexture.TextureUse.Standard
        texture.Mapping = FbxTexture.MappingType.Uv
        texture.MaterialUseType = FbxTexture.MaterialUse.Model
        texture.SwapUV = False
        texture.SetTranslation(0.0, 0.0)
        texture.SetScale(1.0, 1.0)
        texture.SetRotation(0.0, 0.0)
        Dim layerElementTexture As FbxLayerElementTexture = layercontainer.GetLayer(0).DiffuseTextures
        If layerElementTexture Is Nothing Then
            layerElementTexture = FbxLayerElementTexture.Create(layercontainer, "normalMap")
            layercontainer.GetLayer(0).DiffuseTextures = layerElementTexture
        End If
        layerElementTexture.Blend_Mode = FbxLayerElementTexture.BlendMode.Translucent
        layerElementTexture.Alpha = 1.0
        layerElementTexture.Mapping_Mode = FbxLayerElement.MappingMode.AllSame
        layerElementTexture.Reference_Mode = FbxLayerElement.ReferenceMode.Direct
        layerElementTexture.DirectArray.Add(texture)
        layerElementTexture.Dispose()
        layercontainer.Dispose()

    End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2015 19:28:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fbx-forum/fbx-sdk-is-creating-a-new-mat-texture-pair-for-every-mesh/m-p/5859941#M2343</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-10-13T19:28:17Z</dc:date>
    </item>
    <item>
      <title>Re: FBX SDK is creating a new mat/texture pair for every mesh??!!</title>
      <link>https://forums.autodesk.com/t5/fbx-forum/fbx-sdk-is-creating-a-new-mat-texture-pair-for-every-mesh/m-p/5861873#M2344</link>
      <description>&lt;P&gt;I figured this out..&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code to export using the wrapper and VB.net (2012)&lt;/P&gt;&lt;P&gt;It is important to created the arrays exactly as in the&amp;nbsp;code below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I cleaned up the code and added some comments to explain this thing better.&lt;/P&gt;&lt;PRE&gt;   Public Sub export_fbx()
        'exports FBX   DUH
        Dim fbx_location As String = frmMain.SaveFileDialog1.FileName

        '--------------------------------------------------------------------------
        'create manager and scene
        Dim pManager As FbxSdkManager
        Dim scene As FbxScene
        pManager = FbxSdkManager.Create
        scene = FbxScene.Create(pManager, "My Scene")
        Dim rootNode As Skill.FbxSDK.FbxNode
        Dim node_list() = {FbxNode.Create(pManager, "anyName")}

        Dim r_vector As New FbxVector4(0.0, 0.0, 0.0, 0.0)
        Dim t_vector As New FbxVector4(0.0, 0.0, 0.0)
        Dim s_vector As New FbxVector4(1.0, 1.0, 1.0, 0.0)

        'create the material and texture arrays.
        Dim lMaterials(texture_count) As FbxSurfacePhong
        Dim lTextures(texture_count) As FbxTexture
        'make the materials
        For i = 0 To texture_count - 1
            lMaterials(i) = fbx_create_material(pManager, i)
        Next
        'make the textures
        For i = 0 To texture_count - 1
            lTextures(i) = fbx_create_texture(pManager, i)
        Next

        rootNode = scene.RootNode ' need this so we can add our elements to it
        For id = 0 To Mesh_Count - 1 ' mesh count is my total pieces in this mesh.. around 300-400 per model
            ReDim Preserve node_list(id + 1)
            If Not visiblility_list(data(id).part_id) Then
                GoTo we_dont_want_this_one_saved
            End If
            Dim model_name = "part_" + id.ToString("000") ' create a name for this part

            node_list(id) = FbxNode.Create(pManager, model_name) ' create a new node in the array. With out this array it don't seem to work

            'create mesh node from my data stuctures
            Dim mymesh = fbx_create_mesh(model_name, id, pManager)
            'Need a layercontainer to put the texture in.
            Dim layercontainer As FbxLayerContainer = mymesh
            Dim layerElementTexture As FbxLayerElementTexture = layercontainer.GetLayer(0).DiffuseTextures
            If layerElementTexture Is Nothing Then
                layerElementTexture = FbxLayerElementTexture.Create(layercontainer, "diffuseMap")
                layercontainer.GetLayer(0).DiffuseTextures = layerElementTexture
            End If
            'not 100% sure about the translucent but it isn't breaking anything.
            layerElementTexture.Blend_Mode = FbxLayerElementTexture.BlendMode.Translucent
            layerElementTexture.Alpha = 1.0
            layerElementTexture.Mapping_Mode = FbxLayerElement.MappingMode.AllSame
            layerElementTexture.Reference_Mode = FbxLayerElement.ReferenceMode.Direct

            'add the texture from the texture array using the Texture ID for this mesh section
            layerElementTexture.DirectArray.Add(lTextures(data(id).GL_texture_Id - 1))

            node_list(id).NodeAttribute = mymesh
            node_list(id).SetDefaultR(r_vector)
            node_list(id).SetDefaultT(t_vector)
            node_list(id).SetDefaultS(s_vector)
            If node_list(id).IsValid Then ' useless test but Im leaving it.
                'add the texture from the array using this models texture ID
                node_list(id).AddMaterial(lMaterials(data(id).GL_texture_Id - 1))
                '---------------------------------------
                'If we dont connect this texture to this node, it will never show up!
                node_list(id).ConnectSrcObject(lMaterials(data(id).GL_texture_Id - 1), FbxConnectionType.ConnectionDefault)
            End If
            node_list(id).Shading_Mode = FbxNode.ShadingMode.TextureShading ' not even sure this is needed but what ever.

            'now that everyhing is added to the current node in the array,
            'its time to add this to the root node of the scene.
            rootNode.AddChild(node_list(id))
            layerElementTexture.Dispose()
            layercontainer.Dispose()

we_dont_want_this_one_saved:  'Jump here to skip parts that are not tagged for export.
        Next 'Id loop

        scene.SetCurrentTake("One Take") ' need a name
        'time to save...
        Dim exporter As Skill.FbxSDK.IO.FbxExporter = Skill.FbxSDK.IO.FbxExporter.Create(pManager, "")
        If Not exporter.Initialize(frmMain.SaveFileDialog1.FileName) Then
            MsgBox("fbx unable to initialize exporter!", MsgBoxStyle.Exclamation, "FBX Error..")
            frmMain.Timer1.Enabled = True
            GoTo outahere
        End If
        'Dim version As Version = Skill.FbxSDK.IO.FbxIO.CurrentVersion
        'Console.Write(String.Format("FBX version number for this FBX SDK is {0}.{1}.{2}", _
        '                  version.Major, version.Minor, version.Revision))

        exporter.FileFormat = IO.FileFormat.FbxAscii ' Ascii so I can look at the out put.

        Dim exportOptions As Skill.FbxSDK.IO.FbxStreamOptionsFbxWriter _
                = Skill.FbxSDK.IO.FbxStreamOptionsFbxWriter.Create(pManager, "")
        If pManager.IOPluginRegistry.WriterIsFBX(IO.FileFormat.FbxAscii) Then

            ' Export options determine what kind of data is to be imported.
            ' The default (except for the option eEXPORT_TEXTURE_AS_EMBEDDED)
            ' is true, but here we set the options explictly.
            exportOptions.SetOption(Skill.FbxSDK.IO.FbxStreamOptionsFbx.MATERIAL, True)
            exportOptions.SetOption(Skill.FbxSDK.IO.FbxStreamOptionsFbx.TEXTURE, True)
            exportOptions.SetOption(Skill.FbxSDK.IO.FbxStreamOptionsFbx.EMBEDDED, False)
            exportOptions.SetOption(Skill.FbxSDK.IO.FbxStreamOptionsFbx.LINK, True)
            exportOptions.SetOption(Skill.FbxSDK.IO.FbxStreamOptionsFbx.SHAPE, False)
            exportOptions.SetOption(Skill.FbxSDK.IO.FbxStreamOptionsFbx.GOBO, False)
            exportOptions.SetOption(Skill.FbxSDK.IO.FbxStreamOptionsFbx.ANIMATION, False)
            exportOptions.SetOption(Skill.FbxSDK.IO.FbxStreamOptionsFbx.GLOBAL_SETTINGS, False)
            exportOptions.SetOption(Skill.FbxSDK.IO.FbxStreamOptionsFbx.MEDIA, False)
        End If
        Dim status = exporter.Export(scene, exportOptions)
        exporter.Destroy()
        pManager.Destroy()
        'let the garbage collector take care of these
        ReDim lMaterials(0)
        ReDim lTextures(0)
        ReDim node_list(0)
outahere:
    End Sub
    Public Function fbx_create_material(pManager As FbxSdkManager, id As Integer) As FbxSurfacePhong
        Dim lMaterial As FbxSurfacePhong
        Dim m_name As String = "Material"
        Dim s_name As String = "Phong"
        'need colors defined
        Dim black = New FbxDouble3(0.0, 0.0, 0.0)
        Dim light = New FbxDouble3(0.9, 0.9, 0.9)
        Dim light2 = New FbxDouble3(0.7, 0.7, 0.7)
        Dim color As New FbxDouble3(0.8, 0.8, 0.8)
        'Need a name for this material
        lMaterial = FbxSurfacePhong.Create(pManager, m_name + ":" + id.ToString("000"))
        lMaterial.EmissiveColor = black
        lMaterial.AmbientColor = light
        lMaterial.DiffuseColor = color
        lMaterial.SpecularColor = light2
        lMaterial.SpecularFactor = 0.3
        lMaterial.TransparencyFactor = 0.0
        lMaterial.Shininess = 60.0
        lMaterial.ShadingModel = s_name
        Return lMaterial
    End Function
    Public Function fbx_create_texture(pManager As FbxSdkManager, id As Integer) As FbxTexture
        'need a name for this texture
        Dim texture = FbxTexture.Create(pManager, "DiffuseMap" + ":" + id.ToString("000"))
        ' Set texture properties.
        texture.SetFileName(texture_list(id).path) 'Get the Texture path from the list
        texture.TextureUseType = FbxTexture.TextureUse.Standard
        texture.Mapping = FbxTexture.MappingType.Uv
        texture.MaterialUseType = FbxTexture.MaterialUse.Model
        texture.SwapUV = False
        texture.SetTranslation(0.0, 0.0)
        texture.SetScale(1.0, 1.0)
        texture.SetRotation(0.0, 0.0)
        Return texture
    End Function
    Public Function fbx_create_mesh(model_name As String, id As Integer, pManager As FbxSdkManager) As FbxMesh
        Dim myMesh As FbxMesh
        myMesh = FbxMesh.Create(pManager, model_name)
        Dim v As vec3
        Dim v_2 As New FbxVector2
        Dim v4 As New FbxVector4
        Dim I As Integer

        'first we load all the vertices for the triangles data
        myMesh.InitControlPoints(triangles(id).vert_cnt) ' size of array
        'add in the vertices (or control points as its called in FBX)
        Dim cp_array(myMesh.ControlPointsCount - 1) As FbxVector4
        For I = 0 To myMesh.ControlPointsCount - 1
            cp_array(I) = New FbxVector4
            cp_array(I).X = triangles(id).vertices(I).x
            cp_array(I).Y = triangles(id).vertices(I).y
            cp_array(I).Z = triangles(id).vertices(I).z
        Next
        myMesh.ControlPoints = cp_array ' push it in to the mesh object
        'create or get the layer 0
        Dim layer As FbxLayer = myMesh.GetLayer(0)
        If layer Is Nothing Then
            myMesh.CreateLayer()
            layer = myMesh.GetLayer(0)
        End If

        'normals.. seems to be working ok
        Dim layerElementNormal = FbxLayerElementNormal.Create(myMesh, "Normals")
        layerElementNormal.Mapping_Mode = FbxLayerElement.MappingMode.ByPolygonVertex
        layerElementNormal.Reference_Mode = FbxLayerElement.ReferenceMode.Direct
        'time to assign the normals to each control point.
        'OK.. I have to reverse the winding order be cause 3DS dont like it the way it is
        For I = 0 To (triangles(id).indi_cnt - 1) Step 3
            Dim v3 = triangles(id).indices(I)
            Dim v2 = triangles(id).indices(I + 1)
            Dim v1 = triangles(id).indices(I + 2)
            v = triangles(id).norm(v1)
            v4.X = v.x
            v4.Y = v.y
            v4.Z = v.z
            layerElementNormal.DirectArray.Add(v4)

            v = triangles(id).norm(v2)
            v4.X = v.x
            v4.Y = v.y
            v4.Z = v.z
            layerElementNormal.DirectArray.Add(v4)

            v = triangles(id).norm(v3)
            v4.X = v.x
            v4.Y = v.y
            v4.Z = v.z
            layerElementNormal.DirectArray.Add(v4)
        Next

        '--------------------------------------------------------------------------
        ' Create UV for Diffuse channel
        layer.Normals = layerElementNormal
        Dim UVDiffuseLayer As FbxLayerElementUV = FbxLayerElementUV.Create(myMesh, "DiffuseUV")
        UVDiffuseLayer.Mapping_Mode = FbxLayerElement.MappingMode.ByControlPoint
        UVDiffuseLayer.Reference_Mode = FbxLayerElement.ReferenceMode.Direct
        layer.SetUVs(UVDiffuseLayer, FbxLayerElement.LayerElementType.DiffuseTextures)

        For I = 0 To myMesh.ControlPointsCount - 1
            If frmMain.m_U_Save_Flip.CheckState Then
                v_2.X = triangles(id).uv(I).u * -1
            Else
                v_2.X = triangles(id).uv(I).u
            End If

            If frmMain.m_V_Save_Flip.CheckState Then
                v_2.Y = triangles(id).uv(I).v * -1
            Else
                v_2.Y = triangles(id).uv(I).v
            End If
            UVDiffuseLayer.DirectArray.Add(v_2)
        Next

        '---------------------------------------------------------------------------

        'we should have indi_cnt-1 / 3 triangles
        Dim pos As UInt32 = 0
        Dim n As UInt32 = 0
        Dim j As UInt32 = 0
        For I = 0 To (triangles(id).indi_cnt - 1) Step 3
            myMesh.BeginPolygon(-1, -1, -1, False)

            j = 0
            pos = triangles(id).indices(n + 2)
            myMesh.AddPolygon(pos)
            UVDiffuseLayer.IndexArray.SetAt(pos, j)
            j += 1
            pos = triangles(id).indices(n + 1)
            myMesh.AddPolygon(pos)
            UVDiffuseLayer.IndexArray.SetAt(pos, j)
            j += 1
            pos = triangles(id).indices(n)
            myMesh.AddPolygon(pos)
            UVDiffuseLayer.IndexArray.SetAt(pos, j)
            n += 3
            myMesh.EndPolygon()

        Next
        Return myMesh
    End Function&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Oct 2015 19:21:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fbx-forum/fbx-sdk-is-creating-a-new-mat-texture-pair-for-every-mesh/m-p/5861873#M2344</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-10-14T19:21:08Z</dc:date>
    </item>
  </channel>
</rss>

