Setting Alpha on a volume

0
arknano posted this 16 January 2017

Hi there, I'm working with qubicle (which lacks an alpha channel) and would like to be able to set the colour of all voxels in a volume to 0 alpha, for the purposes of using the emissive material on them, since painting them all manually every time I reimport is a drag.

I was hoping you'd be able to point me in the right direction to create an editor script to do this? I've got no idea where to start with the PicaVoxel code.

Thanks for your time!

6 Comments
Order By: Standard | Newest | Votes
0
GarethIW posted this 16 January 2017

Hey!

The absolute simplest way of doing this would be to make the alpha value 0 on the importer.

The Qubicle importer code is located in PicaVoxel/Scripts/Editor/QubicleImporter.cs

The line you need is number 252 in the UIntToColor function:

        return new Color32(r, g, b, 255);

The last value is the alpha value.

A more flexible option would be to add a new field for alpha to QubicleImportWindow.cs, and pass that through into the importer in the same way that I pass the voxelSize value. If you did this, there would be a bit of extra work to support re-importing as well.

Last edited 16 January 2017

0
arknano posted this 16 January 2017

Thanks for the quick reply Gareth!

The issue with doing it on the importer is that .qb files that I'm importing have both things that should be emissive and things that shouldn't; I separate the matrices in Qubicle to simplify working with them in PicaVoxel as separate volumes.

What I'd like to be able to do is have a button on an editor script that gives me a button to set all voxels in that volume to 0 alpha, or something similar. I can work out the inspector coding side of things, the problem is I have no idea where to start to access the colours of voxels within a volume!

Thanks again.

0
GarethIW posted this 16 January 2017

Ah okay, fair enough.

That's pretty simple then. The voxels are kept in an array on the Frame class. Assuming you only have one animation frame, that would be:

GetComponent<Volume>().Frames[0].Voxels

The array is one dimensional, so you can easily iterate over it to change the colours:

(Off the top of my head, so let me know if you have problems!)

Ugh, you know what - I'm just going to put this in a gist because the forum code formatting simply doesn't like squirly braces:

https://gist.github.com/GarethIW/08918287f4a798c3b85c6220c782c8af

Last edited 16 January 2017

0
GarethIW posted this 16 January 2017

There are also helper methods on the volume class for doing operations on single voxels:

Voxel? v = Volume.GetVoxelAtArrayPosition(x,y, z);  // get the voxel at an x,y,z array position

v.State // active, inactive, hidden
v.Colour // the colour of the voxel
v.Value // byte value that you can use for whatever you need

Volume.SetVoxelAtArrayPosition(x, y, z, v); // set voxel at array position

Last edited 16 January 2017

0
arknano posted this 16 January 2017

Heh, turns out I should have refreshed this page before going off to fix it myself! Took a bit of trial and error but I feel like I understand PicaVoxel a little better now, so it wasn't a total waste of time haha!

I'm attaching (read: linking) a unitypackage file that includes my implementation for others to use should they wish, as well as gists if you're just curious.

Thanks a ton for your help Gareth, the already great price of PicaVoxel is made even more bargain by your willingness to go out of your way to help out!


unitypackage download

SetVolumeAlpha.cs (gist)

SetVolumeAlphaEditor.cs (gist)

Last edited 16 January 2017

0
GarethIW posted this 16 January 2017

Sweet, nice and simple!


Our 282 members have posted 390 times in 91 discussions