Example #1
0
        public Light(ulong id, Element element, Document doc, string name)
            : base(id, element, doc, name)
        {
            Color = new SimpleProperty<Vector3>(Props, "Color", new Vector3(1, 1, 1));
            LightType = new SimpleProperty<Type>(Props, "LightType", (Type)0);
            CastLightOnObject = new SimpleProperty<bool>(Props, "CastLightOnObject", false);
            DrawVolumetricLight = new SimpleProperty<bool>(Props, "DrawVolumetricLight", true);
            DrawGroundProjection = new SimpleProperty<bool>(Props, "DrawGroundProjection", true);
            DrawFrontFacingVolumetricLight = new SimpleProperty<bool>(Props, "DrawFrontFacingVolumetricLight", false);
            Intensity = new SimpleProperty<float>(Props, "Intensity", 1.0f);
            InnerAngle = new SimpleProperty<float>(Props, "InnerAngle", 0.0f);
            OuterAngle = new SimpleProperty<float>(Props, "OuterAngle", 45.0f);
            Fog = new SimpleProperty<int>(Props, "Fog", 50);
            DecayType = new SimpleProperty<Decay>(Props, "DecayType", (Decay)0);
            DecayStart = new SimpleProperty<int>(Props, "DecayStart", 0);
            FileName = new SimpleProperty<string>(Props, "FileName", "");

            EnableNearAttenuation = new SimpleProperty<bool>(Props, "EnableNearAttenuation", false);
            NearAttenuationStart = new SimpleProperty<float>(Props, "NearAttenuationStart", 0f);
            NearAttenuationEnd = new SimpleProperty<float>(Props, "NearAttenuationEnd", 0f);
            EnableFarAttenuation = new SimpleProperty<bool>(Props, "EnableFarAttenuation", false);
            FarAttenuationStart = new SimpleProperty<float>(Props, "FarAttenuationStart", 0f);
            FarAttenuationEnd = new SimpleProperty<float>(Props, "FarAttenuationEnd", 0f);

            CastShadow = new SimpleProperty<bool>(Props, "CastShadows", true);
            ShadowColor = new SimpleProperty<Vector3>(Props, "ShadowColor", new Vector3(0, 0, 0));

            AreaLightShape = new SimpleProperty<int>(Props, "AreaLightShape", 0);

            LeftBarnDoor = new SimpleProperty<float>(Props, "LeftBarnDoor", 20.0f);
            RightBarnDoor = new SimpleProperty<float>(Props, "RightBarnDoor", 20.0f);
            TopBarnDoor = new SimpleProperty<float>(Props, "TopBarnDoor", 20.0f);
            BottomBarnDoor = new SimpleProperty<float>(Props, "BottomBarnDoor", 20.0f);
            EnableBarnDoor = new SimpleProperty<bool>(Props, "EnableBarnDoor", true);
        }
Example #2
0
 public static List<FbxMesh> Load(string path, Device device, out Scene scene)
 {
     byte[] input;
     using (var stream = new FileStream(path, FileMode.Open))
     {
         input = new byte[stream.Length];
         stream.Read(input, 0, (int)stream.Length);
     }
     bool isBinary = false;
     List<Token> tokens;
     if (Encoding.ASCII.GetString(input, 0, 18) == "Kaydara FBX Binary")
     {
         isBinary = true;
         BinaryTokenizer.TokenizeBinary(out tokens, input, input.Length);
     }
     else
     {
         Tokenizer.Tokenize(out tokens, input);
     }
     var parser = new Parser(tokens, isBinary);
     var settings = ImporterSettings.Default;
     var doc = new Document(parser, settings);
     FbxConverter.ConvertToScene(out scene, doc);
     var result = new List<FbxMesh>();
     foreach (var assimpMesh in scene.Meshes)
     {
         var mat = scene.Materials[assimpMesh.MaterialIndex];
         var fbxMesh = new FbxMesh(assimpMesh, mat, device, path);
         result.Add(fbxMesh);
     }
     return result;
 }
Example #3
0
        public FbxConverter(out AssimpSharp.Scene scene, Document doc)
        {
            this.Doc = doc;
            this.NodeNames = new Dictionary<string, bool>();
            this.RenamedNodes = new Dictionary<string, string>();
            this.Result = scene = new AssimpSharp.Scene();

            // animations need to be converted first since this will
            // populate the node_anim_chain_bits map, which is needed
            // to determine which nodes need to be generated.
            ConvertAnimations();
            ConvertRootNode();
            if (doc.Settings.ReadAllMaterials)
            {
                // unfortunately this means we have to evaluate all objects
                foreach(var v in doc.Objects)
                {
                    var ob = v.Value.Get();
                    if (ob == null)
                    {
                        continue;
                    }
                    var mat = ob as Material;
                    if (mat != null)
                    {
                        if (!MaterialsConverted.ContainsKey(mat))
                        {
                            ConvertMaterial(mat, null);
                        }
                    }
                }
            }
            TransferDataToScene();
        }
Example #4
0
 public Deformer(ulong id, Element element, Document doc, string name)
     : base(id, element, name)
 {
     var sc = Parser.GetRequiredScope(element);
     var classname = Parser.ParseTokenAsString(Parser.GetRequiredToken(element, 2));
     Props = DocumentUtil.GetPropertyTable(doc, "Deformer.Fbx" + classname, element, sc, true);
 }
Example #5
0
 public NodeAttribute(ulong id, Element element, Document doc, string name)
     : base(id, element, name)
 {
     var sc = Parser.GetRequiredScope(element);
     var classname = Parser.ParseTokenAsString(Parser.GetRequiredToken(element, 2));
     var isNullOrLimb = (classname == "Null") || (classname == "LimbNode");
     props = DocumentUtil.GetPropertyTable(doc, "NodeAttribute.Fbx" + classname, element, sc, isNullOrLimb);
 }
Example #6
0
        /// <summary>
        /// Represents a FBX animation layer (i.e. a list of node animations)
        /// </summary>
        public AnimationLayer(ulong id, Element element, string name, Document doc)
            : base(id, element, name)
        {
            this.doc = doc;
            var sc = Parser.GetRequiredScope(element);

            // note: the props table here bears little importance and is usually absent
            this.props = DocumentUtil.GetPropertyTable(doc, "AnimationLayer.FbxAnimLayer", element, sc, true);
        }
Example #7
0
        public Texture(ulong id, Element element, Document doc, string name)
            : base(id, element, name)
        {
            uvScaling = new Vector2(1, 1);

            var sc = Parser.GetRequiredScope(element);
            var Type = sc["Type"];
            var FileName = sc["FileName"];
            var RelativeFilename = sc["RelativeFilename"];
            var ModelUVTranslation = sc["ModelUVTranslation"];
            var ModelUVScaling = sc["ModelUVScaling"];
            var Texture_Alpha_Source = sc["Texture_Alpha_Source"];
            var Cropping = sc["Cropping"];

            if (Type != null)
            {
                type = Parser.ParseTokenAsString(Parser.GetRequiredToken(Type, 0));
            }
            if (FileName != null)
            {
                fileName = Parser.ParseTokenAsString(Parser.GetRequiredToken(FileName, 0));
            }
            if (RelativeFilename != null)
            {
                relativeFileName = Parser.ParseTokenAsString(Parser.GetRequiredToken(RelativeFilename, 0));
            }
            if (ModelUVTranslation != null)
            {
                uvTrans = new Vector2(Parser.ParseTokenAsFloat(Parser.GetRequiredToken(ModelUVTranslation, 0)), Parser.ParseTokenAsFloat(Parser.GetRequiredToken(ModelUVTranslation, 1)));
            }
            if (ModelUVScaling != null)
            {
                uvTrans = new Vector2(Parser.ParseTokenAsFloat(Parser.GetRequiredToken(ModelUVScaling, 0)), Parser.ParseTokenAsFloat(Parser.GetRequiredToken(ModelUVScaling, 1)));
            }
            if (Cropping != null)
            {
                uint i1 = (uint)Parser.ParseTokenAsInt(Parser.GetRequiredToken(Cropping, 0));
                uint i2 = (uint)Parser.ParseTokenAsInt(Parser.GetRequiredToken(Cropping, 1));
                uint i3 = (uint)Parser.ParseTokenAsInt(Parser.GetRequiredToken(Cropping, 2));
                uint i4 = (uint)Parser.ParseTokenAsInt(Parser.GetRequiredToken(Cropping, 3));
                crop = new Tuple<uint, uint, uint, uint>(i1, i2, i3, i4);
            }
            else
            {
                crop = new Tuple<uint, uint, uint, uint>(0, 0, 0, 0);
            }
            if (Texture_Alpha_Source != null)
            {
                alphaSource = Parser.ParseTokenAsString(Parser.GetRequiredToken(Texture_Alpha_Source, 0));
            }
            props = DocumentUtil.GetPropertyTable(doc, "Texture.FbxFileTexture", element, sc);
        }
Example #8
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 #9
0
 public Camera(ulong id, Element element, Document doc, string name)
     : base(id, element, doc, name)
 {
     Position = new SimpleProperty<Vector3>(Props, "Position", new Vector3(0, 0, 0));
     UpVector = new SimpleProperty<Vector3>(Props, "UpVector", new Vector3(0, 1, 0));
     InterestPosition = new SimpleProperty<Vector3>(Props, "InterestPosition", new Vector3(0, 0, 0));
     AspectWidth = new SimpleProperty<float>(Props, "AspectWidth", 1.0f);
     AspectHeight = new SimpleProperty<float>(Props, "AspectHeight", 1.0f);
     FilmWidth = new SimpleProperty<float>(Props, "FilmWidth", 1.0f);
     FilmHeight = new SimpleProperty<float>(Props, "FilmHeight", 1.0f);
     FilmAspectRatio = new SimpleProperty<float>(Props, "FilmAspectRatio", 1.0f);
     ApertureMode = new SimpleProperty<int>(Props, "ApertureMode", 0);
     FieldOfView = new SimpleProperty<float>(Props, "FieldOfView", 1.0f);
     FocalLength = new SimpleProperty<float>(Props, "FocalLength", 1.0f);
 }
Example #10
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 #11
0
        public LayeredTexture(ulong id, Element element, Document doc, string name)
            : base(id, element, name)
        {
            texture = null;
            blendMode = Blend.Modulate;
            alpha = 1;

            var sc = Parser.GetRequiredScope(element);
            var BlendModes = sc["BlendModes"];
            var Alphas = sc["Alphas"];
            if (BlendModes != null)
            {
                blendMode = (Blend)Parser.ParseTokenAsInt(Parser.GetRequiredToken(BlendModes, 0));
            }
            if (Alphas != null)
            {
                alpha = Parser.ParseTokenAsFloat(Parser.GetRequiredToken(Alphas, 0));
            }
        }
Example #12
0
 public CameraSwicher(ulong id, Element element, Document doc, string name)
     : base(id, element, doc, name)
 {
     var sc = Parser.GetRequiredScope(element);
     var CameraId = sc["CameraId"];
     var CameraName = sc["CameraName"];
     var CameraIndexName = sc["CameraIndexName"];
     if (CameraId != null)
     {
         cameraId = Parser.ParseTokenAsInt(Parser.GetRequiredToken(CameraId, 0));
     }
     if (CameraName != null)
     {
         cameraName = Parser.GetRequiredToken(CameraName, 0).StringContents;
     }
     if (CameraIndexName != null && CameraIndexName.Tokens.Count > 0)
     {
         cameraIndexName = Parser.GetRequiredToken(CameraIndexName, 0).StringContents;
     }
 }
Example #13
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 #14
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 #15
0
        public FileGlobalSettings(Document doc, PropertyTable prop)
        {
            this.doc = doc;
            this.props = prop;

            UpAxis = new SimpleProperty<int>(prop, "UpAxis", 1);
            UnAxisSign = new SimpleProperty<int>(prop, "UnAxisSign", 1);
            FrontAxis = new SimpleProperty<int>(prop, "FrontAxis", 2);
            FrontAxisSign = new SimpleProperty<int>(prop, "FrontAxisSign", 1);
            CoordAxis = new SimpleProperty<int>(prop, "CoordAxis", 0);
            CoordAxisSign = new SimpleProperty<int>(prop, "CoordAxisSign", 0);
            OriginalUpAxis = new SimpleProperty<int>(prop, "OriginalUpAxis", 0);
            OriginalUpAxisSign = new SimpleProperty<int>(prop, "OriginalUpAxisSign", 0);
            UnitScaleFactor = new SimpleProperty<double>(prop, "UnitScaleFactor", 0);
            OriginalUnitScaleFactor = new SimpleProperty<double>(prop, "OriginalUnitScaleFactor", 0);
            AmbientColor = new SimpleProperty<Vector3>(prop, "AmbientColor", new Vector3(0, 0, 0));
            DefaultCamera = new SimpleProperty<string>(prop, "DefaultCamera", "");

            TimeMode = new SimpleProperty<FrameRate>(prop, "TimeMode", FrameRate.FrameRate_DEFAULT);
            TimeSpanStart = new SimpleProperty<ulong>(prop, "TimeSpanStart", 0);
            TimeSpanStop = new SimpleProperty<ulong>(prop, "TimeSpanStop", 0);
            CustomFrameRate = new SimpleProperty<float>(prop, "CustomFrameRate", -1f);
        }
Example #16
0
        public AnimationCurve(ulong id, Element element, string name, Document doc)
            : base(id, element, name)
        {
            var sc = Parser.GetRequiredScope(element);
            var KeyTime = Parser.GetRequiredElement(sc, "KeyTime");
            var KeyValueFloat = Parser.GetRequiredElement(sc, "KeyValueFloat");

            Parser.ParseVectorDataArray(out this.keys, KeyTime);
            Parser.ParseVectorDataArray(out this.values, KeyValueFloat);

            if (keys.Count != values.Count)
            {
                DocumentUtil.DOMError("the number of key times does not match the number of keyframe values", KeyTime);
            }

            // check if the key times are well-ordered
            for (int i = 0; i < keys.Count - 1; i++)
            {
                if (keys[i] > keys[i + 1])
                {
                    DocumentUtil.DOMError("the keyframes are not in ascending order", KeyTime);
                }
            }

            var keyAttrDataFloat = sc["KeyAttrDataFloat"];
            if (keyAttrDataFloat != null)
            {
                Parser.ParseVectorDataArray(out attributes, keyAttrDataFloat);
            }

            var keyAttrFlags = sc["KeyAttrFlags"];
            if (keyAttrFlags != null)
            {
                Parser.ParseVectorDataArray(out flags, keyAttrFlags);
            }
        }
Example #17
0
 public Null(ulong id, Element element, Document doc, string name)
     : base(id, element, doc, name)
 {
 }
Example #18
0
        public Model(ulong id, Element element, Document doc, string name)
            : base(id, element, name)
        {
            shading = "Y";
            var sc = Parser.GetRequiredScope(element);
            var Shading = sc["Shading"];
            var Culling = sc["Culling"];
            if (Shading != null)
            {
                shading = Parser.GetRequiredToken(Shading, 0).StringContents;
            }
            if (Culling != null)
            {
                culling = Parser.ParseTokenAsString(Parser.GetRequiredToken(Culling, 0));
            }
            props = DocumentUtil.GetPropertyTable(doc, "Model.FbxNode", element, sc);
            ResolveLink(element, doc);

            this.QuaternionInterpolate = new SimpleProperty<int>(this.Props, "QuaternionInterpolate", 0);

            this.RotationOrder = new SimpleProperty<RotOrder>(this.Props, "RotationOrder", (RotOrder)0);
            this.RotationOffset = new SimpleProperty<Vector3>(this.Props, "RotationOffset", new Vector3());
            this.RotationPivot = new SimpleProperty<Vector3>(this.Props, "RotationPivot", new Vector3());
            this.ScalingOffset = new SimpleProperty<Vector3>(this.Props, "ScalingOffset", new Vector3());
            this.ScalingPivot = new SimpleProperty<Vector3>(this.Props, "ScalingPivot", new Vector3());
            this.TranslationActive = new SimpleProperty<bool>(this.Props, "TranslationActive", false);

            this.TranslationMin = new SimpleProperty<Vector3>(this.Props, "TranslationMin", new Vector3());
            this.TranslationMax = new SimpleProperty<Vector3>(this.Props, "TranslationMax", new Vector3());

            this.TranslationMinX = new SimpleProperty<bool>(this.Props, "TranslationMinX", false);
            this.TranslationMaxX = new SimpleProperty<bool>(this.Props, "TranslationMaxX", false);
            this.TranslationMinY = new SimpleProperty<bool>(this.Props, "TranslationMinY", false);
            this.TranslationMaxY = new SimpleProperty<bool>(this.Props, "TranslationMaxY", false);
            this.TranslationMinZ = new SimpleProperty<bool>(this.Props, "TranslationMinZ", false);
            this.TranslationMaxZ = new SimpleProperty<bool>(this.Props, "TranslationMaxZ", false);

            this.RotationOrder = new SimpleProperty<RotOrder>(this.Props, "RotationOrder", (RotOrder)0);
            this.RotationSpaceForLimitOnly = new SimpleProperty<bool>(this.Props, "RotationSpaceForLimitOnly", false);
            this.RotationStiffnessX = new SimpleProperty<float>(this.Props, "RotationStiffnessX", 0.0f);
            this.RotationStiffnessY = new SimpleProperty<float>(this.Props, "RotationStiffnessY", 0.0f);
            this.RotationStiffnessZ = new SimpleProperty<float>(this.Props, "RotationStiffnessZ", 0.0f);
            this.AxisLen = new SimpleProperty<float>(this.Props, "AxisLen", 0.0f);

            this.PreRotation = new SimpleProperty<Vector3>(this.Props, "PreRotation", new Vector3());
            this.PostRotation = new SimpleProperty<Vector3>(this.Props, "PostRotation", new Vector3());
            this.RotationActive = new SimpleProperty<bool>(this.Props, "RotationActive", false);

            this.RotationMin = new SimpleProperty<Vector3>(this.Props, "RotationMin", new Vector3());
            this.RotationMax = new SimpleProperty<Vector3>(this.Props, "RotationMax", new Vector3());

            this.RotationMinX = new SimpleProperty<bool>(this.Props, "RotationMinX", false);
            this.RotationMaxX = new SimpleProperty<bool>(this.Props, "RotationMaxX", false);
            this.RotationMinY = new SimpleProperty<bool>(this.Props, "RotationMinY", false);
            this.RotationMaxY = new SimpleProperty<bool>(this.Props, "RotationMaxY", false);
            this.RotationMinZ = new SimpleProperty<bool>(this.Props, "RotationMinZ", false);
            this.RotationMaxZ = new SimpleProperty<bool>(this.Props, "RotationMaxZ", false);
            this.InheritType = new SimpleProperty<TransformInheritance>(this.Props, "InheritType", (TransformInheritance)0);

            this.ScalingActive = new SimpleProperty<bool>(this.Props, "ScalingActive", false);
            this.ScalingMin = new SimpleProperty<Vector3>(this.Props, "ScalingMin", new Vector3());
            this.ScalingMax = new SimpleProperty<Vector3>(this.Props, "ScalingMax", new Vector3(1.0f, 1.0f, 1.0f));
            this.ScalingMinX = new SimpleProperty<bool>(this.Props, "ScalingMinX", false);
            this.ScalingMaxX = new SimpleProperty<bool>(this.Props, "ScalingMaxX", false);
            this.ScalingMinY = new SimpleProperty<bool>(this.Props, "ScalingMinY", false);
            this.ScalingMaxY = new SimpleProperty<bool>(this.Props, "ScalingMaxY", false);
            this.ScalingMinZ = new SimpleProperty<bool>(this.Props, "ScalingMinZ", false);
            this.ScalingMaxZ = new SimpleProperty<bool>(this.Props, "ScalingMaxZ", false);

            this.GeometricTranslation = new SimpleProperty<Vector3>(this.Props, "GeometricTranslation", new Vector3());
            this.GeometricRotation = new SimpleProperty<Vector3>(this.Props, "GeometricRotation", new Vector3());
            this.GeometricScaling = new SimpleProperty<Vector3>(this.Props, "GeometricScaling", new Vector3(1.0f, 1.0f, 1.0f));

            this.MinDampRangeX = new SimpleProperty<float>(this.Props, "MinDampRangeX", 0.0f);
            this.MinDampRangeY = new SimpleProperty<float>(this.Props, "MinDampRangeY", 0.0f);
            this.MinDampRangeZ = new SimpleProperty<float>(this.Props, "MinDampRangeZ", 0.0f);
            this.MaxDampRangeX = new SimpleProperty<float>(this.Props, "MaxDampRangeX", 0.0f);
            this.MaxDampRangeY = new SimpleProperty<float>(this.Props, "MaxDampRangeY", 0.0f);
            this.MaxDampRangeZ = new SimpleProperty<float>(this.Props, "MaxDampRangeZ", 0.0f);

            this.MinDampStrengthX = new SimpleProperty<float>(this.Props, "MinDampStrengthX", 0.0f);
            this.MinDampStrengthY = new SimpleProperty<float>(this.Props, "MinDampStrengthY", 0.0f);
            this.MinDampStrengthZ = new SimpleProperty<float>(this.Props, "MinDampStrengthZ", 0.0f);
            this.MaxDampStrengthX = new SimpleProperty<float>(this.Props, "MaxDampStrengthX", 0.0f);
            this.MaxDampStrengthY = new SimpleProperty<float>(this.Props, "MaxDampStrengthY", 0.0f);
            this.MaxDampStrengthZ = new SimpleProperty<float>(this.Props, "MaxDampStrengthZ", 0.0f);

            this.PreferredAngleX = new SimpleProperty<float>(this.Props, "PreferredAngleX", 0.0f);
            this.PreferredAngleY = new SimpleProperty<float>(this.Props, "PreferredAngleY", 0.0f);
            this.PreferredAngleZ = new SimpleProperty<float>(this.Props, "PreferredAngleZ", 0.0f);

            this.Show = new SimpleProperty<bool>(this.Props, "Show", true);
            this.LODBox = new SimpleProperty<bool>(this.Props, "LODBox", false);
            this.Freeze = new SimpleProperty<bool>(this.Props, "Freeze", false);
        }
Example #19
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 #20
0
 public Scene ReadFile(string file)
 {
     byte[] input;
     using (var stream = new FileStream(file, FileMode.Open))
     {
         input = new byte[stream.Length];
         stream.Read(input, 0, (int)stream.Length);
     }
     bool isBinary = false;
     List<Token> tokens;
     if (Encoding.ASCII.GetString(input, 0, 18) == "Kaydara FBX Binary")
     {
         isBinary = true;
         BinaryTokenizer.TokenizeBinary(out tokens, input, input.Length);
     }
     else
     {
         Tokenizer.Tokenize(out tokens, input);
     }
     Parser parser = new Parser(tokens, isBinary);
     Document doc = new Document(parser, settings);
     Scene scene;
     FbxConverter.ConvertToScene(out scene, doc);
     return scene;
 }
Example #21
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 #22
0
 public LimbNode(ulong id, Element element, Document doc, string name)
     : base(id, element, doc, name)
 {
 }
Example #23
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;
                }
            }
        }
Example #24
0
 public static void ConvertToScene(out AssimpSharp.Scene result, Document doc)
 {
     new FbxConverter(out result, doc);
 }
Example #25
0
        /// <summary>
        /// the optional whitelist specifies a list of property names for which the caller
        /// wants animations for. If the curve node does not match one of these, std::range_error
        /// will be thrown.
        /// </summary>
        public AnimationCurveNode(ulong id, Element element, string name, Document doc, string[] targetPropWhitelist = null)
            : base(id, element, name)
        {
            this.doc = doc;
            this.target = null;
            curves = new Dictionary<string, AnimationCurve>();

            var sc = Parser.GetRequiredScope(element);

            // find target node
            var whitelist = new[] { "Model", "NodeAttribute" };
            var conns = doc.GetConnectionsBySourceSequenced(ID, whitelist);

            foreach(var con in conns)
            {
                // link should go for a property
                if (string.IsNullOrEmpty(con.PropertyName))
                {
                    continue;
                }

                if (targetPropWhitelist != null)
                {
                    var s = con.PropertyName;
                    var ok = false;
                    for(int i=0; i<whitelist.Length; ++i)
                    {
                        if (s == targetPropWhitelist[i])
                        {
                            ok = true;
                            break;
                        }
                    }

                    if (!ok)
                    {
                        throw (new ArgumentOutOfRangeException("AnimationCurveNode target property is not in whitelist"));
                    }
                }

                var ob = con.DestinationObject;
                if (ob == null)
                {
                    DocumentUtil.DOMWarning("failed to read destination object for AnimationCurveNode->Model link, ignoring", element);
                    continue;
                }

                // XXX support constraints as DOM class
                //ai_assert(dynamic_cast<const Model*>(ob) || dynamic_cast<const NodeAttribute*>(ob));
                target = ob;
                if (target == null)
                {
                    continue;
                }

                prop = con.PropertyName;
                break;
            }

            if (target == null)
            {
                DocumentUtil.DOMWarning("failed to resolve target Model/NodeAttribute/Constraint for AnimationCurveNode", element);
            }

            props = DocumentUtil.GetPropertyTable(doc, "AnimationCurveNode.FbxAnimCurveNode", element, sc, false);
        }