Page 1 of 1

Voxelizing a model results in entities expanding volume?!

Posted: Sun Jan 02, 2011 6:47 pm
by Spankenstein
I'm importing a simple cube model and "voxelizing" it in order to create 100s of small equally sized cubes from the original model mesh.

The voxel constructor is as follows:

Code: Select all

        public Voxel(Game1 game, Vector3 position, float size, Vector4 colour)
        {
            this.colour = colour;
            this.game = game;
            this.size = size;

            colourTimer = new LerpTimer(1f, 0f, 2000);

            // Reduce size by a small amount based on collision margins
            // This prevent the voxel from overlapping neighbouring voxels when created
            size -= game.Space.SimulationSettings.CollisionDetection.DefaultMargin;

            // Entity can be obtained from EntityPool
            entity = new Box(position, size, size, size, 1);
            entity.IsAffectedByGravity = false;        

            game.Space.Add(entity);
        }
The weird thing is that all the voxels don't stay put and instead expand away from each other. I thought they might be overlapping but I have tried reducing the size by the Default Margin and still nothing.

Why is this happening?

Image

Re: Voxelizing a model results in entities expanding volume?!

Posted: Sun Jan 02, 2011 7:12 pm
by Norbo
That is definitely caused by overlap. Try decreasing the size by 2 * DefaultMargin since the full expanded 'width' of a box is width + 2 * DefaultMargin (a margin on each side of the box). If that doesn't work, it might be related to some tuning designed for normal-sized objects (if objects get really really small, quite a bit less than 0.1). Or maybe it is related to the position calculation.

Another future-upgrade note: v0.15.0 considers box margins to be built into the box. Defining a width of 1 will give the box a total width of 1, with the margins going 'inwards.' Spheres and capsules also have 'inward' margins. Other shapes like MinkowskiSums and ConvexHulls still have outward margins.

Re: Voxelizing a model results in entities expanding volume?!

Posted: Sun Jan 02, 2011 7:44 pm
by Spankenstein
Cool, that fixed it. Thanks very much Norbo.