World not rendered if origin isn't in viewport

It’s self-explanatory, but I’ll give more detail anyway.



After the game is started, generated and the stars a pinned, the player ship is moved to a random location and the camera is pointing at the ship.



Now, if the origin of the map (0,0,0) isn’t in the viewport, the galaxy isn’t rendered. It’s an empty void. I have to rotate, turn, etc until I can move the origin in the viewport. When that happens, the galaxy fitting into the viewport gets drawn.



I know that when I first started I could look in any direction and things was drawn (at least that’s how I remember it, not 100% sure though).



Is there something I’m doing wrong? Or the culling is done on the origin itself. I don’t know how the rendering engine works. So it’s probably just me not doing something right.

You have to set the cullstate of the sky spatial to never. Or simply use the new SkyFactory tool.

If the galaxy is rendered as a sky, then do what normen said. If its a model you generated yourself, you probably want to call Mesh.updateBound() on your model to re-generate the bounding volume used for culling.

As it is now, the galaxy isn’t rendered as anything in particular. Each sun is attached like so:



[java]stateGalaxy.getRootNode().attachChild(ptSun);



ptSun being: Geometry ptSun = new Geometry(“pt_sun”, sun); [/java]



and sun being:



[java]sun = new Mesh();

sun.setMode(Mesh.Mode.Points);[/java]



Every sun is put at the X,Y,Z coordinates generated by the galaxy algorithm. After the suns are pinned the whole thing is scaled down/up (depending on how you view it).



Here’s the code for the stars pinning into the world.



[java]if (i == tagStop && x < maxStarsScreen) {

sun = new Mesh();

sun.setMode(Mesh.Mode.Points);

sun.setPointSize(stars.get(i).getRadius()/3);

sun.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(stars.get(i).getXYZ()));

Material mat = new Material(assetManager, “Common/MatDefs/Misc/SolidColor.j3md”);

mat.setColor(“m_Color”, stars.get(i).getColor());

Geometry ptSun = new Geometry(“pt_sun”, sun);

// BoundingSphere bBoundSun = new BoundingSphere();

// ptSun.setModelBound(bBoundSun);

ptSun.setMaterial(mat);

stateGalaxy.getRootNode().setName(“star”);

stateGalaxy.getRootNode().attachChild(ptSun);



switch (gType) {

case 1:

case 2:

visibleStars.add(stars.get(i));

tagStop = tag + i;

break;

case 3:

if (changeSphereAt == x) {

atSphere += 1;

changeSphereAt = maxStarsScreen / g.gSpheres * atSphere;

tagStop = g.starsBySphere * atSphere;

visibleStars.add(stars.get(i));

i = g.starsBySphere * atSphere -1;

//changeSphereAt = x + (maxStarsScreen / g.gSpheres);

break;

} else {

visibleStars.add(stars.get(i));

tagStop = tag + i;

}

}

x = visibleStars.size();

stateGalaxy.getRootNode().updateGeometricState();

}

}[/java]



What’s at, and following, the “switch” isn’t important for the topic here but I left it there.

I think the issue might be that you have a single point in each geometry, since points are infinitely small, that means the generated bounding box will have zero volume which could cause issues.

I recommend that you put all your stars into one geometry as that is a lot faster than having a single point in every object.

@Momoko_Fan



I’m not sure how you want me to do that…



As it is I made a custom Octree that will display around 2000 stars in the node I’m traveling in. It works great except for the part that the rootNode’s origin (0,0,0) has to be in the view frustrum to get those 2000 stars painted on the screen. If it’s not, the screen is blank, only the ship is visible.



Since only what is attached to the rootNode is being displayed on the screen, I can’t find a way to either do what you’re suggesting or find a work-around.



Oh, and those points don’t have bounding boxes. In the code above those boxes are commented out. Do you imply I should add boxes to those?

Any object in the scene graph has a bounding box. The bounding box is generated from the geometry, in this case, a single point.

If you’re making an octree, then you should have all the stars in a leaf node be inside a single geometry, there’s no reason having them in separate meshes.

I fixed the culling by simply using:



rootNode.setCullHint(CullHint.Never);



But I’m concerned by what you’re suggesting.



I’m probably over-complicating things, so I guess you’ll have to simplify for me. The way I’ve done it is the only way I can see how to pin those stars on the canvas. Please explain how I could do it otherwise.