I made a tiled dancefloor mesh with a dynamic size at runtime in C#. No prefabs. Everything is working but I'm loading a 128x128 tile texture using:
https://docs.unity3d.com/530/Documentation/ScriptReference/Texture2D.LoadRawTextureData.html
... and the data is coming from a huge hardcoded byte[] array. It's 128x128x3 => 49.152 bytes.
It works, but it's just an ugly workaround.
I cannot figure out how to load from a png-file to a texture in C# properly.
Is it even possible to load png-texture directly? Or is it blocked too for security reasons?
Where do have to put the png? All Unity guides seem to assume there is an Assets/Resource-folder - VAM has no such thing?! Maybe VaM\Custom\Assets ?
Or do I have to create an AssetBundle? I've create one with a single .mat but don't know how to load it from C# in VAM. Also I'm not sure the .assetbundle was created correctly, because the file had no extension - so I added it. Tried to load on a CUA-atom - did not show any content. But that seems to be build for other content anyway.
It's super easy to get things working in the UnityEditor, but VAM is a blackbox.
A path- and name-list of all texture, materials and shaders from a clean VAM install would help too. There is probably already a good texture somewhere that I could use ... if I figure out how to set it to my Material. I don't want the plugin that I'm working on to be bloated with unnecessary resources.
Btw. I also tried to load a raw DXT1 compressed texture to reduce the size of the byte[]-array. It does work, but has textures glitches. Probably because I used a sketchy online converter to get the DXT1 data from a PNG. That thing returned a DDS file. So I guess it is not raw DXT, it's still inside a container maybe.
EDIT:
Manages to load raw DXT1 compressed data without glitches now. This time I exported the image with GIMP to DDS without mipmaps. The I removed the first 4 bytes - it is the ".dds" containers magic number to identify the fileformat. Then I removed another 124 bytes - that is the size of the DDS header. Size is down to 8192 bytes. The compression is noticeable though. Quality is worse.
https://docs.unity3d.com/530/Documentation/ScriptReference/Texture2D.LoadRawTextureData.html
Code:
Texture2D tex = new Texture2D(128, 128, TextureFormat.RGB24, false);
tex.LoadRawTextureData(rawrgb24Texture);
- open image in Gimp -> export by changing the extension to .raw and a popup will ask you about the format
- open your browser and go to https://hexed.it/ - that's an online hexeditor
- open file -> pick your exported .raw
- right click -> select all
- right click -> Export selected bytes as code snipped ...
- copy the Code Snippet to C# and fix the byte-array declaration to match the C# syntax
I cannot figure out how to load from a png-file to a texture in C# properly.
Is it even possible to load png-texture directly? Or is it blocked too for security reasons?
Where do have to put the png? All Unity guides seem to assume there is an Assets/Resource-folder - VAM has no such thing?! Maybe VaM\Custom\Assets ?
Or do I have to create an AssetBundle? I've create one with a single .mat but don't know how to load it from C# in VAM. Also I'm not sure the .assetbundle was created correctly, because the file had no extension - so I added it. Tried to load on a CUA-atom - did not show any content. But that seems to be build for other content anyway.
It's super easy to get things working in the UnityEditor, but VAM is a blackbox.
A path- and name-list of all texture, materials and shaders from a clean VAM install would help too. There is probably already a good texture somewhere that I could use ... if I figure out how to set it to my Material. I don't want the plugin that I'm working on to be bloated with unnecessary resources.
EDIT:
Manages to load raw DXT1 compressed data without glitches now. This time I exported the image with GIMP to DDS without mipmaps. The I removed the first 4 bytes - it is the ".dds" containers magic number to identify the fileformat. Then I removed another 124 bytes - that is the size of the DDS header. Size is down to 8192 bytes. The compression is noticeable though. Quality is worse.
C#:
public static byte[] dancefloorTileDXT1 = {
// MAGIC NUMBER ".dds" 4 bytes https://en.wikipedia.org/wiki/DirectDraw_Surface
//0x44, 0x44, 0x53, 0x20,
// DDS HEADER 124 bytes https://docs.microsoft.com/en-us/windows/win32/direct3ddds/dds-header
//0x7C, 0x00, 0x00, 0x00, 0x07, 0x10, 0x08, 0x00, 0x80, 0x00, 0x00, 0x00,
//0x80, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
//0x01, 0x00, 0x00, 0x00, 0x47, 0x49, 0x4D, 0x50, 0x2D, 0x44, 0x44, 0x53,
//0x5B, 0x09, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
//0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
//0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
//0x20, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x44, 0x58, 0x54, 0x31,
//0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
//0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
//0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
//0x00, 0x00, 0x00, 0x00,
// HEADER END - RAW DXT1 DATA START
0x00, 0x00, 0x00, 0x00, 0xAA, 0xAA, 0xAA, 0xAA,
0x00, 0x00, 0x00, 0x00, 0xAA, 0xAA, 0xAA, 0xAA, 0x00, 0x00, 0x00, 0x00,
// had to remove data to be able to post this (20000 characters limit)
};
Last edited: