Skip to main content

12000 boxes - 100Mb memory

8 replies [Last post]
murgog
Offline
Joined: 2006-02-14
Points: 0

Hi, i´m creating a program to show multiple boxes (12000 )inside a rectangle. It´s possible to rotate around the rectangle and see it by others angules. It´s using around 100Mb to do this. I have to lower this.

I´m doing this to create each box:
GeometryData data = new GeometryData();
data.geometryType = GeometryData.QUADS;
boxGenerator.setDimensions( dimX, dimY, dimZ );
boxGenerator.generate( data );
geom = new QuadArray( data.vertexCount, GeometryArray.COORDINATES | GeometryArray.BY_REFERENCE );
geom.setCoordRefFloat( data.coordinates );
Shape3D shape = new Shape3D();
shape.setGeometry( geom );
shape.setBounds( new BoundingSphere( boundPoint, Double.POSITIVE_INFINITY ) );
shape.setBoundsAutoCompute(false);

I move each box with a Transform3D to put on the right place.

Is there a way to lower this or is this number (100Mb) right?

Thanks
Pedro A. V.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Anonymous

...
> {
> for (int i = 0; i < borderCoords.length;
> s.length; i++)
> {
> borderCoords[i] *= distance;
> }
>
> LineArray la = new LineArray(24,
> Array(24, LineArray.COORDINATES);
...

nice demo, but forum rules interprets "array element i syntax" as italic text html command, see above :)

try post your samples with these operators below, replace { to [ and } to ]

{code}
/* your code */
{/code}

Justin Couch

java3d-interest@javadesktop.org wrote:
> Hi, i´m creating a program to show multiple boxes (12000 )inside a rectangle. It´s possible to rotate around the rectangle and see it by others angules. It´s using around 100Mb to do this. I have to lower this.
>
> I´m doing this to create each box:
> GeometryData data = new GeometryData();
> data.geometryType = GeometryData.QUADS;

You shouldn't do this if at all possible. Use a single geometry array
and then scale each box to the right location and size. Most of your
memory will be disappearing into the geometry arrays. Unless you really
need separate geometry per box instance (eg different colour per vertex
or different texture coordinates), then you are creating memory usage
for zero gain. Better off just creating a single QuadArray instance and
sharing it between multiple Shape3D instances, each with their own
unique Transform3D above them (and sharing Appearance/Material instances
wherever possible too).

--
Justin Couch http://www.vlc.com.au/~justin/
Java Architect & Bit Twiddler http://www.yumetech.com/
Author, Java 3D FAQ Maintainer http://www.j3d.org/
-------------------------------------------------------------------
Programming is essentially a markup language surrounding
mathematical formulae and thus, should not be patentable.
-------------------------------------------------------------------

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@java3d.dev.java.net
For additional commands, e-mail: interest-help@java3d.dev.java.net

fherinean
Offline
Joined: 2004-07-08
Points: 0

I've couldn't help myself, so I've thrown in a little bit of colour ;)

import java.awt.BorderLayout;
import java.awt.Color;
import java.util.Enumeration;
import java.util.Map;
import java.util.Iterator;
import java.util.HashMap;

import javax.media.j3d.*;
import javax.swing.JFrame;
import javax.vecmath.Color3f;
import javax.vecmath.Point3d;
import javax.vecmath.Vector3f;
import javax.vecmath.Vector3d;

import com.sun.j3d.utils.behaviors.vp.OrbitBehavior;
import com.sun.j3d.utils.universe.PlatformGeometry;
import com.sun.j3d.utils.universe.SimpleUniverse;
import com.sun.j3d.utils.universe.ViewingPlatform;

/**
*
* @author fherinean
* @version $Revision: $
*/
public class ManyBoxesDemo
{
private static final double viewingDistance = 500;
private static final int COUNT = 1000;
private static final Color[] colors = {Color.red, Color.blue, Color.green,
Color.yellow, Color.cyan, Color.magenta, Color.orange, Color.pink};

public static void main(String[] args)
{
int count = COUNT;
try
{
count = Integer.parseInt(args[0]);
}
catch (Exception ex)
{
}

JFrame frame = new JFrame("Many Boxes Demo");

// create canvas & universe
Canvas3D c3d = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
SimpleUniverse universe = new SimpleUniverse(c3d);
c3d.getView().setFrontClipDistance(1);
c3d.getView().setBackClipDistance(2 * viewingDistance);
ViewingPlatform platform = universe.getViewingPlatform();
Transform3D t3d = new Transform3D();
Point3d center = new Point3d(0, 0, 0);
Point3d eye = new Point3d(0, 0, -viewingDistance);
Vector3d up = new Vector3d(0, 1, 0);
t3d.lookAt(eye, center, up);
t3d.invert();
platform.getViewPlatformTransform().setTransform(t3d);

// create orbiter
Bounds bounds = new BoundingSphere(new Point3d(), 1000.0);
OrbitBehavior orbit = new OrbitBehavior(c3d,
OrbitBehavior.REVERSE_ALL |
OrbitBehavior.DISABLE_TRANSLATE //|
/*OrbitBehavior.DISABLE_ZOOM*/);
orbit.setZoomFactor(10);

orbit.setSchedulingBounds(bounds);
platform.setViewPlatformBehavior(orbit);

// setup the lights
Color3f ambientLightColor = new Color3f(0.30f, 0.30f, 0.30f);
Color3f diffuseLightColor = new Color3f(0.75f, 0.75f, 0.75f);
Vector3f diffuseLightDirection = new Vector3f(0, 0, -1);
PlatformGeometry pg = new PlatformGeometry();
Light ambient = new AmbientLight(true, ambientLightColor);
ambient.setInfluencingBounds(bounds);
pg.addChild(ambient);
Light directional = new DirectionalLight(true,
diffuseLightColor,
diffuseLightDirection);
directional.setInfluencingBounds(bounds);
pg.addChild(directional);
platform.setPlatformGeometry(pg);

BranchGroup root = new BranchGroup();

BoxesBehavior behavior = new BoxesBehavior();
behavior.setSchedulingBounds(bounds);
root.addChild(behavior);

for (int i = 0; i < colors.length - 1; i++)
{
root.addChild(behavior.addBoxes(count / colors.length, colors[i]));
}
root.addChild(behavior.addBoxes(count - (colors.length - 1) * (count / colors.length), colors[colors.length - 1]));

root.addChild(behavior.createBorders());

root.compile();

universe.getLocale().addBranchGraph(root);

// show the window
frame.getContentPane().add(c3d, BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 400);
frame.setLocation(300, 300);
frame.setVisible(true);
}

private static class BoxesBehavior extends Behavior implements GeometryUpdater
{
private WakeupCondition wakeup = new WakeupOnElapsedTime(20);
private double distance;
private Map boxes;
private Map directions;

public BoxesBehavior()
{
distance = viewingDistance / 4;
boxes = new HashMap();
directions = new HashMap();
}

public Shape3D addBoxes(int count, Color color)
{
if (count > 0)
{
Geometry geometry = createBoxes(count);
boxes.put(geometry, new Integer(count));

double[] dirs = createDirections(count);
directions.put(geometry, dirs);

Color3f c3f = new Color3f(color);
Appearance appearance = new Appearance();
Material material = new Material();
material.setAmbientColor(c3f);
material.setDiffuseColor(c3f);
material.setSpecularColor(c3f);
appearance.setMaterial(material);

Shape3D cubes = new Shape3D(geometry, appearance);
cubes.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
cubes.setCapabilityIsFrequent(Shape3D.ALLOW_GEOMETRY_READ);
return cubes;
}
return new Shape3D();
}

public void initialize()
{
wakeupOn(wakeup);
}

public void processStimulus(Enumeration enumeration)
{
for (Iterator i = boxes.keySet().iterator(); i.hasNext();)
{
((GeometryArray) i.next()).updateData(this);
}
wakeupOn(wakeup);
}

public void updateData(Geometry geometry)
{
int boxSize = 6 /*faces*/ * 4 /*corners*/;
double[] coords = ((GeometryArray) geometry).getCoordRefDouble();
int count = ((Integer) boxes.get(geometry)).intValue();
double[] dirs = (double[]) directions.get(geometry);
int pos = 0;
int dir = 0;
for (int i = 0; i < count; i++)
{
boolean switchX = false;
boolean switchY = false;
boolean switchZ = false;
for (int j = 0; j < boxSize; j++)
{
coords[pos] += dirs[dir];
switchX = needsSwitching(coords[pos++]);
coords[pos] += dirs[dir + 1];
switchY = needsSwitching(coords[pos++]);
coords[pos] += dirs[dir + 2];
switchZ = needsSwitching(coords[pos++]);
}
switchDirections(dir, dirs, switchX, switchY, switchZ);
dir += 3;
}
}

private void switchDirections(int dir, double[] dirs, boolean switchX, boolean switchY, boolean switchZ)
{
if (switchX)
{
dirs[dir] = -dirs[dir];
}
if (switchY)
{
dirs[dir + 1] = -dirs[dir + 1];
}
if (switchZ)
{
dirs[dir + 2] = -dirs[dir + 2];
}
}

private boolean needsSwitching(double coord)
{
return coord < -distance || coord > distance;
}

// normals for a simple box
private static float[] defaultNormals = {
0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f,

1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,

0.0f, 0.0f, -1.0f, 0.0f, 0.0f, -1.0f,
0.0f, 0.0f, -1.0f, 0.0f, 0.0f, -1.0f,

-1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f,
-1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f,

0.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f,
0.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f,

0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f,
};

private static double[] defaultCoords = {
-1.0, -1.0, 1.0, 1.0, -1.0, 1.0,
1.0, 1.0, 1.0, -1.0, 1.0, 1.0,

1.0, -1.0, 1.0, 1.0, -1.0, -1.0,
1.0, 1.0, -1.0, 1.0, 1.0, 1.0,

1.0, -1.0, -1.0, -1.0, -1.0, -1.0,
-1.0, 1.0, -1.0, 1.0, 1.0, -1.0,

-1.0, -1.0, -1.0, -1.0, -1.0, 1.0,
-1.0, 1.0, 1.0, -1.0, 1.0, -1.0,

-1.0, -1.0, -1.0, 1.0, -1.0, -1.0,
1.0, -1.0, 1.0, -1.0, -1.0, 1.0,

-1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
1.0, 1.0, -1.0, -1.0, 1.0, -1.0,
};

private Geometry createBoxes(int count)
{
int boxSize = 6 /*faces*/ * 4 /*corners*/ * 3 /*coordinates*/;
int arraySize = count /*boxes*/ * boxSize /*arraySize-of-a-box*/;
int pointsCount = count /*boxes*/ * 6 /*faces*/ * 4 /*corners*/;

double[] coords = new double[arraySize];
float[] normals = new float[arraySize];

for (int i = 0; i < count; i++)
{
System.arraycopy(defaultCoords, 0, coords, i * boxSize, boxSize);
System.arraycopy(defaultNormals, 0, normals, i * boxSize, boxSize);
}

GeometryArray geometry = new QuadArray(pointsCount, GeometryArray.COORDINATES | GeometryArray.NORMALS | GeometryArray.BY_REFERENCE);
geometry.setCapability(GeometryArray.ALLOW_REF_DATA_WRITE);
geometry.setCapabilityIsFrequent(GeometryArray.ALLOW_REF_DATA_WRITE);
geometry.setCapability(GeometryArray.ALLOW_REF_DATA_READ);
geometry.setCapabilityIsFrequent(GeometryArray.ALLOW_REF_DATA_READ);
geometry.setCoordRefDouble(coords);
geometry.setNormalRefFloat(normals);

return geometry;
}

private double[] createDirections(int count)
{
int arraySize = count /*boxes*/ * 3 /*coordinates*/;
double[] result = new double[arraySize];
Vector3d vector = new Vector3d();
int pos = 0;
for (int i = 0; i < count; i++)
{
vector.x = Math.random() - 0.5;
vector.y = Math.random() - 0.5;
vector.z = Math.random() - 0.5;
vector.normalize();
vector.scale(distance * Math.random() / 250.0d + 0.1);
result[pos++] = vector.x;
result[pos++] = vector.y;
result[pos++] = vector.z;
}
return result;
}

private static double[] borderCoords = {
-1.0, -1.0, -1.0, 1.0, -1.0, -1.0,
-1.0, -1.0, -1.0, -1.0, 1.0, -1.0,
-1.0, -1.0, -1.0, -1.0, -1.0, 1.0,
1.0, -1.0, -1.0, 1.0, 1.0, -1.0,
1.0, -1.0, -1.0, 1.0, -1.0, 1.0,
-1.0, 1.0, -1.0, 1.0, 1.0, -1.0,
-1.0, 1.0, -1.0, -1.0, 1.0, 1.0,
-1.0, -1.0, 1.0, -1.0, 1.0, 1.0,
-1.0, -1.0, 1.0, 1.0, -1.0, 1.0,
-1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
1.0, -1.0, 1.0, 1.0, 1.0, 1.0,
1.0, 1.0, -1.0, 1.0, 1.0, 1.0,
};

public Shape3D createBorders()
{
for (int i = 0; i < borderCoords.length; i++)
{
borderCoords[i] *= distance;
}

LineArray la = new LineArray(24, LineArray.COORDINATES);
la.setCoordinates(0, borderCoords);

Appearance app = new Appearance();
app.setColoringAttributes(new ColoringAttributes(new Color3f(0.7f, 0.8f, 0.9f), ColoringAttributes.NICEST));
return new Shape3D(la, app);
}
}
}

fherinean
Offline
Joined: 2004-07-08
Points: 0

One more thing I forgot to say about the previous posted example (sorry for the spam).

The code should be put in a file named ManyBoxesDemo.java. By default, it will display 1000 boxes (for performance reasons), but you can pass the number of the boxes as the first argument of the program.

Cheers,

Florin

fherinean
Offline
Joined: 2004-07-08
Points: 0

There are many ways in which you can reduce the memory usage, depending on the complexity of the scene you want to achive. I've added a full example below, that you can analyze. It will do what you have described, i.e. put a number of boxes (cubes) in a finite area (visible) and move them randomly around.

The whole program uses on windows 32 mb with 12000 boxes, but considering that the footprint of the program is 21 mb, that means that the data required for the 12000 boxes is only 11 mb. Actually it's less, probably around 8 mb, since a part of it is used for the movement information (I'm storing for each box the movement direction and the speed of movement in that direction)

Cheers,

Florin

import java.awt.BorderLayout;
import java.util.Enumeration;

import javax.media.j3d.*;
import javax.swing.JFrame;
import javax.vecmath.Color3f;
import javax.vecmath.Point3d;
import javax.vecmath.Vector3f;
import javax.vecmath.Vector3d;

import com.sun.j3d.utils.behaviors.vp.OrbitBehavior;
import com.sun.j3d.utils.universe.PlatformGeometry;
import com.sun.j3d.utils.universe.SimpleUniverse;
import com.sun.j3d.utils.universe.ViewingPlatform;

/**
*
* @author fherinean
* @version $Revision: $
*/
public class ManyBoxesDemo
{
private static final double viewingDistance = 500;
private static final int COUNT = 1000;

public static void main(String[] args)
{
int count = COUNT;
try
{
count = Integer.parseInt(args[0]);
}
catch (Exception ex) {}

JFrame frame = new JFrame("Many Boxes Demo");

// create canvas & universe
Canvas3D c3d = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
SimpleUniverse universe = new SimpleUniverse(c3d);
c3d.getView().setFrontClipDistance(1);
c3d.getView().setBackClipDistance(2 * viewingDistance);
ViewingPlatform platform = universe.getViewingPlatform();
Transform3D t3d = new Transform3D();
Point3d center = new Point3d(0, 0, 0);
Point3d eye = new Point3d(0, 0, -viewingDistance);
Vector3d up = new Vector3d(0, 1, 0);
t3d.lookAt(eye, center, up);
t3d.invert();
platform.getViewPlatformTransform().setTransform(t3d);

// create orbiter
Bounds bounds = new BoundingSphere(new Point3d(), 1000.0);
OrbitBehavior orbit = new OrbitBehavior(c3d,
OrbitBehavior.REVERSE_ALL |
OrbitBehavior.DISABLE_TRANSLATE //|
/*OrbitBehavior.DISABLE_ZOOM*/);
orbit.setZoomFactor(10);

orbit.setSchedulingBounds(bounds);
platform.setViewPlatformBehavior(orbit);

// setup the lights
Color3f ambientLightColor = new Color3f(0.30f, 0.30f, 0.30f);
Color3f diffuseLightColor = new Color3f(0.75f, 0.75f, 0.75f);
Vector3f diffuseLightDirection = new Vector3f(0, 0, -1);
PlatformGeometry pg = new PlatformGeometry();
Light ambient = new AmbientLight(true, ambientLightColor);
ambient.setInfluencingBounds(bounds);
pg.addChild(ambient);
Light directional = new DirectionalLight(true,
diffuseLightColor,
diffuseLightDirection);
directional.setInfluencingBounds(bounds);
pg.addChild(directional);
platform.setPlatformGeometry(pg);

BranchGroup root = new BranchGroup();

BoxesBehavior behavior = new BoxesBehavior(count);
behavior.setSchedulingBounds(bounds);
root.addChild(behavior);

root.addChild(behavior.getBoxes());
root.addChild(behavior.getBorders());

root.compile();

universe.getLocale().addBranchGraph(root);

// show the window
frame.getContentPane().add(c3d, BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 400);
frame.setLocation(300, 300);
frame.setVisible(true);
}

private static class BoxesBehavior extends Behavior implements GeometryUpdater
{
private WakeupCondition wakeup = new WakeupOnElapsedTime(20);
private double[] directions;
private double distance;
private int count;
private Shape3D borders;
private Shape3D boxes;

public BoxesBehavior(int count)
{
this.count = count;
distance = viewingDistance / 4;
boxes = createBoxes();
directions = createDirections();
borders = createBorders();
}

public void initialize()
{
wakeupOn(wakeup);
}

public void processStimulus(Enumeration enumeration)
{
((GeometryArray) boxes.getGeometry()).updateData(this);
wakeupOn(wakeup);
}

public void updateData(Geometry geometry)
{
int boxSize = 6 /*faces*/ * 4 /*corners*/;
double[] coords = ((GeometryArray) geometry).getCoordRefDouble();
int pos = 0;
int dir = 0;
for (int i = 0; i < count; i++)
{
boolean switchX = false;
boolean switchY = false;
boolean switchZ = false;
for (int j = 0; j < boxSize; j++)
{
coords[pos] += directions[dir];
if (coords[pos] < -distance || coords[pos] > distance)
{
switchX = true;
}
pos++;
coords[pos] += directions[dir + 1];
if (coords[pos] < -distance || coords[pos] > distance)
{
switchY = true;
}
pos++;
coords[pos] += directions[dir + 2];
if (coords[pos] < -distance || coords[pos] > distance)
{
switchZ = true;
}
pos++;
}
if (switchX)
{
directions[dir] = -directions[dir];
}
if (switchY)
{
directions[dir + 1] = -directions[dir + 1];
}
if (switchZ)
{
directions[dir + 2] = -directions[dir + 2];
}
dir += 3;
}
}

// normals for a simple box
private static float[] defaultNormals = {
0.0f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f,

1.0f, 0.0f, 0.0f,
1.0f, 0.0f, 0.0f,
1.0f, 0.0f, 0.0f,
1.0f, 0.0f, 0.0f,

0.0f, 0.0f, -1.0f,
0.0f, 0.0f, -1.0f,
0.0f, 0.0f, -1.0f,
0.0f, 0.0f, -1.0f,

-1.0f, 0.0f, 0.0f,
-1.0f, 0.0f, 0.0f,
-1.0f, 0.0f, 0.0f,
-1.0f, 0.0f, 0.0f,

0.0f, -1.0f, 0.0f,
0.0f, -1.0f, 0.0f,
0.0f, -1.0f, 0.0f,
0.0f, -1.0f, 0.0f,

0.0f, 1.0f, 0.0f,
0.0f, 1.0f, 0.0f,
0.0f, 1.0f, 0.0f,
0.0f, 1.0f, 0.0f,
};

private static double[] defaultCoords = {
-1.0, -1.0, 1.0,
1.0, -1.0, 1.0,
1.0, 1.0, 1.0,
-1.0, 1.0, 1.0,

1.0, -1.0, 1.0,
1.0, -1.0, -1.0,
1.0, 1.0, -1.0,
1.0, 1.0, 1.0,

1.0, -1.0, -1.0,
-1.0, -1.0, -1.0,
-1.0, 1.0, -1.0,
1.0, 1.0, -1.0,

-1.0, -1.0, -1.0,
-1.0, -1.0, 1.0,
-1.0, 1.0, 1.0,
-1.0, 1.0, -1.0,

-1.0, -1.0, -1.0,
1.0, -1.0, -1.0,
1.0, -1.0, 1.0,
-1.0, -1.0, 1.0,

-1.0, 1.0, 1.0,
1.0, 1.0, 1.0,
1.0, 1.0, -1.0,
-1.0, 1.0, -1.0,
};

private Shape3D createBoxes()
{
int boxSize = 6 /*faces*/ * 4 /*corners*/ * 3 /*coordinates*/;
int arraySize = count /*boxes*/ * boxSize /*arraySize-of-a-box*/;
int pointsCount = count /*boxes*/ * 6 /*faces*/ * 4 /*corners*/;

double[] coords = new double[arraySize];
float[] normals = new float[arraySize];

for (int i = 0; i < count; i++)
{
System.arraycopy(defaultCoords, 0, coords, i * boxSize, boxSize);
System.arraycopy(defaultNormals, 0, normals, i * boxSize, boxSize);
}

GeometryArray geometry = new QuadArray(pointsCount, GeometryArray.COORDINATES | GeometryArray.NORMALS | GeometryArray.BY_REFERENCE);
geometry.setCapability(GeometryArray.ALLOW_REF_DATA_WRITE);
geometry.setCapabilityIsFrequent(GeometryArray.ALLOW_REF_DATA_WRITE);
geometry.setCapability(GeometryArray.ALLOW_REF_DATA_READ);
geometry.setCapabilityIsFrequent(GeometryArray.ALLOW_REF_DATA_READ);
geometry.setCoordRefDouble(coords);
geometry.setNormalRefFloat(normals);

Appearance defaultAppearance = new Appearance();
Material defaultMaterial = new Material();
defaultAppearance.setMaterial(defaultMaterial);

Shape3D result = new Shape3D(geometry, defaultAppearance);
result.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
result.setCapabilityIsFrequent(Shape3D.ALLOW_GEOMETRY_READ);
return result;
}

private double[] createDirections()
{
int arraySize = count /*boxes*/ * 3 /*coordinates*/;
double[] result = new double[arraySize];
Vector3d vector = new Vector3d();
int pos = 0;
for (int i = 0; i < count; i++)
{
vector.x = Math.random() - 0.5;
vector.y = Math.random() - 0.5;
vector.z = Math.random() - 0.5;
vector.normalize();
vector.scale(distance * Math.random() / 250.0d);
result[pos++] = vector.x;
result[pos++] = vector.y;
result[pos++] = vector.z;
}
return result;
}

private static double[] borderCoords = {
-1.0, -1.0, -1.0, 1.0, -1.0, -1.0,
-1.0, -1.0, -1.0, -1.0, 1.0, -1.0,
-1.0, -1.0, -1.0, -1.0, -1.0, 1.0,
1.0, -1.0, -1.0, 1.0, 1.0, -1.0,
1.0, -1.0, -1.0, 1.0, -1.0, 1.0,
-1.0, 1.0, -1.0, 1.0, 1.0, -1.0,
-1.0, 1.0, -1.0, -1.0, 1.0, 1.0,
-1.0, -1.0, 1.0, -1.0, 1.0, 1.0,
-1.0, -1.0, 1.0, 1.0, -1.0, 1.0,
-1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
1.0, -1.0, 1.0, 1.0, 1.0, 1.0,
1.0, 1.0, -1.0, 1.0, 1.0, 1.0,
};

private Shape3D createBorders()
{
for (int i = 0; i < borderCoords.length; i++)
{
borderCoords[i] *= distance;
}

LineArray la = new LineArray(24, LineArray.COORDINATES);
la.setCoordinates(0, borderCoords);

Appearance app = new Appearance();
app.setColoringAttributes(new ColoringAttributes(new Color3f(0.7f, 0.8f, 0.9f), ColoringAttributes.NICEST));
return new Shape3D(la, app);
}

public Shape3D getBorders()
{
return borders;
}

public Shape3D getBoxes()
{
return boxes;
}
}
}

murgog
Offline
Joined: 2006-02-14
Points: 0

Hi Florin,
Thanks a lot, i will give a good look at this! Now i'm at home but tomorrow i'll test it.

Peace,
Pedro

Alan Hudson

java3d-interest@javadesktop.org wrote:

>Hi, i´m creating a program to show multiple boxes (12000 )inside a rectangle. It´s possible to rotate around the rectangle and see it by others angules. It´s using around 100Mb to do this. I have to lower this.
>
>I´m doing this to create each box:
>GeometryData data = new GeometryData();
>data.geometryType = GeometryData.QUADS;
>boxGenerator.setDimensions( dimX, dimY, dimZ );
>boxGenerator.generate( data );
>geom = new QuadArray( data.vertexCount, GeometryArray.COORDINATES | GeometryArray.BY_REFERENCE );
>geom.setCoordRefFloat( data.coordinates );
>Shape3D shape = new Shape3D();
>shape.setGeometry( geom );
>shape.setBounds( new BoundingSphere( boundPoint, Double.POSITIVE_INFINITY ) );
> shape.setBoundsAutoCompute(false);
>
>I move each box with a Transform3D to put on the right place.
>
>Is there a way to lower this or is this number (100Mb) right?
>
>
>
Alot of memory usage in Java is temporary. What size are you setting
your heap to? If you give Java more memory it will use it. Try
lowering your head size till you start getting out of memory errors.
This will represent your true heap usage.

Not sure why your seeing the bounds the way your doing. It totally
disables view frustum culling.

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@java3d.dev.java.net
For additional commands, e-mail: interest-help@java3d.dev.java.net

murgog
Offline
Joined: 2006-02-14
Points: 0

Hi Alan,
I have a limit of 128Mb of heap but i'd like to lower the amount of memory used. I have profiled that the program (JVM ) is using 100Mb after garbage collection.

The program shows about 12.000 boxes pilled up inside a skeleton rectangle and it's possible to rotate around the rectangle. These boxes are very small and most have the same size and color. I don't see how to use a view frustum on this case as the viewer can see the edges of this skeleton rectangle and rotate around it. Most of the boxes cannot be seen as they are behind other boxes.

Thanks,
Pedro