Skip to main content

8000+ Shapes -> OutOfMemory | Shape with n textures | Invisible shapes

4 replies [Last post]
prontector
Offline
Joined: 2009-01-06

When I load a huge level containing many faces and many textures, I need to create one Shape3D for every face in that map. I searched for a way to create a Shape3D with multiple textures on multiple faces, but for some reason it doesn't seem to be possible.
When the amount of Shape3Ds exceeds 8000 I get an OutOfMemoryError exception.

Is there any way to create a single Shape3D for the level? I can't create a big texture containing all level textures and use different texture coordinates for each texture, because one level uses several hundred unique textures.

Another problem I have encountered is when I use the original vertices of the level nothing is rendered. Only when I multiply the vector data with 0.01, Java3d renders the level. Problem with that is, the level I use is in bsp format and bsp stores texture offsets as dotproducts with the original vertex data. By scaling that data the texture offsets get messed up.

I can give anyone who is interested the source of my bsp loader and shape generator, but it must not be published before the project goes public.

Thank you for reading and thanks for any suggestions and comments!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
zesharp
Offline
Joined: 2006-12-21

> I need to create one Shape3D for every face in that map ...

What about to group faces using the same texture into a single Shape3D ?
This way you'll end up with a few shapes instead of thousands.

>Only when I multiply the vector data with 0.01, Java3d renders the level.

Perhaps your data is too big to fit in your screen. Try to scale down your scene by the same factor.

prontector
Offline
Joined: 2009-01-06

> What about to group faces using the same texture into a single Shape3D ?
> This way you'll end up with a few shapes instead of thousands.

Wow, that's actually a great idea. Simple and easy to implement. Thanks, wonder why I didn't come up with that :D

> Perhaps your data is too big to fit in your screen. Try to scale down your scene by the same factor.

Okay, seems my Java3d skills are still very poor. May be a silly question, but how can I scale my scene? I have the universe, the canvas3d and the main branchgroup.

Thank you very much!

zesharp
Offline
Joined: 2006-12-21

> but how can I scale my scene?

add a TransformGroup to your scene graph

universe -> bgScale -> tgScale -> bgScene -> ...

[code]
// the scale
double scale = 0.01d;

// temp transform
Transform3D tempT3D = new Transform3D();

// the transform group
TransformGroup tgScale = new TransformGroup();

// get a copy of current Transform
tgScale.getTransform(tempT3D);
// set scale
tempT3D.setScale(scale)
// copy transform back
tgScale.setTransform(tempT3D);

// add main bg as child of tgScale - I'm assuming bgScene contains your 3D shapes
tgScale.addChild(bgScene);

// add tgScale to scene graph. Don't forget to create it before using it ;)
bgScene.addChild(tgScale);

//add bgScene to universe
// I guess you can go by yourself from here

[/code]

prontector
Offline
Joined: 2009-01-06

Okay, thanks for that detailled explanation. I tried that, but even with that the screen stayed black.

I saw another thread where someone posted setBackClipDistance and setFrontClipDistance. Didn't know about those, though. Standard value for backClipDistance is 10 meters. Obvious that nothing is rendered when my vertex coordinates use meters as unit and my camera is 32 meters in the air :D
Solved the problem with setBackClipDistance(1000) and setFrontClipDistance(1).

Thank you very much for your help, even if your second solution didn't help, it gave me some better understanding of how Java3D and transformGroups work.