Beispiel #1
0
        public override Texture Load(IResource resource, LoaderParameters parameters)
        {
            Stream       stream = resource.OpenStream();
            BinaryReader input  = new BinaryReader(stream);

            DDSImageInfo image = ReadHeaderInfo(input);

            SurfaceFormat     format     = DetermineFormat(image);
            TextureDimensions dimensions = DetermineTextureDimensions(image);

            switch (dimensions)
            {
            case TextureDimensions.Two:
                Texture2D tex2d = LoadTexture2D(image, input, format);
                tex2d.Name = resource.Name;
                input.Close();
                return(tex2d);

            case TextureDimensions.Three:
                Texture3D tex3d = LoadTexture3D(image, input, format);
                tex3d.Name = resource.Name;
                input.Close();
                return(tex3d);

            case TextureDimensions.Cube:
                TextureCube texcube = LoadTextureCube(image, input, format);
                texcube.Name = resource.Name;
                input.Close();
                return(texcube);

            default:
                input.Close();
                throw new InvalidOperationException("Error loading DDS file");
            }
        }
Beispiel #2
0
        /// <summary>
        /// Load the DXS model. If the model is a single mesh, Mesh will
        /// be returned. Otherwise Node will be returned.
        /// </summary>
        /// <param name="resource">Dxs resource</param>
        /// <param name="parameters">Model loader parameters, must be of type ModelLoaderParameters otherwise it's ignored.</param>
        /// <returns>The model</returns>
        public override Spatial Load(IResource resource, LoaderParameters parameters)
        {
            _parser.Reset();

            ModelLoaderParameters modelParams = parameters as ModelLoaderParameters;

            if (modelParams == null)
            {
                modelParams = _defaultParams;
            }

            DxsNode dxsModel;

            using (Stream stream = resource.OpenStream()) {
                dxsModel = _parser.Parse(stream, resource.Name);
            }

            Node root = new Node(dxsModel.Name);

            foreach (DxsNode node in dxsModel.Children)
            {
                ParseDxsTree(node, root, modelParams);
            }

            if (root.Count == 1 && root[0] is Mesh)
            {
                Spatial s = root[0];
                s.RemoveFromParent();
                return(s);
            }

            return(root);
        }
Beispiel #3
0
        /// <summary>
        /// Loads the specified resource.
        /// </summary>
        /// <param name="resource">The resource to load.</param>
        /// <param name="parameters">Loader parameters.</param>
        /// <returns>The loaded MaterialCollection</returns>
        public override MaterialCollection Load(IResource resource, LoaderParameters parameters)
        {
            if (_parser == null)
            {
                _parser = new MaterialParser(ContentManager);
            }

            return(_parser.LoadAllMaterials(resource, parameters));
        }
Beispiel #4
0
        protected TExpectedType ValidateParameterType <TExpectedType>(LoaderParameters parameters)
            where TExpectedType : LoaderParameters
        {
            if (!(parameters is TExpectedType aParameters))
            {
                throw new Exception($"{nameof(LoaderParameters)} are of the wrong type: {parameters.GetType().Name}");
            }

            return(aParameters);
        }
Beispiel #5
0
        public override Texture Load(IResource resource, LoaderParameters parameters)
        {
            ImageLoaderParameters imageParams = parameters as ImageLoaderParameters;

            if (imageParams == null)
            {
                imageParams = new ImageLoaderParameters();
            }

            return(m_translator.Load(resource, m_imageType, imageParams));
        }
Beispiel #6
0
 public override Object Load(IResource resource, Type type, LoaderParameters parameters)
 {
     if (type.Equals(this.TargetType))
     {
         return(Load(resource, parameters));
     }
     else
     {
         throw new InvalidCastException("Invalid type to load, must be an Effect.");
     }
 }
Beispiel #7
0
        /// <summary>
        /// Loads the specified resource.
        /// </summary>
        /// <param name="resource">The resource to load</param>
        /// <param name="parameters">Loader parameters</param>
        /// <returns>The loaded resource</returns>
        public override Spatial Load(IResource resource, LoaderParameters parameters)
        {
            ModelLoaderParameters modelParams = parameters as ModelLoaderParameters;

            if (modelParams == null)
            {
                modelParams = new ModelLoaderParameters();
            }

            return(m_translator.Load(resource, base.Extension, modelParams));
        }
Beispiel #8
0
        /// <summary>
        /// Loads the specified resource.
        /// </summary>
        /// <param name="resource">The resource to load</param>
        /// <param name="parameters">Any loading parameters</param>
        /// <exception cref="System.IO.InvalidDataException">Thrown if the stream does not contain a valid TEBO file.</exception>
        /// <returns>The loaded resource</returns>
        public override ISavable Load(IResource resource, LoaderParameters parameters)
        {
            //Read header
            Stream stream = resource.OpenStream();

            if (!ReadHeader(stream))
            {
                throw new InvalidDataException("Invalid binary file, either it is not a tesla engine binary object or the version is not compatible.");
            }

            BinarySavableReader reader  = new BinarySavableReader(stream, ContentManager);
            ISavable            savable = reader.ReadSavable <ISavable>();

            reader.Dispose();
            return(savable);
        }
Beispiel #9
0
        public override Texture Load(IResource resource, LoaderParameters parameters)
        {
            Stream str = resource.OpenStream();

            SD.Bitmap bitmap = new SD.Bitmap(str);

            ImageLoaderParameters imageParams = parameters as ImageLoaderParameters;

            if (imageParams != null)
            {
                if (imageParams.FlipImage)
                {
                    bitmap.RotateFlip(SD.RotateFlipType.RotateNoneFlipY);
                }
            }

            byte[] data = GetData(bitmap);
            SD.Imaging.PixelFormat pixelFormat = bitmap.PixelFormat;
            Color[] colors = null;
            switch (pixelFormat)
            {
            case SD.Imaging.PixelFormat.Format32bppArgb:
                colors = GetRGBA(bitmap, data);
                break;

            case SD.Imaging.PixelFormat.Format24bppRgb:
                colors = GetRGB(bitmap, data);
                break;

            case SD.Imaging.PixelFormat.Format8bppIndexed:
                colors = GetIndexed(bitmap, data);
                break;

            default:
                throw new InvalidOperationException("Cannot read from that format encoding");
            }

            Texture2D tex = new Texture2D(bitmap.Width, bitmap.Height, true, SurfaceFormat.Color, new DataBuffer <Color>(colors));

            tex.Name = resource.Name;

            bitmap.Dispose();
            str.Close();

            return(tex);
        }
Beispiel #10
0
        /// <summary>
        /// Loads an Effect from the resource.
        /// </summary>
        /// <param name="resource">Resource that references the FX file</param>
        /// <param name="parameters">Loader parameters</param>
        /// <returns>Compiled effect</returns>
        public override Effect Load(IResource resource, LoaderParameters parameters)
        {
            EffectInclude include = new EffectInclude(ContentManager, Path.GetDirectoryName(resource.FullName));

            D3DC.ShaderBytecode byteCode = D3DC.ShaderBytecode.CompileFromFile(resource.FullName, "fx_4_0", D3DC.ShaderFlags.None, D3DC.EffectFlags.None, null, include);
            byte[]        bytes          = new byte[byteCode.Data.Length];
            System.IntPtr ptr            = Tesla.Util.MemoryHelper.PinObject(bytes);
            Tesla.Util.MemoryHelper.Copy(byteCode.Data.DataPointer, ptr, bytes.Length);
            Tesla.Util.MemoryHelper.UnpinObject(bytes);
            byteCode.Dispose();

            Effect e = new Effect(bytes);

            e.Name = resource.Name;

            return(e);
        }
        protected override void Load(LoaderParameters parameters)
        {
            var tParameters = ValidateParameterType <AddressableLoaderParameters>(parameters);

            switch (tParameters.behaviour)
            {
            case LoaderBehaviour.Asset:
            {
                LoadAsset();
                break;
            }

            case LoaderBehaviour.Scene:
            {
                LoadSceneAsync(tParameters);
                break;
            }
            }
        }
Beispiel #12
0
        public override Effect Load(IResource resource, LoaderParameters parameters)
        {
            FileInfo info = new FileInfo(resource.FullName);

            if (!info.Exists)
            {
                throw new FileNotFoundException("Effect file does not exist in directory");
            }
            EffectContent content = new EffectContent();

            content.Identity   = new ContentIdentity(resource.FullName);
            content.EffectCode = File.ReadAllText(resource.FullName);

            CompiledEffectContent compiled = _processor.Process(content, _xnaContext);

            Effect effect = new Effect(compiled.GetEffectCode());

            effect.Name = resource.Name;
            return(effect);
        }
Beispiel #13
0
        protected override void Load(LoaderParameters parameters)
        {
            status = ContentAsyncStatus.Loading;

            if (!ValidateLoadOperation(parameters))
            {
                status = ContentAsyncStatus.Failed;

                OnLoadCompleted();
                return;
            }

            var job = GetLoadJob(parameters);

            if (job == null)
            {
                status = ContentAsyncStatus.Failed;
                return;
            }

            handler.Schedule(this, job);
        }
        protected override void Unload(LoaderParameters parameters)
        {
            if (!(parameters is AddressableLoaderParameters aParameters))
            {
                throw new Exception($"{nameof(LoaderParameters)} are of the wrong type: {parameters.GetType().Name}");
            }

            switch (aParameters.behaviour)
            {
            case LoaderBehaviour.Asset:
            {
                UnloadAsset();
                break;
            }

            case LoaderBehaviour.Scene:
            {
                UnloadSceneAsync();
                break;
            }
            }
        }
        protected override LoadJob GetLoadJob(LoaderParameters parameters)
        {
            this.parameters = ValidateParameterType <LocalLoaderParameters>(parameters);
            switch (this.parameters.format)
            {
            case LocalAssetFormat.Byte:
            {
                return(new ReadAllBytes(contentPath.FileInfo.FullName));
            }

            case LocalAssetFormat.Text:
            {
                return(new ReadAllText(contentPath.FileInfo.FullName));
            }

            case LocalAssetFormat.Lines:
            {
                return(new ReadAllLines(contentPath.FileInfo.FullName));
            }
            }

            return(null);
        }
Beispiel #16
0
        public override SpriteFont Load(IResource resource, LoaderParameters parameters)
        {
            document.RemoveAll();
            document.Load(resource.OpenStream());

            XmlNode fontNode = GetFontNode();

            XmlNode charsNode;
            XmlNode kerningsNode;
            String  texturePath;
            int     lineHeight;

            GetFontData(fontNode, out texturePath, out lineHeight, out charsNode, out kerningsNode);

            Texture2D texture     = ContentManager.LoadRelativeTo <Texture2D>(texturePath, resource);
            Glyph?    defaultChar = GetDefaultCharacter(texture, charsNode);

            SpriteFont spriteFont;

            if (defaultChar.HasValue)
            {
                spriteFont = new SpriteFont(texture, lineHeight, defaultChar.Value);
            }
            else
            {
                spriteFont = new SpriteFont(texture, lineHeight);
            }

            GetCharacters(spriteFont, charsNode);
            if (kerningsNode != null)
            {
                GetKernings(spriteFont, kerningsNode);
            }

            return(spriteFont);
        }
Beispiel #17
0
 protected abstract LoadJob GetLoadJob(LoaderParameters parameters);
Beispiel #18
0
 protected virtual bool ValidateLoadOperation(LoaderParameters parameters)
 {
     return(contentPath.FileInfo.Exists);
 }
 protected override void Unload(LoaderParameters parameters)
 {
     byteData  = null;
     textData  = null;
     linesData = null;
 }
Beispiel #20
0
 public void SetLoadContextParameters(LoaderParameters parameters)
 {
     this.parameters = parameters;
 }