new background

This commit is contained in:
Johannes Schmelz 2024-12-10 10:14:06 +01:00
parent 1db2d9ebac
commit 5959f36a21
5 changed files with 73 additions and 9 deletions

View File

@ -10,11 +10,13 @@ import com.jme3.light.AmbientLight;
import com.jme3.light.DirectionalLight;
import com.jme3.light.PointLight;
import com.jme3.material.Material;
import com.jme3.material.RenderState.FaceCullMode;
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.renderer.Camera;
import com.jme3.renderer.queue.RenderQueue;
import com.jme3.renderer.queue.RenderQueue.ShadowMode;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
@ -177,17 +179,79 @@ public class BoardAppState extends MonopolyAppState {
*/
private void setupSky() {
final AssetManager assetManager = getApp().getAssetManager();
final Texture west = assetManager.loadTexture("Pictures/Backdrop/wall.jpg"); //NON-NLS
final Texture east = assetManager.loadTexture("Pictures/Backdrop/door.jpg"); //NON-NLS
final Texture north = assetManager.loadTexture("Pictures/Backdrop/board.jpg"); //NON-NLS
final Texture south = assetManager.loadTexture("Pictures/Backdrop/wall.jpg"); //NON-NLS
final Texture up = assetManager.loadTexture("Pictures/Backdrop/wall.jpg"); //NON-NLS
final Texture down = assetManager.loadTexture("Pictures/Backdrop/floor1.jpg"); //NON-NLS
final Spatial sky = SkyFactory.createSky(assetManager, west, east, north, south, up, down);
// sky.rotate(0, PI, 0);
viewNode.attachChild(sky);
// Create a cylinder for the sky
float radius = 500f; // Adjust radius as needed
float height = 200f; // Height of the cylinder
int radialSamples = 64; // Number of radial segments for smoothness
int axisSamples = 2; // No vertical divisions (flat vertical surface)
Cylinder skyCylinder = new Cylinder(axisSamples, radialSamples, radius, height, true);
// Create a geometry for the cylinder
Geometry skyGeometry = new Geometry("CylinderSky", skyCylinder);
// Load the cylindrical texture
Texture cylinderTexture = assetManager.loadTexture("Textures/CylinderMap.jpg");
// Create a material and apply the texture
Material skyMaterial = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
skyMaterial.setTexture("ColorMap", cylinderTexture);
skyMaterial.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off); // Render inside of the cylinder
// Assign material to the geometry
skyGeometry.setMaterial(skyMaterial);
skyGeometry.rotate(-FastMath.HALF_PI, 0, 0); // Rotate 90° along the Y-axis
// Position and attach the cylinder to the scene
skyGeometry.setQueueBucket(RenderQueue.Bucket.Sky); // Ensure it's rendered in the background
skyGeometry.setCullHint(Spatial.CullHint.Never); // Always render the sky
viewNode.attachChild(skyGeometry);
addCylinderCaps();
}
/**
* Adds top and bottom caps to the cylinder sky.
*/
private void addCylinderCaps() {
final AssetManager assetManager = getApp().getAssetManager();
float radius = 500f; // Match the cylinder's radius
float height = 225f; // Match the cylinder's height
int radialSamples = 64; // Match the cylinder's radial samples
// Bottom Cap
Cylinder bottomCap = new Cylinder(2, radialSamples, radius, 0.01f, true, false); // Thin bottom cap
Geometry bottomGeometry = new Geometry("BottomCap", bottomCap);
bottomGeometry.setLocalTranslation(0, -height / 2, 0); // Position at the bottom
bottomGeometry.rotate(FastMath.HALF_PI, 0, 0); // Rotate to make it horizontal
Material bottomMaterial = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
bottomMaterial.setTexture("ColorMap", assetManager.loadTexture("Textures/grass.jpg")); // Bottom texture
bottomMaterial.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off); // Render both sides
bottomGeometry.setMaterial(bottomMaterial);
bottomGeometry.setQueueBucket(RenderQueue.Bucket.Sky);
bottomGeometry.setCullHint(Spatial.CullHint.Never);
// Top Cap
Cylinder topCap = new Cylinder(2, radialSamples, radius, 0.01f, true, false); // Thin top cap
Geometry topGeometry = new Geometry("TopCap", topCap);
topGeometry.setLocalTranslation(0, height / 2, 0); // Position at the top
topGeometry.rotate(FastMath.HALF_PI, 0, 0); // Rotate to make it horizontal
Material topMaterial = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
topMaterial.setTexture("ColorMap", assetManager.loadTexture("Textures/Top.png")); // Top texture
topMaterial.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off); // Render both sides
topGeometry.setMaterial(topMaterial);
topGeometry.setQueueBucket(RenderQueue.Bucket.Sky);
topGeometry.setCullHint(Spatial.CullHint.Never);
// Attach caps to the view node
viewNode.attachChild(bottomGeometry);
viewNode.attachChild(topGeometry);
}
/**
* Sets up the sea surface in the scene. This includes creating the sea mesh,
* applying textures, and enabling shadows.

Binary file not shown.

After

Width:  |  Height:  |  Size: 707 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 478 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 MiB