22
$\begingroup$

I am using Blender's particle system to try to voxelize my mesh. I'd like to color the voxels based on the diffuse color of the textured mesh at the closest location to each voxel. This is an image that shows what I'm trying to do:

This Stack Exchange post explains how to color emitted particles based on the mesh from which they are emitted. The technique uses the "jittered" emission setting:

enter image description here

Using the technique in the post I linked to, here is what I get with "jittered" selected. You can see that the emitted cubes correctly match the color of the mesh:

When I change the emission setting to "grid", the cubes no longer match the color of the object:

I'd like to use the "grid" emission setting for voxelization, but can't figure out how to get the color of the emitted particles to correctly match the color of the mesh.

This is what my shader nodes look like for the cube which I am using as the dupli object:

I'd appreciate any help with this! Please let me know if there's something I can clarify.

$\endgroup$
  • $\begingroup$ It seems that particles UV (with the grid option) are calculated from the vertices bounding box of the mesh (starting from the min vertex). So not related to the positions of the mesh faces $\endgroup$ – lemon Jul 22 '16 at 11:05
  • $\begingroup$ are you planning to animate this? I can only see the grid option when you set the particle system to emission. But for a character in motion you'll have to set it to hair, otherwise the particles will detach from the surface right after emission happened. This would force you to take a different approach anyways. $\endgroup$ – aliasguru Jul 22 '16 at 11:08
  • $\begingroup$ Do you need the cubes to be monocolor or can they inherit from all the below colors ? $\endgroup$ – lemon Jul 22 '16 at 13:28
  • $\begingroup$ I have a possible solution for this, just wonder if you expect all blocks as one piece or individual objects. $\endgroup$ – Leon Cheung Jul 22 '16 at 14:04
  • $\begingroup$ @Miles - Can you post your original Blend File? $\endgroup$ – Rick Riggs Jul 22 '16 at 14:38
15
+100
$\begingroup$

A bit 'complicated' solution, as it seems that the particles UV are relative to the mesh boundings when the 'grid' option is set, not to the parent UV map (so I don't think this is possible to tune the nodes to obtain the wanted result, if you want to use particles) :

enter image description here

To do it :

  • Tune your particle system to obtain the grid dimensions you need
  • Apply the particle system, by clicking convert here :

enter image description here

  • You will obtain a duplicate of the cubes (on the right here) :

enter image description here

  • This cubes are dupli from the same object, so make them single user, by selecting them all and use the "make single user/object & data' menu, like below, and confirm 'selected objects'

enter image description here

  • Now join them all in order to have 1 mesh from them. As they are still all selected use Ctrl+J

  • Enter edit mode Tab

  • Them select all the vertices and unwrap U using the 'smart UV project' mode. It will give you some kind of UV grid like in the right part of the picture below :

enter image description here

Now we will make a bake from the original to the cube shape. This bake wont work directly because the proximity between the cubes and the original mesh is not good. So, to overpass that :

  • Add a shrinkwrap modifier to the cubes and set your original mesh as target object :

enter image description here

Now we can bake :

  • 1 : Add a material to your cube mesh
  • 2 : Add a image texture with a newly created texture. Keep this node active.
  • 3 : Select your original mesh RMB then the cube mesh with Shift+RMB
  • 4 : Go to the bake part of the render panel and check 'selected to active'
  • 5 : click 'bake'

enter image description here

  • Disable or remove the shrinkwrap modifier we set above
  • Using the baked texture, you obtain this below, with several colors on each cube :

enter image description here

If you need one color per cube, (edit : one color per face !)

  • Go to the UV editor
  • Select all your UVs
  • Set pivot to individual origins
  • Then scale to 0 S0

enter image description here

Doing that each cube UV is reduced to one point, and we obtain this :

enter image description here

If needed you can separate the cube in edit mode, using P then 'by loose parts' (this may take some calculations...). enter image description here

$\endgroup$
  • $\begingroup$ Hey, thanks so much for the help @lemon! The suggestion to scale the individual faces on the UV map is brilliant. Do you know if there is a way to obtain a single color per cube? Using your method, I get a single color per face, perhaps because smart UV project creates a UV island for each cube face. $\endgroup$ – Miles Jul 22 '16 at 19:50
  • $\begingroup$ @Miles, I will think about it (one color per cube) but no good ideas for now... $\endgroup$ – lemon Jul 23 '16 at 7:49
  • $\begingroup$ Smart part here imho is to use bake + shrinkwrap. The reason I didn't use grid particle is that it is hard to control the gap between cubes accurately to real zero. But of course it is more effective than using Animation Nodes addon if you don't care about that so much. $\endgroup$ – Leon Cheung Jul 23 '16 at 8:49
  • $\begingroup$ Smart part here imho is to use bake + shrinkwrap. The reason I didn't use grid particle is that it is hard to control the gap between cubes accurately to real zero. But of course it is more effective than using Animation Nodes addon if you don't care that so much. $\endgroup$ – Leon Cheung Jul 23 '16 at 8:49
  • 2
    $\begingroup$ Very nicely written and structured answer, +1 $\endgroup$ – Jaroslav Jerryno Novotny Jul 23 '16 at 8:52
13
$\begingroup$

There might be something odd with the Grid distributed particle when working with From Dupli feature. Before it can be officially solved, you can consider another non-particle way:

  1. Create an 3D array of cubes to cover the target object. Then group them for further convenience.

enter image description here

  1. Get rid of all outter cubes around the target. You may have to do that with some scripting work, or with help of Animation Nodes addon like this:

enter image description here

  1. Disable Animation Nodes addon. Select all visible objects, move them to another empty layer, then go back to the original layer, Alt H to make all invisible cubes visible again, then delete them all. Finally you can move all other objects from another layer back to the current layer (or not):

enter image description here

  1. Ctrl J to join all cubes as one single mesh, then go to Edit Mode, switch Selection type to Face, and make sure Limit Selection button is toggled, then use selection tools to select all visible faces around the mesh:

enter image description here

  1. After that, press Ctrl L to select all linked cubes, then Ctrl I to invert selection, then delete. This will remove all inner cubes.

  2. Select all elements in the combined mesh, switch Pivot Point type to Individual, then S . 0 0 1 to make each block fairly small.

enter image description here

  1. Back to Object Mode, hold Shift and select the target object. Keep all visible cubes selected, and the target object active (last selected), then find Data Transfer section in Toolshelf sidebar, click Data (or Shift Ctrl T) then UVs: enter image description here

  2. Then select the joined mesh, switch to Edit Mode, select all elements then S 1 0 0 0 to scale all blocks back to initial size.

  3. Then set the material for joined mesh. Finally delete or move the target object away. Voilà:

enter image description here

If you want to separate the joined mesh into cubes again, select all elements in Edit Mode, then press P -> By loose parts. Then Shift Ctrl Alt C to center origins for each cube.


And of course, you can use Remesh Modifier here, things goes quite similar but the result goes a bit different. It all depends on what kind of result you really want. (Mine strictly follows the Mario style you presented, which is, one single color per cube.)

$\endgroup$
  • 1
    $\begingroup$ UVed. Very nice use of animation nodes for modeling! $\endgroup$ – David Jul 23 '16 at 2:55
6
$\begingroup$

I know this doesn't answer your question, but if you are going for a result like the top image with Louigie, you might want to consider not using a Particle System, but a Remesh modifier with the Mode: set to Blocks and Remove Disconnected Pieces disabled.

Remesh modifier:

enter image description here

Without modifier:

enter image description here

With Modifier:

enter image description here

$\endgroup$
  • 1
    $\begingroup$ Thanks! I am trying to make an object where each of the voxels is a separate cube, and AFAIK Remesh with the Blocks setting produces a single object that can't be separated. $\endgroup$ – Miles Jul 19 '16 at 21:15
  • 1
    $\begingroup$ It can be separated. Go in edit mode, press "p", then "separate by loose parts". Hope that helps. $\endgroup$ – Uncle Snail Jul 21 '16 at 23:11
  • 4
    $\begingroup$ @UncleSnail No, it cannot. :) $\endgroup$ – Leon Cheung Jul 22 '16 at 2:34
  • 1
    $\begingroup$ Shady, I wanted to rework on this subject, and I do not succeed to keep the UV map using your approach. Do you know why ? I mean remesh looses the UV map $\endgroup$ – lemon Jul 26 '16 at 12:32
  • $\begingroup$ @Leon Cheung Oh, I'm sorry, you have to convert before you can separate. :P $\endgroup$ – Uncle Snail Aug 1 '16 at 21:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.