Example #1
0
 public Geometry(ulong id, Element element, string name, Document doc)
     : base(id, element, name)
 {
     var conns = doc.GetConnectionsByDestinationSequenced(ID, "Deformer");
     foreach (var con in conns)
     {
         var sk = DocumentUtil.ProcessSimpleConnection<Skin>(con, false, "Skin -> Geometry", element);
         if (sk != null)
         {
             skin = sk;
             break;
         }
     }
 }
Example #2
0
        public Cluster(ulong id, Element element, Document doc, string name)
            : base(id, element, doc, name)
        {
            var sc = Parser.GetRequiredScope(element);
            var Indexes = sc["Indexes"];
            var Weights = sc["Weights"];
            var Transform = Parser.GetRequiredElement(sc, "Transform", element);
            var TransformLink = Parser.GetRequiredElement(sc, "Transform", element);
            this.Transform = Parser.ReadMatrix(Transform);
            this.TransformLink = Parser.ReadMatrix(TransformLink);

            // it is actually possible that there be Deformer's with no weights
            if ((Indexes == null) != (Weights == null))
            {
                throw (new DomException("either Indexes or Weights are missing from Cluster", element));
            }
            if (Indexes != null)
            {
                List<uint> indices;
                List<float> weights;
                Parser.ParseVectorDataArray(out indices, Indexes);
                Parser.ParseVectorDataArray(out weights, Weights);
                this.Indices = indices;
                this.Weights = weights;
            }
            if (this.Indices.Count != this.Weights.Count)
            {
                throw (new DomException("sizes of index and weight array don't match up", element));
            }

            // read assigned node
            var conns = doc.GetConnectionsByDestinationSequenced(ID, "Model");
            foreach (var con in conns)
            {
                var mod = DocumentUtil.ProcessSimpleConnection<Model>(con, false, "Model -> Cluster", element);
                if (mod != null)
                {
                    this.TargetNode = mod;
                    break;
                }
            }
            if (this.TargetNode == null)
            {
                throw (new DomException("failed to read target Node for Cluster", element));
            }
        }
Example #3
0
 public Skin(ulong id, Element element, Document doc, string name)
     : base(id, element, doc, name)
 {
     var sc = Parser.GetRequiredScope(element);
     var LinkDeformAcuracy = sc["Link_DeformAcuracy"];
     if (LinkDeformAcuracy != null)
     {
         DeformAccuracy = Parser.ParseTokenAsFloat(Parser.GetRequiredToken(LinkDeformAcuracy, 0));
     }
     var conns = doc.GetConnectionsByDestinationSequenced(ID, "Deformer");
     Clusters = new List<Cluster>(conns.Count);
     foreach (var con in conns)
     {
         var cluster = DocumentUtil.ProcessSimpleConnection<Cluster>(con, false, "Cluster -> Skin", element);
         if (cluster != null)
         {
             Clusters.Add(cluster);
             continue;
         }
     }
 }
Example #4
0
        public AnimationStack(ulong id, Element element, string name, Document doc)
            : base(id, element, name)
        {
            var sc = Parser.GetRequiredScope(element);

            // note: we don't currently use any of these properties so we shouldn't bother if it is missing
            props = DocumentUtil.GetPropertyTable(doc, "AnimationStack.FbxAnimStack", element, sc, true);

            // resolve attached animation layers
            var conns = doc.GetConnectionsByDestinationSequenced(ID, "AnimationLayer");
            layers = new List<AnimationLayer>(conns.Count);
            foreach (var con in conns)
            {
                // link should not go to a property
                if (!string.IsNullOrEmpty(con.PropertyName))
                {
                    continue;
                }
                var ob = con.SourceObject;
                if (ob == null)
                {
                    DocumentUtil.DOMWarning("failed to read source object for AnimationLayer->AnimationStack link, ignoring", element);
                    continue;
                }
                var anim = ob as AnimationLayer;
                if (anim == null)
                {
                    DocumentUtil.DOMWarning("source object for ->AnimationStack link is not an AnimationLayer", element);
                    continue;
                }
                layers.Add(anim);
            }

            LocalStart = new SimpleProperty<long>(props, "LocalStart", 0);
            LocalStop = new SimpleProperty<long>(props, "LocalStop", 0);
            ReferenceStart = new SimpleProperty<long>(props, "ReferenceStart", 0);
            ReferenceStop = new SimpleProperty<long>(props, "ReferenceStop", 0);
        }
Example #5
0
 private void ResolveLink(Element element, Document doc)
 {
     var arr = new[] { "Geometry", "Material", "NodeAttribute" };
     var conns = doc.GetConnectionsByDestinationSequenced(ID, arr);
     materials = new List<Material>(conns.Count);
     geometry = new List<Geometry>(conns.Count);
     attributes = new List<NodeAttribute>(conns.Count);
     foreach (var con in conns)
     {
         if (con.PropertyName.Length > 0)
         {
             continue;
         }
         Object ob = con.SourceObject;
         if (ob == null)
         {
             Debug.WriteLine("failed to read source object for incoming Model link, ignoring");
             continue;
         }
         Material mat = ob as Material;
         if (mat != null)
         {
             materials.Add(mat);
             continue;
         }
         Geometry geo = ob as Geometry;
         if (geo != null)
         {
             geometry.Add(geo);
             continue;
         }
         NodeAttribute att = ob as NodeAttribute;
         if (att != null)
         {
             attributes.Add(att);
             continue;
         }
         Debug.WriteLine("source object for model link is neither Material, NodeAttribute nor Geometry, ignoring");
         continue;
     }
 }
Example #6
0
 public void FillTexture(Document doc)
 {
     var conns = doc.GetConnectionsByDestinationSequenced(ID);
     for (int i = 0; i < conns.Count; i++)
     {
         var con = conns[i];
         var ob = con.SourceObject;
         if (ob == null)
         {
             DocumentUtil.DOMWarning("failed to read source object for texture link, ignoring", element);
             continue;
         }
         var tex = ob as Texture;
         texture = tex;
     }
 }
Example #7
0
        public Material(ulong id, Element element, Document doc, string name)
            : base(id, element, name)
        {
            var sc = Parser.GetRequiredScope(element);

            var ShadingModel = sc["ShadingModel"];
            var MultiLayer = sc["MultiLayer"];

            if (MultiLayer != null)
            {
                this.multilayer = (Parser.ParseTokenAsID(Parser.GetRequiredToken(MultiLayer, 0)) != 0);
            }

            if (ShadingModel != null)
            {
                this.shading = Parser.ParseTokenAsString(Parser.GetRequiredToken(ShadingModel, 0));
            }
            else
            {
                DocumentUtil.DOMWarning("shading mode not specified, assuming phong", element);
                shading = "phong";
            }

            var templateName = string.Empty;

            var sh = shading;
            if (sh == "phong")
            {
                templateName = "Material.FbxSurfacePhong";
            }
            else if (sh == "lambert")
            {
                templateName = "Material.FbxSurfaceLambert";
            }
            else
            {
                DocumentUtil.DOMWarning("shading mode not recognized: " + shading, element);
            }

            props = DocumentUtil.GetPropertyTable(doc, templateName, element, sc);

            // resolve texture links
            var conns = doc.GetConnectionsByDestinationSequenced(ID);
            foreach (var con in conns)
            {
                // texture link to properties, not objects
                if (string.IsNullOrEmpty(con.PropertyName))
                {
                    continue;
                }

                var ob = con.SourceObject;
                if (ob == null)
                {
                    DocumentUtil.DOMWarning("failed to read source object for texture link, ignoring", element);
                    continue;
                }

                var tex = ob as Texture;
                if (tex == null)
                {
                    var layeredTexture = ob as LayeredTexture;
                    if (layeredTexture == null)
                    {
                        DocumentUtil.DOMWarning("source object for texture link is not a texture or layered texture, ignoring", element);
                        continue;
                    }
                    var prop = con.PropertyName;
                    if (layeredTextures.ContainsKey(prop))
                    {
                        DocumentUtil.DOMWarning("duplicate layered texture link: " + prop, element);
                    }

                    layeredTextures[prop] = layeredTexture;
                    layeredTexture.FillTexture(doc);
                }
                else
                {
                    var prop = con.PropertyName;
                    if (textures.ContainsKey(prop))
                    {
                        DocumentUtil.DOMWarning("duplicate texture link: " + prop, element);
                    }
                    textures[prop] = tex;
                }
            }
        }