static LUtfNode DefaultMaterialNode(LUtfNode parent, ColladaMaterial mat, int i)
        {
            var matnode = new LUtfNode()
            {
                Name = mat.Name, Parent = parent
            };

            matnode.Children = new List <LUtfNode>();
            matnode.Children.Add(new LUtfNode()
            {
                Name = "Type", Parent = matnode, Data = Encoding.ASCII.GetBytes("DcDt")
            });
            var arr = new float[] { mat.Dc.R, mat.Dc.G, mat.Dc.B };

            matnode.Children.Add(new LUtfNode()
            {
                Name = "Dc", Parent = matnode, Data = UnsafeHelpers.CastArray(arr)
            });
            matnode.Children.Add(new LUtfNode()
            {
                Name = "Dt_name", Parent = matnode, Data = Encoding.ASCII.GetBytes(mat.Name + ".dds")
            });
            matnode.Children.Add(new LUtfNode()
            {
                Name = "Dt_flags", Parent = matnode, Data = BitConverter.GetBytes(64)
            });
            return(matnode);
        }
Exemplo n.º 2
0
 static bool HasMat(List<ColladaMaterial> materials, ColladaMaterial m)
 {
     foreach (var m2 in materials)
     {
         if (m2.Name == m.Name) return true;
     }
     return false;
 }
 static bool HasMat(List <ColladaMaterial> materials, ColladaMaterial m)
 {
     foreach (var m2 in materials)
     {
         if (m2.Name == m.Name)
         {
             return(true);
         }
     }
     return(false);
 }
 static void SetDc(ColladaMaterial material, CL.common_color_or_texture_type obj)
 {
     if (obj == null)
     {
         return;
     }
     if (obj.Item is CL.common_color_or_texture_typeColor col)
     {
         TryParseColor(col.Text, out material.Dc);
     }
     if (obj.Item is CL.common_color_or_texture_typeTexture tex)
     {
         material.Dc = Color4.White;
         FLLog.Warning("Collada", "Not Implemented: Diffuse texture import");
     }
 }
        static ColladaMaterial ParseMaterial(string name, CL.library_materials matlib, CL.library_effects fxlib)
        {
            if (matlib == null)
            {
                return new ColladaMaterial()
                       {
                           Dc   = Color4.Red,
                           Name = name
                       }
            }
            ;
            var src = matlib.material.FirstOrDefault(mat => mat.id.Equals(name, StringComparison.InvariantCulture));

            if (src == null)
            {
                return new ColladaMaterial()
                       {
                           Dc   = Color4.Red,
                           Name = name
                       }
            }
            ;
            var output = new ColladaMaterial()
            {
                Dc = Color4.Red
            };

            output.Name = string.IsNullOrWhiteSpace(src.name) ? name : src.name;
            if (src.instance_effect == null)
            {
                return(output);
            }
            if (fxlib == null)
            {
                return(output);
            }
            var fx = fxlib.effect.FirstOrDefault(fx =>
                                                 fx.id.Equals(CheckURI(src.instance_effect.url), StringComparison.InvariantCulture));

            if (fx != null)
            {
                var profile = fx.Items.FirstOfType <CL.effectFx_profile_abstractProfile_COMMON>();
                if (profile == null)
                {
                    return(output);
                }
                if (profile.technique == null)
                {
                    return(output);
                }
                switch (profile.technique.Item)
                {
                case CL.effectFx_profile_abstractProfile_COMMONTechniquePhong phong:
                    SetDc(output, phong.diffuse);
                    break;

                case CL.effectFx_profile_abstractProfile_COMMONTechniqueBlinn blinn:
                    SetDc(output, blinn.diffuse);
                    break;

                case CL.effectFx_profile_abstractProfile_COMMONTechniqueConstant constant:
                    output.Dc = Color4.White;
                    break;

                case CL.effectFx_profile_abstractProfile_COMMONTechniqueLambert lambert:
                    SetDc(output, lambert.diffuse);
                    break;
                }
            }
            return(output);
        }