public static AudioStreamSample GetSoundClip(int idx) { AudioStreamSample result = _vswapSound.ContainsKey(idx) ? _vswapSound[idx] : null; if (result == null) { byte[] data = VSWAP.GetSoundData((uint)idx); if (data != null && data.Length > 0) { for (int i = 0; i < data.Length; i++) { unchecked { data[i] -= 0x80; } } result = new AudioStreamSample(); result.Format = AudioStreamSample.FormatEnum.Format8Bits; result.MixRate = SoundSampleRate; result.LoopMode = AudioStreamSample.LoopModeEnum.Disabled; result.Data = data; } } return(result); }
public static Material GetSprite(int idx) { Material ret = _vswapSprite.ContainsKey(idx) ? _vswapSprite[idx] : null; if (ret == null) { byte[] data = new byte[VSWAP.SpriteSize.Width * VSWAP.SpriteSize.Height * 4]; SpatialMaterial mat = new SpatialMaterial(); ImageTexture tex = new ImageTexture(); Image img = new Image(); System.Drawing.Bitmap bmp = VSWAP.GetSpriteBitmap(Palette, (uint)idx); int stride = VSWAP.SpriteSize.Width * 4; for (int y = 0; y < VSWAP.SpriteSize.Height; y++) { for (int x = 0; x < VSWAP.SpriteSize.Width; x++) { System.Drawing.Color pixel = bmp.GetPixel(x, y); data[(stride * y) + (x * 4) + 0] = pixel.R; data[(stride * y) + (x * 4) + 1] = pixel.G; data[(stride * y) + (x * 4) + 2] = pixel.B; if (pixel.R == Transparent.r8 && pixel.G == Transparent.g8 && pixel.B == Transparent.b8) { data[(stride * y) + (x * 4) + 3] = 0; } else { data[(stride * y) + (x * 4) + 3] = 255; } } } img.CreateFromData( VSWAP.SpriteSize.Width, VSWAP.SpriteSize.Height, false, Image.Format.Rgba8, data); tex.CreateFromImage(img, (uint)0); mat.AlbedoTexture = tex; mat.ParamsCullMode = SpatialMaterial.CullMode.Disabled; mat.ParamsBillboardMode = SpatialMaterial.BillboardMode.FixedY; ret = mat; _vswapSprite.Add(idx, ret); } return(ret); }
public static Material GetTexture(int idx) { Material ret = _vswapTexture.ContainsKey(idx) ? _vswapTexture[idx] : null; if (ret == null) { byte[] data = new byte[VSWAP.TextureSize.Width * VSWAP.TextureSize.Height * 4]; SpatialMaterial mat = new SpatialMaterial(); ImageTexture tex = new ImageTexture(); Image img = new Image(); System.Drawing.Bitmap bmp = VSWAP.GetTextureBitmap(Palette, (uint)idx); int stride = VSWAP.TextureSize.Width * 4; for (int y = 0; y < VSWAP.TextureSize.Height; y++) { for (int x = 0; x < VSWAP.TextureSize.Width; x++) { System.Drawing.Color pixel = bmp.GetPixel(x, y); data[(stride * y) + (x * 4) + 0] = pixel.R; data[(stride * y) + (x * 4) + 1] = pixel.G; data[(stride * y) + (x * 4) + 2] = pixel.B; data[(stride * y) + (x * 4) + 3] = 255; } } img.CreateFromData( VSWAP.TextureSize.Width, VSWAP.TextureSize.Height, false, Image.Format.Rgba8, data); tex.CreateFromImage(img, (uint)Texture.FlagsEnum.Repeat); mat.AlbedoTexture = tex; mat.ParamsCullMode = SpatialMaterial.CullMode.Back; ret = mat; _vswapTexture.Add(idx, ret); } return(ret); }