- Home /
Generating a pixelmodel from scripts.
Hey guys.
Im working on a little project, where all models are in a pixel art style (a lot like cube world). I'm not very good at 3D modelling, so I got an idea that might work. Is it possible to construct the models via scripting in unity? The way I thought it might works is as follows:
The model would lie in a form of data. XML or something. Like coordinates for all the blocks, that the pixel-model would consist of. Then there would be a model in the unity game, of a cube. Then the scripting would generate the model, by instantiating cubes and connecting them, attach it to a skeleton somehow, attach textures and such, and then let that be the model of the character.
Another idea i have for this little game (1 vs 1 duel arena), is if it would be possible to animate, that if a character was hit on the arm, the cubes forming the arm would break off, and the player would be an amputee.
If it isnt possible to do it this way, does anyone know of a piece of software, that lets me draw 3d pixelart, much like qubicle, export it as a 3d model and import it into blender? preferably something free?
Answer by MountDoomTeam · Jan 04, 2013 at 08:54 PM
Hello! Great question! Pixel-model is basically a pixel-Sprite made from blocky pixels same as a Commodore game.-For others that wonder-
I would guess that the code you are after ... would be about 30 or 50 lines of forensically collated code, quite complicated code!it's part of a domain that I'm very interested in, using data from different emulations and different sources and converting it inside unity so that have a lot of cheap easy pretty unity content that you don't have to make in so much time.
I wouldn't use XML, just use pictures, there is a command in unity called getPixel http://docs.unity3d.com/Documentation/ScriptReference/Texture2D.GetPixel.html
So what you can do, is search all the pixels one by one, or every 10 pixels, depending on the size of the picture you are working from, get the colour of it, and make a cube in the middle of the game with the correct relative position and colour of the getpixel.
You can also put in a command which says if pixel is white, don't make a cube.
To begin with, you can just use "set texture colour" unity command- which sets the texture colour RGB of the cube in one line without having to do any other texture material stuff to it.
That basically covers it.
By this time you will find you have 10 lines of code only-that can take any picture and make a pixel model out of it
You could actually just feed simple pictures of cartoon characters and it would only sample every 10 pixels, or you could get proper little sprites and sample every pixel, which would be more stylised.
Afterwards, you will want to combine the cubes into one model using-combine children extended version, which is somewhere on the unity forums
and then you will also want to use export object script, which basically lets you export something we have made in playtime as a fully coloured nice file that you can use as a prefab.
By this time you will have about 15 lines and some extra scripts.
To make unity running efficiently, you'll have to learn a complicated trick-you have to give all the cubes only one texture, the texture of a colour chart, and the have to modify the cube UVs says they are equal to only one pixel, for example if you want to bluecube you have to set the UVs to all equals .443 on the colour chart. and all the cube will be blue. This means that you can have 50 or 100 cubes using only one model and one texture, which makes the 50 or 100 times more efficient, I had to find all this out myself, if I do get the script's I put together to do it I can post them online, basically I found it piece by piece from the forum. Good luck!
if you wanted to draw inside unity, there were maybe already some free drawing demo programs or cheap asset store things,what you want to do is just use the code which selects the colour and puts it on objects, use it to colour a Grid of 100 X 100 cubes, and then just go into edit mode and delete the ones which aren't coloured.
to get the colour of a pixel you select with the mouse, and apply it to the texture of the cube, it only takes about 20 lines if you know how to code it!
that's why you have to learn coding! Like that any time you need to do something like that, you will do it in 2 or 3 hours.
That sounds brilliant. So basically I'll be making a script that will generate the 3D model, and then export it at runtime. Then when that is done, I can (outside of runtime) attach a skeleton to the exported 3D model? Or can I do that at runtime as well? Or will I have to have a "blank" 3D model with a skeleton, and then attach the cubes to that skeleton?
Yes, maybe the easiest is work on 90 x 90 pixel pictures and zoomed in really big, and then just get each pixel and converted to a cube. you can use alpha to say the cube is there or not or totally white and off-white. don't know about skeletons! I haven't fiddled with skeletons for the moment,probably just find a tutorial and figure how they work, think you have to group some of the cubes into limbs with hinge joint if you want to use classic Unity movement.
In classic pixels, they use a few different pictures for the different movements and just change those around, it would look better with something original and new so probably best to make the unity skeleton thing however it works!
Answer by ssaullors · Jan 05, 2013 at 03:14 AM
Hi, I'm from Brazil and I'm working in a project that looks similar to yours. I think you are talking abou voxels, right? For me it was easier to make all the parts in a 3D Modeller software(C4D) and then just give the option for the user to choose the part type and color. I am in my third day of development in this project and... It's running, that's the good part... :p Take a look in the picture. Your idea is a good one but, in my project, the user would have to model the hand, torso, hair, head and foot separately...
![alt text][id] [id]: C:/S.png "The Book : Athos part I"
So you have a kind of modular setup, where the character chooses between heads, hands and stuff? I wasnt going to let the player model their own character. Its more for when I have to make 3D models of characters, monsters and items. $$anonymous$$y system is more for building the models that the player can choose from in the first place. If you understand what i mean?
Answer by ssaullors · Jan 05, 2013 at 03:31 AM
So you kinda just want a software to make the voxels, right? I use Voxel Section Editor III, is very easy to model... Sproxel is a good one too. With Voxel3D you can export as obj.