Пример #1
0
        /// <summary>
        /// Imports a model from the given file.
        /// </summary>
        /// <param name="sourceFile">The source file to be loaded.</param>
        /// <param name="importOptions">Some configuration for the importer.</param>
        public ImportedModelContainer ImportModel(ResourceLink sourceFile, ImportOptions importOptions)
        {
            // Get import options
            ObjImportOptions objImportOptions = importOptions as ObjImportOptions;

            if (objImportOptions == null)
            {
                throw new SeeingSharpException("Invalid import options for ACImporter!");
            }

            ImportedModelContainer result = new ImportedModelContainer(objImportOptions);

            // Read object file
            ObjFileReader objFileReader = new ObjFileReader(sourceFile, result, objImportOptions);

            objFileReader.Read();
            objFileReader.GenerateObjects();

            return(result);
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ObjFileReader"/> class.
        /// </summary>
        /// <param name="resource">The resource to be loaded.</param>
        /// <param name="targetContainer">The target ModelContainer into which to put the generated objects and resources.</param>
        /// <param name="importOptions">Current import settings.</param>
        public ObjFileReader(ResourceLink resource, ImportedModelContainer targetContainer, ObjImportOptions importOptions)
        {
            resource.EnsureNotNull(nameof(resource));
            targetContainer.EnsureNotNull(nameof(targetContainer));
            importOptions.EnsureNotNull(nameof(importOptions));

            m_resource        = resource;
            m_targetContainer = targetContainer;
            m_importOptions   = importOptions;

            m_rawVertices           = new List <Vector3>(1024);
            m_rawNormals            = new List <Vector3>(1014);
            m_rawTextureCoordinates = new List <Vector2>(1024);
            m_targetVertexStructure = new VertexStructure();

            // Apply transform matrix in case of a different coordinate system (switched coordinate axes)
            Matrix4x4 coordSpaceTransformMatrix = importOptions.GetTransformMatrixForCoordinateSystem();

            if (coordSpaceTransformMatrix != Matrix4x4.Identity)
            {
                m_targetVertexStructure.EnableBuildTimeTransform(coordSpaceTransformMatrix);
            }
        }