Beispiel #1
0
        public InstanceObjectArmature(ObjectArmature o)
            : base(o)
        {
            Armature = o.Armature;

            Bones = new InstanceBone[o.Armature.Bones.Length];
            for (int i = 0; i != Bones.Length; ++i)
            {
                Bones[i] = new InstanceBone(o.Armature.Bones[i]);
            }
        }
Beispiel #2
0
        public static void Write(BinaryWriter writer, SoftwareObject softwareObject)
        {
            string typeName = "";
            var    type     = softwareObject.GetType();

            if (softwareObject.GetType() == typeof(SoftwareObjectMesh))
            {
                typeName = "MESH";
            }
            else if (softwareObject.GetType() == typeof(SoftwareObjectArmature))
            {
                typeName = "ARMATURE";
            }
            else
            {
                Debug.ThrowError("Object", "Unsuported SoftwareObject type: " + softwareObject.GetType());
            }
            writer.Write(typeName);

            // name
            writer.Write(softwareObject.Name);
            writer.Write((softwareObject.Parent != null) ? softwareObject.Parent.Name : "");

            // transform
            writer.WriteVector(softwareObject.Position);
            writer.WriteVector(softwareObject.Scale);
            writer.WriteVector(softwareObject.Rotation);

            // animation
            writer.Write((softwareObject.ArmatureObject != null) ? softwareObject.ArmatureObject.Name : "");
            writer.Write((softwareObject.DefaultAction != null) ? softwareObject.DefaultAction.Name : "");

            // bone groups
            writer.Write(softwareObject.BoneGroups.Count);
            foreach (var bonegroup in softwareObject.BoneGroups)
            {
                ObjectBoneGroup.Write(writer, bonegroup);
            }

            // types
            if (typeName == "MESH")
            {
                ObjectMesh.Write(writer, (SoftwareObjectMesh)softwareObject);
            }
            else if (typeName == "ARMATURE")
            {
                ObjectArmature.Write(writer, (SoftwareObjectArmature)softwareObject);
            }
        }
Beispiel #3
0
        internal void linkObjects(Object[] objects)
        {
            // link parent
            if (!string.IsNullOrEmpty(parentName))
            {
                foreach (var o in objects)
                {
                    if (parentName == o.Name)
                    {
                        Parent     = o;
                        parentName = null;
                        break;
                    }
                }

                if (Parent == null)
                {
                    Debug.ThrowError("Object", "Failed to find Parent");
                }
            }

            // link object armature
            if (!string.IsNullOrEmpty(armatureObjectName))
            {
                foreach (var o in objects)
                {
                    if (armatureObjectName == o.Name)
                    {
                        ArmatureObject     = (ObjectArmature)o;
                        armatureObjectName = null;
                        break;
                    }
                }

                if (ArmatureObject == null)
                {
                    Debug.ThrowError("Object", "Failed to find ObjectArmature");
                }
            }

            // link bones to bone groups
            foreach (var bonegroup in BoneGroups)
            {
                bonegroup.linkObjects(this);
            }
        }
Beispiel #4
0
		private void init(string filename, Stream stream, string contentDirectory, Dictionary<string,Type> materialTypes, List<MaterialFieldBinder> value1BinderTypes, List<MaterialFieldBinder> value2BinderTypes, List<MaterialFieldBinder> value3BinderTypes, List<MaterialFieldBinder> value4BinderTypes, List<MaterialFieldBinder> textureBinderTypes, Dictionary<string,string> fileExtOverrides, int classicInstanceCount, Loader.LoadedCallbackMethod loadedCallback)
		{
			try
			{
				var reader = new BinaryReader(stream);

				// meta data
				if (reader.ReadInt32() != Streams.MakeFourCC('R', 'M', 'F', 'T')) Debug.ThrowError("Error", "Not a ReignModel file: " + filename);
				float version = reader.ReadSingle();
				if (version != 1.0f) Debug.ThrowError("Error", "Unsuported model version: " + version.ToString());
				bool compressed = reader.ReadBoolean();

				// frames
				FrameStart = reader.ReadSingle();
				FrameEnd = reader.ReadSingle();
				FrameCount = FrameEnd - FrameStart;
				FPS = reader.ReadSingle();

				// materials
				int materialCount = reader.ReadInt32();
				Materials = new MaterialI[materialCount];
				Textures = new List<ITexture2D>();
				for (int i = 0; i != materialCount; ++i)
				{
					string name = reader.ReadString();

					// create material
					bool pass = false;
					foreach (var materialType in (Dictionary<string,Type>)materialTypes)
					{
						if (materialType.Key == name)
						{
							Materials[i] = (MaterialI)Activator.CreateInstance(materialType.Value);
							Materials[i].Name = name;
							pass = true;
							break;
						}
					}
					if (!pass) Debug.ThrowError("Model", "Failed to find a valid material type for: " + name);
					var material = Materials[i];

					// values1
					var values1 = new Dictionary<string,float>();
					int valueCount = reader.ReadInt32();
					for (int i2 = 0; i2 != valueCount; ++i2) values1.Add(reader.ReadString(), reader.ReadSingle());
					bindTypes(material, values1, value1BinderTypes, contentDirectory, fileExtOverrides, handleFoundValueBinder);

					// values2
					var values2 = new Dictionary<string,Vector2>();
					valueCount = reader.ReadInt32();
					for (int i2 = 0; i2 != valueCount; ++i2) values2.Add(reader.ReadString(), reader.ReadVector2());
					bindTypes(material, values2, value2BinderTypes, contentDirectory, fileExtOverrides, handleFoundValueBinder);

					// values3
					var values3 = new Dictionary<string,Vector3>();
					valueCount = reader.ReadInt32();
					for (int i2 = 0; i2 != valueCount; ++i2) values3.Add(reader.ReadString(), reader.ReadVector3());
					bindTypes(material, values3, value3BinderTypes, contentDirectory, fileExtOverrides, handleFoundValueBinder);

					// values4
					var values4 = new Dictionary<string,Vector4>();
					valueCount = reader.ReadInt32();
					for (int i2 = 0; i2 != valueCount; ++i2) values4.Add(reader.ReadString(), reader.ReadVector4());
					bindTypes(material, values4, value4BinderTypes, contentDirectory, fileExtOverrides, handleFoundValueBinder);

					// textures
					var textures = new Dictionary<string,string>();
					int textureCount = reader.ReadInt32();
					for (int i2 = 0; i2 != textureCount; ++i2) textures.Add(reader.ReadString(), reader.ReadString());
					bindTypes(material, textures, textureBinderTypes, contentDirectory, fileExtOverrides, handleFoundTextureBinder);
				}

				// meshes
				int meshCount = reader.ReadInt32();
				Meshes = new Mesh[meshCount];
				for (int i = 0; i != meshCount; ++i)
				{
					Meshes[i] = new Mesh(reader, this, classicInstanceCount);
				}

				// actions
				int actionCount = reader.ReadInt32();
				Actions = new Action[actionCount];
				for (int i = 0; i != actionCount; ++i)
				{
					Actions[i] = new Action(reader);
				}

				// armatures
				int armatureCount = reader.ReadInt32();
				Armatures = new Armature[armatureCount];
				for (int i = 0; i != armatureCount; ++i)
				{
					Armatures[i] = new Armature(reader);
				}

				// objects
				int objectCount = reader.ReadInt32();
				Objects = new Object[objectCount];
				for (int i = 0; i != objectCount; ++i)
				{
					string type = reader.ReadString();
					if (type == "MESH") Objects[i] = new ObjectMesh(reader, this);
					else if (type == "ARMATURE") Objects[i] = new ObjectArmature(reader, this);
					else Debug.ThrowError("Mesh", "Unsuported Object type: " + type);
				}

				// link objects
				foreach (var o in Objects)
				{
					o.linkObjects(Objects);
				}
			}
			catch (Exception e)
			{
				FailedToLoad = true;
				Loader.AddLoadableException(e);
				Dispose();
				if (loadedCallback != null) loadedCallback(this, false);
				return;
			}

			if (Textures.Count == 0)
			{
				Loaded = true;
				if (loadedCallback != null) loadedCallback(this, true);
			}
			else
			{
				new LoadWaiter(Textures.ToArray(),
				delegate(object sender, bool succeeded)
				{
					if (succeeded)
					{
						Loaded = true;
						if (loadedCallback != null) loadedCallback(this, true);
					}
					else
					{
						FailedToLoad = true;
						Dispose();
						if (loadedCallback != null) loadedCallback(this, false);
					}
				});
			}
		}
        public InstanceObjectArmature(ObjectArmature o)
            : base(o)
        {
            Armature = o.Armature;

            Bones = new InstanceBone[o.Armature.Bones.Length];
            for (int i = 0; i != Bones.Length; ++i)
            {
                Bones[i] = new InstanceBone(o.Armature.Bones[i]);
            }
        }
Beispiel #6
0
        private void init(string filename, Stream stream, string contentDirectory, Dictionary <string, Type> materialTypes, List <MaterialFieldBinder> value1BinderTypes, List <MaterialFieldBinder> value2BinderTypes, List <MaterialFieldBinder> value3BinderTypes, List <MaterialFieldBinder> value4BinderTypes, List <MaterialFieldBinder> textureBinderTypes, Dictionary <string, string> fileExtOverrides, int classicInstanceCount, Loader.LoadedCallbackMethod loadedCallback)
        {
            try
            {
                var reader = new BinaryReader(stream);

                // meta data
                if (reader.ReadInt32() != Streams.MakeFourCC('R', 'M', 'F', 'T'))
                {
                    Debug.ThrowError("Error", "Not a ReignModel file: " + filename);
                }
                float version = reader.ReadSingle();
                if (version != 1.0f)
                {
                    Debug.ThrowError("Error", "Unsuported model version: " + version.ToString());
                }
                bool compressed = reader.ReadBoolean();

                // frames
                FrameStart = reader.ReadSingle();
                FrameEnd   = reader.ReadSingle();
                FrameCount = FrameEnd - FrameStart;
                FPS        = reader.ReadSingle();

                // materials
                int materialCount = reader.ReadInt32();
                Materials = new MaterialI[materialCount];
                Textures  = new List <ITexture2D>();
                for (int i = 0; i != materialCount; ++i)
                {
                    string name = reader.ReadString();

                    // create material
                    bool pass = false;
                    foreach (var materialType in (Dictionary <string, Type>)materialTypes)
                    {
                        if (materialType.Key == name)
                        {
                            Materials[i]      = (MaterialI)Activator.CreateInstance(materialType.Value);
                            Materials[i].Name = name;
                            pass = true;
                            break;
                        }
                    }
                    if (!pass)
                    {
                        Debug.ThrowError("Model", "Failed to find a valid material type for: " + name);
                    }
                    var material = Materials[i];

                    // values1
                    var values1    = new Dictionary <string, float>();
                    int valueCount = reader.ReadInt32();
                    for (int i2 = 0; i2 != valueCount; ++i2)
                    {
                        values1.Add(reader.ReadString(), reader.ReadSingle());
                    }
                    bindTypes(material, values1, value1BinderTypes, contentDirectory, fileExtOverrides, handleFoundValueBinder);

                    // values2
                    var values2 = new Dictionary <string, Vector2>();
                    valueCount = reader.ReadInt32();
                    for (int i2 = 0; i2 != valueCount; ++i2)
                    {
                        values2.Add(reader.ReadString(), reader.ReadVector2());
                    }
                    bindTypes(material, values2, value2BinderTypes, contentDirectory, fileExtOverrides, handleFoundValueBinder);

                    // values3
                    var values3 = new Dictionary <string, Vector3>();
                    valueCount = reader.ReadInt32();
                    for (int i2 = 0; i2 != valueCount; ++i2)
                    {
                        values3.Add(reader.ReadString(), reader.ReadVector3());
                    }
                    bindTypes(material, values3, value3BinderTypes, contentDirectory, fileExtOverrides, handleFoundValueBinder);

                    // values4
                    var values4 = new Dictionary <string, Vector4>();
                    valueCount = reader.ReadInt32();
                    for (int i2 = 0; i2 != valueCount; ++i2)
                    {
                        values4.Add(reader.ReadString(), reader.ReadVector4());
                    }
                    bindTypes(material, values4, value4BinderTypes, contentDirectory, fileExtOverrides, handleFoundValueBinder);

                    // textures
                    var textures     = new Dictionary <string, string>();
                    int textureCount = reader.ReadInt32();
                    for (int i2 = 0; i2 != textureCount; ++i2)
                    {
                        textures.Add(reader.ReadString(), reader.ReadString());
                    }
                    bindTypes(material, textures, textureBinderTypes, contentDirectory, fileExtOverrides, handleFoundTextureBinder);
                }

                // meshes
                int meshCount = reader.ReadInt32();
                Meshes = new Mesh[meshCount];
                for (int i = 0; i != meshCount; ++i)
                {
                    Meshes[i] = new Mesh(reader, this, classicInstanceCount);
                }

                // actions
                int actionCount = reader.ReadInt32();
                Actions = new Action[actionCount];
                for (int i = 0; i != actionCount; ++i)
                {
                    Actions[i] = new Action(reader);
                }

                // armatures
                int armatureCount = reader.ReadInt32();
                Armatures = new Armature[armatureCount];
                for (int i = 0; i != armatureCount; ++i)
                {
                    Armatures[i] = new Armature(reader);
                }

                // objects
                int objectCount = reader.ReadInt32();
                Objects = new Object[objectCount];
                for (int i = 0; i != objectCount; ++i)
                {
                    string type = reader.ReadString();
                    if (type == "MESH")
                    {
                        Objects[i] = new ObjectMesh(reader, this);
                    }
                    else if (type == "ARMATURE")
                    {
                        Objects[i] = new ObjectArmature(reader, this);
                    }
                    else
                    {
                        Debug.ThrowError("Mesh", "Unsuported Object type: " + type);
                    }
                }

                // link objects
                foreach (var o in Objects)
                {
                    o.linkObjects(Objects);
                }
            }
            catch (Exception e)
            {
                FailedToLoad = true;
                Loader.AddLoadableException(e);
                Dispose();
                if (loadedCallback != null)
                {
                    loadedCallback(this, false);
                }
                return;
            }

            if (Textures.Count == 0)
            {
                Loaded = true;
                if (loadedCallback != null)
                {
                    loadedCallback(this, true);
                }
            }
            else
            {
                new LoadWaiter(Textures.ToArray(),
                               delegate(object sender, bool succeeded)
                {
                    if (succeeded)
                    {
                        Loaded = true;
                        if (loadedCallback != null)
                        {
                            loadedCallback(this, true);
                        }
                    }
                    else
                    {
                        FailedToLoad = true;
                        Dispose();
                        if (loadedCallback != null)
                        {
                            loadedCallback(this, false);
                        }
                    }
                });
            }
        }