Exemple #1
0
        protected override bool BuildColladaInstanceImpl()
        {
            // reset and repopulate the collada file
            COLLADAFile = new ColladaFile();

            COLLADAFile.Version = "1.4.1";
            AddAsset(
                System.Environment.UserName,
                "OpenSauceIDE:ColladaBuilder",
                "meter", 0.0254, Enums.ColladaUpAxisEnum.Z_UP);

            mModelDataProvider = GetDataProvider <IHalo1ModelDataProvider>();

            CreateBoneList();
            CreateMarkerList();
            CreateGeometryList();
            CreateControllerList();
            CreateNodeList();

            CreateImageList();
            CreateEffectList();
            CreateMaterialList();

            AddLibraryImages();
            AddLibraryEffects();
            AddLibraryMaterials();
            AddLibraryGeometries();
            AddLibraryControllers();
            AddLibraryVisualScenes();
            AddScene("main");

            COLLADAFile.Validate();

            return(true);
        }
        protected override bool BuildColladaInstanceImpl()
        {
            COLLADAFile = new ColladaFile();

            COLLADAFile.Version = "1.4.1";
            AddAsset(
                System.Environment.UserName,
                "OpenSauceIDE:ColladaBuilder",
                "meter", 0.0254, Enums.ColladaUpAxisEnum.Z_UP);

            CollectBitmaps();

            CreateImageList();
            CreateEffectList();
            CreateMaterialList();
            CreateBoneList();
            CreateGeometryList();
            CreateControllerList();
            CreateNodeList();
            CreateMarkerList();

            AddLibraryImages();
            AddLibraryEffects();
            AddLibraryMaterials();
            AddLibraryGeometries();
            AddLibraryControllers();
            AddLibraryVisualScenes();
            AddScene("main");

            return(true);
        }
		/// <summary>
		/// Validates a collada file
		/// </summary>
		/// <param name="collada_file">The file to validate</param>
		/// <returns>True if the file is valid</returns>
		public bool ValidateFile(ColladaFile collada_file)
		{
			// get the local IDs from the collada file
			localIDs.AddRange(collada_file.GetIDs());

			bool is_valid = false;
			try
			{
				collada_file.Validate();
				collada_file.ValidateLocalURIs(localIDs);

				is_valid = true;
			}
			catch (ColladaValidationException exception)
			{
				// if the collada file is not valid, add a report detailing why it is not valid
				OnErrorOccured(ColladaExceptionStrings.ValidationFailed);

				// report an error for all inner exceptions
				for (Exception except = exception; except != null; except = except.InnerException)
				{
					OnErrorOccured(except.Message);

					// if the exception was a validation exception, report the element details
					var validation_exception = except as ColladaValidationException;
					if ((validation_exception != null) && (validation_exception.ElementDetails != null))
					{
						foreach (string detail in validation_exception.ElementDetails)
							OnErrorOccured(String.Format("COLLADA_DETAIL: {0}", detail));
					}
				}
			}

			return is_valid;
		}
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>	Loads the specified COLLADA file. </summary>
        ///
        /// <param name="path">	Data relative pathname of the file. </param>
        ///
        /// <returns>	The COLLADA file. </returns>
        private ColladaFile LoadCOLLADAFile(string path)
        {
            var xmlSerializer = new XmlSerializer(typeof(ColladaFile));

            // Build the collada file path
            if (!File.Exists(path))
            {
                SendMessage("The provided source file does not exist");
                return(null);
            }

            // Deserialize the COLLADA file
            ColladaFile colladaFile = null;

            using (var reader = XmlReader.Create(path))
            {
                if (!xmlSerializer.CanDeserialize(reader))
                {
                    SendMessage("Unable to deserialize the source file");
                    return(null);
                }

                colladaFile = xmlSerializer.Deserialize(reader) as ColladaFile;

                if (colladaFile == null)
                {
                    SendMessage("Failed to deserialize the source file");
                    return(null);
                }
            }

            return(colladaFile);
        }
        ///-------------------------------------------------------------------------------------------------
        /// <summary>
        ///     Performs the actual collada file population.
        /// </summary>
        /// <returns>	True if no errors occurred. </returns>
        ///-------------------------------------------------------------------------------------------------
        protected override bool BuildColladaInstanceImpl()
        {
            COLLADAFile = new ColladaFile();

            COLLADAFile.Version = "1.4.1";
            AddAsset(
                System.Environment.UserName,
                "OpenSauceIDE:ColladaBuilder",
                "meter", 0.0254, Enums.ColladaUpAxisEnum.Z_UP);

            mScenarioDataProvider = GetDataProvider <IHalo1ScenarioDataProvider>();

            CreateNodeList();
            AddLibraryVisualScenes();
            AddScene("main");

            return(true);
        }
Exemple #6
0
        protected override bool BuildColladaInstanceImpl()
        {
            COLLADAFile = new ColladaFile();

            COLLADAFile.Version = "1.4.1";
            AddAsset(
                System.Environment.UserName,
                "OpenSauceIDE:ColladaBuilder",
                "meter", 0.0254, Enums.ColladaUpAxisEnum.Z_UP);

            mBSPDataProvider = GetDataProvider <IHalo1BSPDataProvider>();

            if (mBSPDataProvider.IncludeRenderMesh)
            {
                CreateImageList();
                CreateEffectList();
                CreateMaterialList();
            }

            if (mBSPDataProvider.IncludePortals)
            {
                CreateEffectListPortals();
                CreateMaterialListPortals();
            }

            if (mBSPDataProvider.IncludeFogPlanes)
            {
                CreateEffectListFogPlanes();
                CreateMaterialListFogPlanes();
            }

            CreateGeometryList();
            CreateMarkerList();
            CreateNodeList();

            AddLibraryImages();
            AddLibraryEffects();
            AddLibraryMaterials();
            AddLibraryGeometries();
            AddLibraryVisualScenes();
            AddScene("main");

            return(true);
        }
Exemple #7
0
        /// <summary>
        /// Validates a collada file
        /// </summary>
        /// <param name="collada_file">The file to validate</param>
        /// <returns>True if the file is valid</returns>
        public bool ValidateFile(ColladaFile collada_file)
        {
            // get the local IDs from the collada file
            localIDs.AddRange(collada_file.GetIDs());

            bool is_valid = false;

            try
            {
                collada_file.Validate();
                collada_file.ValidateLocalURIs(localIDs);

                is_valid = true;
            }
            catch (Exception exception)
            {
                // if the collada file is not valid, add a report detailing why it is not valid
                OnErrorOccured(ColladaExceptionStrings.ValidationFailed);

                // report an error for all inner exceptions
                for (var except = exception; except != null; except = except.InnerException)
                {
                    OnErrorOccured(except.Message);

                    // if the exception was a validation exception, report the element details
                    var validation_exception = except as ColladaValidationException;
                    if ((validation_exception != null) && (validation_exception.ElementDetails != null))
                    {
                        foreach (string detail in validation_exception.ElementDetails)
                        {
                            OnErrorOccured(String.Format("COLLADA_DETAIL: {0}", detail));
                        }
                    }
                }
            }

            return(is_valid);
        }
		protected override bool BuildColladaInstanceImpl()
		{
			COLLADAFile = new ColladaFile();

			COLLADAFile.Version = "1.4.1";
			AddAsset(
				System.Environment.UserName,
				"OpenSauceIDE:ColladaBuilder",
				"meter", 0.0254, Enums.ColladaUpAxisEnum.Z_UP);

			CreateGeometryList();
			CreateNodeList();

			AddLibraryGeometries();
			AddLibraryVisualScenes();
			AddScene("main");

			return true;
		}
Exemple #9
0
		protected override bool BuildColladaInstanceImpl()
		{
			COLLADAFile = new ColladaFile();

			COLLADAFile.Version = "1.4.1";
			AddAsset(
				System.Environment.UserName,
				"OpenSauceIDE:ColladaBuilder",
				"meter", 0.0254, Enums.ColladaUpAxisEnum.Z_UP);

			if (bspInfo.IncludeRenderMesh())
			{
				CollectBitmaps();

				CreateImageList();
				CreateEffectList();
				CreateMaterialList();
			}
			
			if(bspInfo.IncludePortalsMesh())
			{
				CreateEffectListPortals();
				CreateMaterialListPortals();
			}

			CreateGeometryList();
			CreateNodeList();
			CreateMarkerList();

			AddLibraryImages();
			AddLibraryEffects();
			AddLibraryMaterials();
			AddLibraryGeometries();
			AddLibraryVisualScenes();
			AddScene("main");

			return true;
		}
		protected override bool BuildColladaInstanceImpl()
		{
			// reset and repopulate the collada file
			COLLADAFile = new ColladaFile();

			COLLADAFile.Version = "1.4.1";
			AddAsset(
				System.Environment.UserName,
				"OpenSauceIDE:ColladaBuilder",
				"meter", 0.0254, Enums.ColladaUpAxisEnum.Z_UP);

			mModelDataProvider = GetDataProvider<IHalo1ModelDataProvider>();

			CreateBoneList();
			CreateMarkerList();
			CreateGeometryList();
			CreateControllerList();
			CreateNodeList();

			CreateImageList();
			CreateEffectList();
			CreateMaterialList();

			AddLibraryImages();
			AddLibraryEffects();
			AddLibraryMaterials();
			AddLibraryGeometries();
			AddLibraryControllers();
			AddLibraryVisualScenes();
			AddScene("main");

			COLLADAFile.Validate();

			return true;
		}
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>	Collate's the lightmap geometry from a COLLADA file into a usable format. </summary>
        ///
        /// <param name="colladaFile">	The collada file. </param>
        ///
        /// <returns>	A list of lightmap mesh data. </returns>
        List <Lightmap> CollateLightmapGeometry(ColladaFile colladaFile)
        {
            var lightmapMeshes = new List <Lightmap>();

            // Collect the geometry info
            foreach (var geometry in colladaFile.LibraryGeometries.Geometry)
            {
                if (geometry.Mesh == null)
                {
                    SendMessage(String.Format("The geometry {0} does not have a mesh", geometry.Name));
                    return(null);
                }

                if (geometry.Mesh.Triangles.Count == 0)
                {
                    SendMessage(String.Format("The geometry {0} has no triangles", geometry.Name));
                    return(null);
                }

                // Get the lightmap index from the end of the geometry name
                if (geometry.Name.EndsWith("-1"))
                {
                    continue;
                }

                var indexString = Regex.Match(geometry.Name, @"\d+$").Value;
                if (System.String.IsNullOrEmpty(indexString))
                {
                    SendMessage(String.Format("The geometry {0} does not have the lightmap index at the end of it's name", geometry.Name));
                    return(null);
                }
                int lightmapIndex = Int32.Parse(indexString);

                // Create the lightmap entry
                var lightmap = new Lightmap()
                {
                    LightmapIndex = lightmapIndex, Faces = new List <Lightmap.Face>()
                };

                foreach (var triangles in geometry.Mesh.Triangles)
                {
                    // Get the input object containing the texture coordinates
                    var texcoord1Input = triangles.Input.Find(entry => (entry.Set == 1) && (entry.Semantic == ColladaInputSharedSemantic.TEXCOORD));
                    if (texcoord1Input == null)
                    {
                        SendMessage(String.Format("Unable to find a second texture coordinate for geometry {0}", geometry.Name));
                        return(null);
                    }
                    var sourceID = texcoord1Input.Source.TrimStart('#');

                    // Get the source array for the coord data
                    var sourceArray = geometry.Mesh.Source.Find(
                        entry =>
                    {
                        return(entry.ID.EndsWith(sourceID));
                    }
                        );

                    if (sourceArray == null)
                    {
                        SendMessage(String.Format("Unable to find a texture coordinate source array for geometry {0}", geometry.Name));
                        return(null);
                    }

                    if (sourceArray.FloatArray == null)
                    {
                        SendMessage(String.Format("Unable to find a texture coordinate source array for geometry {0}", geometry.Name));
                        return(null);
                    }

                    // Collect the vertex data
                    int sourceArrayStride = (int)sourceArray.TechniqueCommon.Accessor.Stride;
                    var indexStride       = (triangles.P.Values.Count / 3) / (int)triangles.Count;

                    foreach (var faceIndex in Enumerable.Range(0, (int)triangles.Count))
                    {
                        var face = new Lightmap.Face();

                        // Get the index of the texture coordinates for the face vertices
                        int faceOffset = (indexStride * 3) * faceIndex;                         // Offset to start of current face

                        int vertex0Offset = faceOffset + (0 * indexStride) + (int)texcoord1Input.Offset;
                        int vertex1Offset = faceOffset + (1 * indexStride) + (int)texcoord1Input.Offset;
                        int vertex2Offset = faceOffset + (2 * indexStride) + (int)texcoord1Input.Offset;

                        int vertex0Index = triangles.P.Values[vertex0Offset];
                        int vertex1Index = triangles.P.Values[vertex1Offset];
                        int vertex2Index = triangles.P.Values[vertex2Offset];

                        // Get the data from the float array
                        int uIndex = (vertex0Index * sourceArrayStride);
                        int vIndex = (vertex0Index * sourceArrayStride) + 1;
                        face.Vertex0.X = sourceArray.FloatArray.Values[uIndex];
                        face.Vertex0.Y = (sourceArray.FloatArray.Values[vIndex] - 1) * -1;

                        uIndex         = (vertex1Index * sourceArrayStride);
                        vIndex         = (vertex1Index * sourceArrayStride) + 1;
                        face.Vertex1.X = sourceArray.FloatArray.Values[uIndex];
                        face.Vertex1.Y = (sourceArray.FloatArray.Values[vIndex] - 1) * -1;

                        uIndex         = (vertex2Index * sourceArrayStride);
                        vIndex         = (vertex2Index * sourceArrayStride) + 1;
                        face.Vertex2.X = sourceArray.FloatArray.Values[uIndex];
                        face.Vertex2.Y = (sourceArray.FloatArray.Values[vIndex] - 1) * -1;

                        lightmap.Faces.Add(face);
                    }
                }

                lightmapMeshes.Add(lightmap);
            }

            return(lightmapMeshes);
        }
Exemple #12
0
        static void Main(string[] args)
        {
            if (args.Length == 0 || args[0] == "-h")
            {
                printHelp();
                return;
            }
            List <string> fileList = new List <string>();
            FileInfo      dest     = null;
            string        format   = "";

            var settings = Settings.None;


            for (int i = 0; i < args.Length; i++)
            {
                string arg = args[i];
                if (arg.StartsWith("-") || arg.Length == 1)
                {
                    var option = arg.Last();
                    // Handle as argument
                    switch (option)
                    {
                    case 'o':
                        if (i + 1 >= args.Length)
                        {
                            Console.Error.WriteLine("No value for {0}", arg);
                            printHelp();
                            return;
                        }

                        string path = args[++i];
                        int    idx  = path.LastIndexOf('.');
                        if (idx >= 0)
                        {
                            if (format == "")
                            {
                                format = path.Substring(idx + 1);
                            }
                            path = path.Substring(0, idx);
                        }
                        dest = new FileInfo(path);

                        break;

                    case 'h':
                        printHelp();
                        return;

                    case 'u':
                        settings |= Settings.Compatibility;
                        break;

                    case 'b':
                        settings |= Settings.Skin;
                        break;

                    case 's':
                        settings |= Settings.SliceAnimations;
                        break;

                    case 'm':
                        settings |= Settings.Morphs;
                        break;

                    case 'a':
                        settings |= Settings.Animations | Settings.Skin;
                        break;

                    case 'c':
                        settings |= Settings.Merge;
                        break;

                    case 'f':
                        if (i + 1 >= args.Length)
                        {
                            Console.Error.WriteLine("No value for {0}", arg);
                            printHelp();
                            return;
                        }
                        format = args[++i];
                        if (format != "dae" && format != "obj")
                        {
                            Console.Error.WriteLine("Invalid format: {0}", format);
                            printHelp();
                            return;
                        }

                        break;

                    default:
                        Console.Error.WriteLine("Unknown option {0}", arg);
                        printHelp();
                        return;
                    }
                }
                else
                {
                    // Handle as input file
                    var info = new FileInfo(arg);
                    if (info.Exists)
                    {
                        if (arg.EndsWith(".anz"))
                        {
                            fileList.Add(info.FullName);

                            if (dest == null)
                            {
                                dest = new FileInfo(info.FullName.Replace(".anz", ""));
                            }
                        }
                        else
                        {
                            Console.Error.WriteLine("File {0} is not an *.anz file.", arg);
                        }
                    }
                    else
                    {
                        Console.Error.WriteLine("Could not find file {0}", arg);
                    }
                }
            }
            if (settings == Settings.None)
            {
                settings = Settings.All;
            }

            //   settings = Settings.Animations | Settings.SliceAnimations | Settings.Compress;

            if (format == "")
            {
                format = "dae";
            }

            dest = new FileInfo(dest.FullName + "." + format);

            IConvertTarget target;

            if (format == "dae")
            {
                target = new ColladaFile();
            }
            else
            {
                target = new ObjFile();
            }

            target.Options = settings;

            int processed = 0;

            foreach (var file in fileList)
            {
                var anz = ANZFile.FromFile(file);
                if (!anz.HasAnimation || anz.Anims.Any(a => a.Objects == null || a.Objects.All(o => o.Name == null)))
                {
                    Console.WriteLine("{0}: mesh", file);

                    target.AddMesh(anz);
                    processed++;
                }
                else if (target is IMotionSupport)
                {
                    Console.WriteLine("{0}: anim", file);


                    ((IMotionSupport)target).AddMotion(anz);
                    processed++;
                }
                else
                {
                    Console.Error.WriteLine("{0} does not support animations. Skipping: {1}", format, file);
                }
            }

            if (processed > 0)
            {
                target.Save(dest.FullName);
            }
            else
            {
                Console.Error.WriteLine("Got nothing to do...");
            }
        }