Пример #1
0
        public new static FbxSurfacePhong Create(FbxObject pContainer, string pName)
        {
            global::System.IntPtr cPtr = FbxWrapperNativePINVOKE.FbxSurfacePhong_Create__SWIG_1(FbxObject.getCPtr(pContainer), pName);
            FbxSurfacePhong       ret  = (cPtr == global::System.IntPtr.Zero) ? null : new FbxSurfacePhong(cPtr, false);

            return(ret);
        }
Пример #2
0
        public new static FbxSurfacePhong Cast(FbxObject arg0)
        {
            global::System.IntPtr cPtr = FbxWrapperNativePINVOKE.FbxSurfacePhong_Cast(FbxObject.getCPtr(arg0));
            FbxSurfacePhong       ret  = (cPtr == global::System.IntPtr.Zero) ? null : new FbxSurfacePhong(cPtr, false);

            return(ret);
        }
Пример #3
0
        public new static FbxSurfacePhong Create(FbxManager pManager, string pName)
        {
            global::System.IntPtr cPtr = fbx_wrapperPINVOKE.FbxSurfacePhong_Create__SWIG_0(FbxManager.getCPtr(pManager), pName);
            FbxSurfacePhong       ret  = (cPtr == global::System.IntPtr.Zero) ? null : new FbxSurfacePhong(cPtr, false);

            return(ret);
        }
Пример #4
0
        protected override FbxScene CreateScene(FbxManager manager)
        {
            FbxScene scene = base.CreateScene(manager);

            // mesh shared by all instances
            FbxMesh            sharedMesh     = FbxMesh.Create(scene, m_meshName);
            FbxSurfaceMaterial sharedMaterial = FbxSurfacePhong.Create(scene, m_materialName);

            // add mesh to all nodes
            Queue <FbxNode> nodes = new Queue <FbxNode>();

            for (int i = 0; i < scene.GetRootNode().GetChildCount(); i++)
            {
                nodes.Enqueue(scene.GetRootNode().GetChild(i));
            }

            while (nodes.Count > 0)
            {
                FbxNode node = nodes.Dequeue();
                node.SetNodeAttribute(sharedMesh);
                node.AddMaterial(sharedMaterial);
                for (int i = 0; i < node.GetChildCount(); i++)
                {
                    nodes.Enqueue(node.GetChild(i));
                }
            }

            return(scene);
        }
 public bool Equals(FbxSurfacePhong other)
 {
     if (object.ReferenceEquals(other, null))
     {
         return(false);
     }
     return(this.swigCPtr.Handle.Equals(other.swigCPtr.Handle));
 }
Пример #6
0
        public void SurfacePhong_Create_HasNamespacePrefix()
        {
            // given:
            var surface = new FbxSurfacePhong("asdf");

            // then:
            Assert.AreEqual("Material::", surface.GetNameSpacePrefix());
        }
        public new static FbxSurfacePhong Create(FbxObject pContainer, string pName)
        {
            global::System.IntPtr cPtr = NativeMethods.FbxSurfacePhong_Create__SWIG_1(FbxObject.getCPtr(pContainer), pName);
            FbxSurfacePhong       ret  = (cPtr == global::System.IntPtr.Zero) ? null : new FbxSurfacePhong(cPtr, false);

            if (NativeMethods.SWIGPendingException.Pending)
            {
                throw NativeMethods.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Пример #8
0
        public void Node_AddMaterial_SetsMaterialScene()
        {
            // given:
            var scene = new FbxScene("");
            var root  = scene.GetRootNode();
            var node  = new FbxNode("");
            var mat   = new FbxSurfacePhong("");

            root.AddChild(node);

            // require:
            Assert.AreEqual(4, scene.GetSrcObjectCount());
            Assert.AreEqual(scene.GetRootNode(), scene.GetSrcObject(0));
            Assert.AreEqual(scene.GetGlobalSettings(), scene.GetSrcObject(1));
            Assert.AreEqual(scene.GetAnimationEvaluator(), scene.GetSrcObject(2));
            Assert.AreEqual(node, scene.GetSrcObject(3));
            Assert.AreEqual(0, scene.GetDstObjectCount());
            Assert.AreEqual(2, scene.GetNodeCount());
            Assert.AreEqual(scene.GetRootNode(), scene.GetNode(0));
            Assert.AreEqual(node, scene.GetNode(1));

            Assert.AreEqual(0, node.GetSrcObjectCount());
            Assert.AreEqual(2, node.GetDstObjectCount());
            Assert.AreEqual(root, node.GetDstObject(0));
            Assert.AreEqual(scene, node.GetDstObject(1));
            Assert.AreEqual(scene, node.GetScene());
            Assert.AreEqual(0, node.GetMaterialCount());

            Assert.AreEqual(0, mat.GetSrcObjectCount());
            Assert.AreEqual(0, mat.GetDstObjectCount());
            Assert.AreEqual(null, mat.GetScene());

            // when:
            node.AddMaterial(mat);

            // then:
            Assert.AreEqual(5, scene.GetSrcObjectCount());
            Assert.AreEqual(mat, scene.GetSrcObject(4));
            Assert.AreEqual(2, scene.GetNodeCount());
            Assert.AreEqual(scene.GetRootNode(), scene.GetNode(0));
            Assert.AreEqual(node, scene.GetNode(1));

            Assert.AreEqual(1, node.GetSrcObjectCount());
            Assert.AreEqual(mat, node.GetSrcObject(0));
            Assert.AreEqual(1, node.GetMaterialCount());
            Assert.AreEqual(mat, node.GetMaterial(0));

            Assert.AreEqual(0, mat.GetSrcObjectCount());
            Assert.AreEqual(2, mat.GetDstObjectCount());
            Assert.AreEqual(node, mat.GetDstObject(0));
            Assert.AreEqual(scene, mat.GetDstObject(1));
            Assert.AreEqual(scene, mat.GetScene());
        }
Пример #9
0
        public void SurfacePhong_FindProperty_FindsProperty()
        {
            // given:
            var surf = new FbxSurfacePhong("");

            // when:
            var prop = surf.FindProperty("SpecularColor");

            // then:
            Assert.NotNull(prop);
            Assert.True(prop.IsValid());
        }
Пример #10
0
        public void SurfacePhongDiffuseColor_ConnectSrcObject_ConnectsSrcObject()
        {
            // given:
            var surf = new FbxSurfacePhong("");
            var tex  = new FbxTexture("");

            // when:
            var result = surf.Diffuse.ConnectSrcObject(tex);

            // then:
            Assert.True(result);
            Assert.AreEqual(1, surf.Diffuse.GetSrcObjectCount());
            var obj = surf.Diffuse.GetSrcObject(0);

            Assert.NotNull(obj);
            Assert.AreSame(tex, obj);
        }
Пример #11
0
            /// <summary>
            /// Export (and map) a Unity PBS material to FBX classic material
            /// </summary>
            public FbxSurfaceMaterial ExportMaterial(Material unityMaterial, FbxScene fbxScene)
            {
                if (Verbose)
                {
                    Debug.Log(string.Format("exporting material {0}", unityMaterial.name));
                }

                var materialName = unityMaterial ? unityMaterial.name : "DefaultMaterial";

                if (MaterialMap.ContainsKey(materialName))
                {
                    return(MaterialMap [materialName]);
                }

                // We'll export either Phong or Lambert. Phong if it calls
                // itself specular, Lambert otherwise.
                var  shader   = unityMaterial ? unityMaterial.shader : null;
                bool specular = shader && shader.name.ToLower().Contains("specular");

                var fbxMaterial = specular
                    ? FbxSurfacePhong.Create(fbxScene, materialName)
                    : FbxSurfaceLambert.Create(fbxScene, materialName);

                // Copy the flat colours over from Unity standard materials to FBX.
                fbxMaterial.Diffuse.Set(GetMaterialColor(unityMaterial, "_Color"));
                fbxMaterial.Emissive.Set(GetMaterialColor(unityMaterial, "_EmissionColor"));
                fbxMaterial.Ambient.Set(new FbxDouble3());
                fbxMaterial.BumpFactor.Set(unityMaterial ? unityMaterial.GetFloat("_BumpScale") : 0);
                if (specular)
                {
                    (fbxMaterial as FbxSurfacePhong).Specular.Set(GetMaterialColor(unityMaterial, "_SpecColor"));
                }

                // Export the textures from Unity standard materials to FBX.
                ExportTexture(unityMaterial, "_MainTex", fbxMaterial, FbxSurfaceMaterial.sDiffuse);
                ExportTexture(unityMaterial, "_EmissionMap", fbxMaterial, "emissive");
                ExportTexture(unityMaterial, "_BumpMap", fbxMaterial, FbxSurfaceMaterial.sNormalMap);
                if (specular)
                {
                    ExportTexture(unityMaterial, "_SpecGlosMap", fbxMaterial, FbxSurfaceMaterial.sSpecular);
                }

                MaterialMap.Add(materialName, fbxMaterial);
                return(fbxMaterial);
            }
Пример #12
0
        public void SurfacePhongDiffuseColor_ConnectSrcObject_ConnectsDstProperty()
        {
            // given:
            var surf = new FbxSurfacePhong("");
            var tex  = new FbxTexture("");

            // when:
            var result = surf.Diffuse.ConnectSrcObject(tex);

            // then:
            Assert.True(result);
            Assert.AreEqual(1, tex.GetDstPropertyCount());
            var prop = tex.GetDstProperty(0);

            Assert.NotNull(prop);
            Assert.True(prop.IsValid());
            Assert.AreEqual("DiffuseColor", prop.GetName());
        }
        protected override FbxScene CreateScene(FbxManager manager)
        {
            FbxScene scene = base.CreateScene(manager);

            // Set the UVs
            FbxMesh cubeMesh = scene.GetRootNode().GetChild(0).GetMesh();

            FbxLayer fbxLayer = cubeMesh.GetLayer(0 /* default layer */);

            if (fbxLayer == null)
            {
                cubeMesh.CreateLayer();
                fbxLayer = cubeMesh.GetLayer(0 /* default layer */);
            }

            using (var fbxLayerElement = FbxLayerElementUV.Create(cubeMesh, "UVSet"))
            {
                fbxLayerElement.SetMappingMode(FbxLayerElement.EMappingMode.eByPolygonVertex);
                fbxLayerElement.SetReferenceMode(FbxLayerElement.EReferenceMode.eIndexToDirect);

                // set texture coordinates per vertex
                FbxLayerElementArray fbxElementArray = fbxLayerElement.GetDirectArray();

                for (int n = 0; n < 8; n++)
                {
                    fbxElementArray.Add(new FbxVector2(n % 2, 1));  // TODO: switch to correct values
                }

                // For each face index, point to a texture uv
                FbxLayerElementArray fbxIndexArray = fbxLayerElement.GetIndexArray();
                fbxIndexArray.SetCount(24);

                for (int vertIndex = 0; vertIndex < 24; vertIndex++)
                {
                    fbxIndexArray.SetAt(vertIndex, vertIndex % 8);  // TODO: switch to correct values
                }
                fbxLayer.SetUVs(fbxLayerElement, FbxLayerElement.EType.eTextureDiffuse);
            }

            // Create the material
            var fbxMaterial = FbxSurfacePhong.Create(scene, m_materialName);

            fbxMaterial.Diffuse.Set(new FbxColor(1, 1, 1));
            fbxMaterial.Emissive.Set(new FbxColor(0.5, 0.1, 0.2));
            fbxMaterial.Ambient.Set(new FbxDouble3(0.3, 0.4, 0));
            fbxMaterial.BumpFactor.Set(0.6);
            fbxMaterial.Specular.Set(new FbxDouble3(0.8, 0.7, 0.9));

            // Create and add the texture
            var fbxMaterialProperty = fbxMaterial.FindProperty(FbxSurfaceMaterial.sDiffuse);

            Assert.IsNotNull(fbxMaterialProperty);
            Assert.IsTrue(fbxMaterialProperty.IsValid());

            var fbxTexture = FbxFileTexture.Create(fbxMaterial, FbxSurfaceMaterial.sDiffuse + "_Texture");

            fbxTexture.SetFileName("/path/to/some/texture.jpg");
            fbxTexture.SetTextureUse(FbxTexture.ETextureUse.eStandard);
            fbxTexture.SetMappingType(FbxTexture.EMappingType.eUV);

            fbxTexture.ConnectDstProperty(fbxMaterialProperty);

            scene.GetRootNode().GetChild(0).AddMaterial(fbxMaterial);
            return(scene);
        }
Пример #14
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(FbxSurfacePhong obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
Пример #15
0
        public void SurfacePhong_Create_HasProperties()
        {
            // given:
            var         surface = new FbxSurfacePhong("");
            FbxProperty prop;

            // then:
            Assert.AreEqual(22, CountProperties(surface));
            Assert.AreEqual(0, surface.GetSrcPropertyCount());
            Assert.AreEqual(0, surface.GetDstPropertyCount());

            prop = surface.FindProperty("ShadingModel");
            Assert.NotNull(prop);
            Assert.True(prop.IsValid());
            Assert.NotNull(surface.ShadingModel);
            Assert.True(surface.ShadingModel.IsValid());
            Assert.AreEqual("ShadingModel", surface.ShadingModel.GetName());
            Assert.AreSame(prop, surface.ShadingModel);

            prop = surface.FindProperty("MultiLayer");
            Assert.NotNull(prop);
            Assert.True(prop.IsValid());
            Assert.NotNull(surface.MultiLayer);
            Assert.True(surface.MultiLayer.IsValid());
            Assert.AreEqual("MultiLayer", surface.MultiLayer.GetName());
            Assert.AreSame(prop, surface.MultiLayer);

            prop = surface.FindProperty("EmissiveColor");
            Assert.NotNull(prop);
            Assert.True(prop.IsValid());
            Assert.NotNull(surface.Emissive);
            Assert.True(surface.Emissive.IsValid());
            Assert.AreEqual("EmissiveColor", surface.Emissive.GetName());
            Assert.AreSame(prop, surface.Emissive);

            prop = surface.FindProperty("EmissiveFactor");
            Assert.NotNull(prop);
            Assert.True(prop.IsValid());
            Assert.NotNull(surface.EmissiveFactor);
            Assert.True(surface.EmissiveFactor.IsValid());
            Assert.AreEqual("EmissiveFactor", surface.EmissiveFactor.GetName());
            Assert.AreSame(prop, surface.EmissiveFactor);

            prop = surface.FindProperty("AmbientColor");
            Assert.NotNull(prop);
            Assert.True(prop.IsValid());
            Assert.NotNull(surface.Ambient);
            Assert.True(surface.Ambient.IsValid());
            Assert.AreEqual("AmbientColor", surface.Ambient.GetName());
            Assert.AreSame(prop, surface.Ambient);

            prop = surface.FindProperty("AmbientFactor");
            Assert.NotNull(prop);
            Assert.True(prop.IsValid());
            Assert.NotNull(surface.AmbientFactor);
            Assert.True(surface.AmbientFactor.IsValid());
            Assert.AreEqual("AmbientFactor", surface.AmbientFactor.GetName());
            Assert.AreSame(prop, surface.AmbientFactor);

            prop = surface.FindProperty("DiffuseColor");
            Assert.NotNull(prop);
            Assert.True(prop.IsValid());
            Assert.NotNull(surface.Diffuse);
            Assert.True(surface.Diffuse.IsValid());
            Assert.AreEqual("DiffuseColor", surface.Diffuse.GetName());
            Assert.AreSame(prop, surface.Diffuse);

            prop = surface.FindProperty("DiffuseFactor");
            Assert.NotNull(prop);
            Assert.True(prop.IsValid());
            Assert.NotNull(surface.DiffuseFactor);
            Assert.True(surface.DiffuseFactor.IsValid());
            Assert.AreEqual("DiffuseFactor", surface.DiffuseFactor.GetName());
            Assert.AreSame(prop, surface.DiffuseFactor);

            prop = surface.FindProperty("Bump");
            Assert.NotNull(prop);
            Assert.True(prop.IsValid());
            Assert.NotNull(surface.Bump);
            Assert.True(surface.Bump.IsValid());
            Assert.AreEqual("Bump", surface.Bump.GetName());
            Assert.AreSame(prop, surface.Bump);

            prop = surface.FindProperty("NormalMap");
            Assert.NotNull(prop);
            Assert.True(prop.IsValid());
            Assert.NotNull(surface.NormalMap);
            Assert.True(surface.NormalMap.IsValid());
            Assert.AreEqual("NormalMap", surface.NormalMap.GetName());
            Assert.AreSame(prop, surface.NormalMap);

            prop = surface.FindProperty("BumpFactor");
            Assert.NotNull(prop);
            Assert.True(prop.IsValid());
            Assert.NotNull(surface.BumpFactor);
            Assert.True(surface.BumpFactor.IsValid());
            Assert.AreEqual("BumpFactor", surface.BumpFactor.GetName());
            Assert.AreSame(prop, surface.BumpFactor);

            prop = surface.FindProperty("TransparentColor");
            Assert.NotNull(prop);
            Assert.True(prop.IsValid());
            Assert.NotNull(surface.TransparentColor);
            Assert.True(surface.TransparentColor.IsValid());
            Assert.AreEqual("TransparentColor", surface.TransparentColor.GetName());
            Assert.AreSame(prop, surface.TransparentColor);

            prop = surface.FindProperty("TransparencyFactor");
            Assert.NotNull(prop);
            Assert.True(prop.IsValid());
            Assert.NotNull(surface.TransparencyFactor);
            Assert.True(surface.TransparencyFactor.IsValid());
            Assert.AreEqual("TransparencyFactor", surface.TransparencyFactor.GetName());
            Assert.AreSame(prop, surface.TransparencyFactor);

            prop = surface.FindProperty("DisplacementColor");
            Assert.NotNull(prop);
            Assert.True(prop.IsValid());
            Assert.NotNull(surface.DisplacementColor);
            Assert.True(surface.DisplacementColor.IsValid());
            Assert.AreEqual("DisplacementColor", surface.DisplacementColor.GetName());
            Assert.AreSame(prop, surface.DisplacementColor);

            prop = surface.FindProperty("DisplacementFactor");
            Assert.NotNull(prop);
            Assert.True(prop.IsValid());
            Assert.NotNull(surface.DisplacementFactor);
            Assert.True(surface.DisplacementFactor.IsValid());
            Assert.AreEqual("DisplacementFactor", surface.DisplacementFactor.GetName());
            Assert.AreSame(prop, surface.DisplacementFactor);

            prop = surface.FindProperty("VectorDisplacementColor");
            Assert.NotNull(prop);
            Assert.True(prop.IsValid());
            Assert.NotNull(surface.VectorDisplacementColor);
            Assert.True(surface.VectorDisplacementColor.IsValid());
            Assert.AreEqual("VectorDisplacementColor", surface.VectorDisplacementColor.GetName());
            Assert.AreSame(prop, surface.VectorDisplacementColor);

            prop = surface.FindProperty("VectorDisplacementFactor");
            Assert.NotNull(prop);
            Assert.True(prop.IsValid());
            Assert.NotNull(surface.VectorDisplacementFactor);
            Assert.True(surface.VectorDisplacementFactor.IsValid());
            Assert.AreEqual("VectorDisplacementFactor", surface.VectorDisplacementFactor.GetName());
            Assert.AreSame(prop, surface.VectorDisplacementFactor);

            prop = surface.FindProperty("SpecularColor");
            Assert.NotNull(prop);
            Assert.True(prop.IsValid());
            Assert.NotNull(surface.Specular);
            Assert.True(surface.Specular.IsValid());
            Assert.AreEqual("SpecularColor", surface.Specular.GetName());
            Assert.AreSame(prop, surface.Specular);

            prop = surface.FindProperty("SpecularFactor");
            Assert.NotNull(prop);
            Assert.True(prop.IsValid());
            Assert.NotNull(surface.SpecularFactor);
            Assert.True(surface.SpecularFactor.IsValid());
            Assert.AreEqual("SpecularFactor", surface.SpecularFactor.GetName());
            Assert.AreSame(prop, surface.SpecularFactor);

            prop = surface.FindProperty("ShininessExponent");
            Assert.NotNull(prop);
            Assert.True(prop.IsValid());
            Assert.NotNull(surface.Shininess);
            Assert.True(surface.Shininess.IsValid());
            Assert.AreEqual("ShininessExponent", surface.Shininess.GetName());
            Assert.AreSame(prop, surface.Shininess);

            prop = surface.FindProperty("ReflectionColor");
            Assert.NotNull(prop);
            Assert.True(prop.IsValid());
            Assert.NotNull(surface.Reflection);
            Assert.True(surface.Reflection.IsValid());
            Assert.AreEqual("ReflectionColor", surface.Reflection.GetName());
            Assert.AreSame(prop, surface.Reflection);

            prop = surface.FindProperty("ReflectionFactor");
            Assert.NotNull(prop);
            Assert.True(prop.IsValid());
            Assert.NotNull(surface.ReflectionFactor);
            Assert.True(surface.ReflectionFactor.IsValid());
            Assert.AreEqual("ReflectionFactor", surface.ReflectionFactor.GetName());
            Assert.AreSame(prop, surface.ReflectionFactor);
        }