Java Code Examples for com.jme3.terrain.geomipmap.TerrainQuad

The following examples show how to use com.jme3.terrain.geomipmap.TerrainQuad. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
protected Sheet createSheet() {
    Sheet sheet = super.createSheet();
    Sheet.Set set = Sheet.createPropertiesSet();
    set.setDisplayName("TerrainQuad");
    set.setName(TerrainQuad.class.getName());
    TerrainQuad obj = geom;//getLookup().lookup(Spatial.class);
    if (obj == null) {
        return sheet;
    }

    set.put(makeProperty(obj, int.class, "getMaxLod", "Max Lod"));
    set.put(makeProperty(obj, short.class, "getQuadrant", "setQuadrant", "Quadrant"));

    sheet.put(set);
    return sheet;

}
 
Example 2
Source Project: jmonkeybuilder   Source File: DefaultTreeNodeFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@FxThread
public <T, V extends TreeNode<T>> @Nullable V createFor(@Nullable final T element, final long objectId) {

    if (element instanceof LayersRoot) {
        return unsafeCast(new LayersRootTreeNode((LayersRoot) element, objectId));
    } else if (element instanceof TerrainGrid) {
        return unsafeCast(new TerrainGridTreeNode((TerrainGrid) element, objectId));
    } else if (element instanceof TerrainQuad) {
        return unsafeCast(new TerrainQuadTreeNode((TerrainQuad) element, objectId));
    } else if (element instanceof SceneNode) {
        return unsafeCast(new SceneNodeTreeNode((SceneNode) element, objectId));
    } else if (element instanceof SceneLayer) {
        return unsafeCast(new SceneLayerTreeNode((SceneLayer) element, objectId));
    } else if (element instanceof Mesh) {
        return unsafeCast(new MeshTreeNode((Mesh) element, objectId));
    } else if (element instanceof Geometry) {
        return unsafeCast(new GeometryTreeNode<>((Geometry) element, objectId));
    } else if (element instanceof AudioNode) {
        return unsafeCast(new AudioTreeNode((AudioNode) element, objectId));
    } else if (element instanceof AssetLinkNode) {
        return unsafeCast(new AssetLinkNodeTreeNode((AssetLinkNode) element, objectId));
    } else if (element instanceof Node) {
        return unsafeCast(new NodeTreeNode<>((Node) element, objectId));
    } else if (element instanceof Material) {
        return unsafeCast(new MaterialTreeNode((Material) element, objectId));
    } else if (element instanceof SceneFiltersNode) {
        return unsafeCast(new SceneFiltersTreeNode((SceneFiltersNode) element, objectId));
    } else if (element instanceof SceneAppStatesNode) {
        return unsafeCast(new SceneAppStatesTreeNode((SceneAppStatesNode) element, objectId));
    } else if (element instanceof Filter) {
        return unsafeCast(new SceneFilterTreeNode((Filter) element, objectId));
    } else if (element instanceof SceneAppState) {
        return unsafeCast(new SceneAppStateTreeNode((SceneAppState) element, objectId));
    }

    return null;
}
 
Example 3
@Before
public void initQuad() {
    Texture heightMapImage = getAssetManager().loadTexture("Textures/Terrain/splat/mountains512.png");
    AbstractHeightMap map = new ImageBasedHeightMap(heightMapImage.getImage(), 0.25f);
    map.load();
    quad = new TerrainQuad("terrain", 65, 513, map.getHeightMap());
}
 
Example 4
private static void testHeightmapBuilding() {
    int s = 9;
    int b = 3;
    float[] hm = new float[s * s];
    for (int i = 0; i < s; i++) {
        for (int j = 0; j < s; j++) {
            hm[(i * s) + j] = i * j;
        }
    }

    for (int i = 0; i < s; i++) {
        for (int j = 0; j < s; j++) {
            System.out.print(hm[i * s + j] + " ");
        }
        System.out.println("");
    }

    TerrainQuad terrain = new TerrainQuad("terrain", b, s, hm);
    float[] hm2 = terrain.getHeightMap();
    boolean failed = false;
    for (int i = 0; i < s * s; i++) {
        if (hm[i] != hm2[i]) {
            failed = true;
        }
    }

    System.out.println("");
    if (failed) {
        System.out.println("Terrain heightmap building FAILED!!!");
        for (int i = 0; i < s; i++) {
            for (int j = 0; j < s; j++) {
                System.out.print(hm2[i * s + j] + " ");
            }
            System.out.println("");
        }
    } else {
        System.out.println("Terrain heightmap building PASSED");
    }
}
 
Example 5
/**
 * 1  3
 * 2  4
 */
@Override
public TerrainQuad getRightQuad(TerrainQuad center) {
    //System.out.println("lookup neighbour");
    if (center == terrain1)
        return terrain3;
    if (center == terrain2)
        return terrain4;
    
    return null;
}
 
Example 6
/**
 * 1  3
 * 2  4
 */
@Override
public TerrainQuad getLeftQuad(TerrainQuad center) {
    //System.out.println("lookup neighbour");
    if (center == terrain3)
        return terrain1;
    if (center == terrain4)
        return terrain2;
    
    return null;
}
 
Example 7
/**
 * 1  3
 * 2  4
 */
@Override
public TerrainQuad getTopQuad(TerrainQuad center) {
    //System.out.println("lookup neighbour");
    if (center == terrain2)
        return terrain1;
    if (center == terrain4)
        return terrain3;
    
    return null;
}
 
Example 8
/**
 * 1  3
 * 2  4
 */
@Override
public TerrainQuad getDownQuad(TerrainQuad center) {
    //System.out.println("lookup neighbour");
    if (center == terrain1)
        return terrain2;
    if (center == terrain3)
        return terrain4;
    
    return null;
}
 
Example 9
/**
 * Add 3x3 terrain to the scene and the PhysicsSpace.
 */
private void addTerrain() {
    int patchSize = 3;
    int mapSize = 3;
    TerrainQuad quad
            = new TerrainQuad("terrain", patchSize, mapSize, nineHeights);
    rootNode.attachChild(quad);
    quad.setMaterial(quadMaterial);

    CollisionShape shape = CollisionShapeFactory.createMeshShape(quad);
    float massForStatic = 0f;
    RigidBodyControl rbc = new RigidBodyControl(shape, massForStatic);
    rbc.setPhysicsSpace(physicsSpace);
    quad.addControl(rbc);
}
 
Example 10
private static void testHeightmapBuilding() {
    int s = 9;
    int b = 3;
    float[] hm = new float[s * s];
    for (int i = 0; i < s; i++) {
        for (int j = 0; j < s; j++) {
            hm[(i * s) + j] = i * j;
        }
    }

    for (int i = 0; i < s; i++) {
        for (int j = 0; j < s; j++) {
            System.out.print(hm[i * s + j] + " ");
        }
        System.out.println("");
    }

    TerrainQuad terrain = new TerrainQuad("terrain", b, s, hm);
    float[] hm2 = terrain.getHeightMap();
    boolean failed = false;
    for (int i = 0; i < s * s; i++) {
        if (hm[i] != hm2[i]) {
            failed = true;
        }
    }

    System.out.println("");
    if (failed) {
        System.out.println("Terrain heightmap building FAILED!!!");
        for (int i = 0; i < s; i++) {
            for (int j = 0; j < s; j++) {
                System.out.print(hm2[i * s + j] + " ");
            }
            System.out.println("");
        }
    } else {
        System.out.println("Terrain heightmap building PASSED");
    }
}
 
Example 11
/**
 * 1  3
 * 2  4
 */
public TerrainQuad getRightQuad(TerrainQuad center) {
    //System.out.println("lookup neighbour");
    if (center == terrain1)
        return terrain3;
    if (center == terrain2)
        return terrain4;
    
    return null;
}
 
Example 12
/**
 * 1  3
 * 2  4
 */
public TerrainQuad getLeftQuad(TerrainQuad center) {
    //System.out.println("lookup neighbour");
    if (center == terrain3)
        return terrain1;
    if (center == terrain4)
        return terrain2;
    
    return null;
}
 
Example 13
/**
 * 1  3
 * 2  4
 */
public TerrainQuad getTopQuad(TerrainQuad center) {
    //System.out.println("lookup neighbour");
    if (center == terrain2)
        return terrain1;
    if (center == terrain4)
        return terrain3;
    
    return null;
}
 
Example 14
/**
 * 1  3
 * 2  4
 */
public TerrainQuad getDownQuad(TerrainQuad center) {
    //System.out.println("lookup neighbour");
    if (center == terrain1)
        return terrain2;
    if (center == terrain3)
        return terrain4;
    
    return null;
}
 
Example 15
Source Project: jmonkeybuilder   Source File: TerrainQuadTreeNode.java    License: Apache License 2.0 4 votes vote down vote up
public TerrainQuadTreeNode(@NotNull final TerrainQuad element, final long objectId) {
    super(element, objectId);
}
 
Example 16
Source Project: jmonkeybuilder   Source File: TerrainPaintingComponent.java    License: Apache License 2.0 4 votes vote down vote up
@Override
@FxThread
public boolean isSupport(@NotNull Object object) {
    return object instanceof Node &&
            NodeUtils.findSpatial((Node) object, TerrainQuad.class::isInstance) != null;
}
 
Example 17
public BresenhamTerrainPicker(TerrainQuad root) {
    this.root = root;
}
 
Example 18
private TerrainQuad createNewQuad(Vector3f location) {
    TerrainQuad q = new TerrainQuad("Quad" + location, patchSize, quadSize, null);
    return q;
}
 
Example 19
@Override
public TerrainQuad getTerrainQuadAt(Vector3f location) {
    HeightMap heightMapAt = getHeightMapAt(location);
    TerrainQuad q = new TerrainQuad("Quad" + location, patchSize, quadSize, heightMapAt == null ? null : heightMapAt.getHeightMap());
    return q;
}
 
Example 20
@Override
public TerrainQuad getTerrainQuadAt(Vector3f location) {
    HeightMap heightMapAt = getHeightMapAt(location);
    TerrainQuad q = new TerrainQuad("Quad" + location, patchSize, quadSize, heightMapAt == null ? null : heightMapAt.getHeightMap());
    return q;
}
 
Example 21
public SimpleLodThreshold(Terrain terrain) {
    if (terrain instanceof TerrainQuad)
        this.size = ((TerrainQuad)terrain).getPatchSize();
}
 
Example 22
TiledTerrain() {
    // TERRAIN TEXTURE material
    matTerrain = new Material(assetManager, "Common/MatDefs/Terrain/TerrainLighting.j3md");
    matTerrain.setBoolean("useTriPlanarMapping", false);
    matTerrain.setBoolean("WardIso", true);
    matTerrain.setFloat("Shininess", 0);

    // GRASS texture
    Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
    grass.setWrap(WrapMode.Repeat);
    matTerrain.setTexture("DiffuseMap", grass);
    matTerrain.setFloat("DiffuseMap_0_scale", grassScale);

    // CREATE THE TERRAIN
    terrain1 = new TerrainQuad("terrain 1", 65, 513, null);
    terrain1.setMaterial(matTerrain);
    terrain1.setLocalTranslation(-256, -100, -256);
    terrain1.setLocalScale(1f, 1f, 1f);
    this.attachChild(terrain1);

    terrain2 = new TerrainQuad("terrain 2", 65, 513, null);
    terrain2.setMaterial(matTerrain);
    terrain2.setLocalTranslation(-256, -100, 256);
    terrain2.setLocalScale(1f, 1f, 1f);
    this.attachChild(terrain2);

    terrain3 = new TerrainQuad("terrain 3", 65, 513, null);
    terrain3.setMaterial(matTerrain);
    terrain3.setLocalTranslation(256, -100, -256);
    terrain3.setLocalScale(1f, 1f, 1f);
    this.attachChild(terrain3);

    terrain4 = new TerrainQuad("terrain 4", 65, 513, null);
    terrain4.setMaterial(matTerrain);
    terrain4.setLocalTranslation(256, -100, 256);
    terrain4.setLocalScale(1f, 1f, 1f);
    this.attachChild(terrain4);
    
    terrain1.setNeighbourFinder(this);
    terrain2.setNeighbourFinder(this);
    terrain3.setNeighbourFinder(this);
    terrain4.setNeighbourFinder(this);
    
    MultiTerrainLodControl lodControl = new MultiTerrainLodControl(getCamera());
    lodControl.setLodCalculator( new DistanceLodCalculator(65, 2.7f) ); // patch size, and a multiplier
    lodControl.addTerrain(terrain1);
    lodControl.addTerrain(terrain2);
    lodControl.addTerrain(terrain3);// order of these seems to matter
    lodControl.addTerrain(terrain4);
    this.addControl(lodControl);
    
}
 
Example 23
public BresenhamTerrainPicker(TerrainQuad root) {
    this.root = root;
}
 
Example 24
private TerrainQuad createNewQuad(Vector3f location) {
    TerrainQuad q = new TerrainQuad("Quad" + location, patchSize, quadSize, null);
    return q;
}
 
Example 25
public TerrainQuad getTerrainQuadAt(Vector3f location) {
    HeightMap heightMapAt = getHeightMapAt(location);
    TerrainQuad q = new TerrainQuad("Quad" + location, patchSize, quadSize, heightMapAt == null ? null : heightMapAt.getHeightMap());
    return q;
}
 
Example 26
public TerrainQuad getTerrainQuadAt(Vector3f location) {
    HeightMap heightMapAt = getHeightMapAt(location);
    TerrainQuad q = new TerrainQuad("Quad" + location, patchSize, quadSize, heightMapAt == null ? null : heightMapAt.getHeightMap());
    return q;
}
 
Example 27
public SimpleLodThreshold(Terrain terrain) {
    if (terrain instanceof TerrainQuad)
        this.size = ((TerrainQuad)terrain).getPatchSize();
}
 
Example 28
TiledTerrain() {
    // TERRAIN TEXTURE material
    matTerrain = new Material(assetManager, "Common/MatDefs/Terrain/TerrainLighting.j3md");
    matTerrain.setBoolean("useTriPlanarMapping", false);
    matTerrain.setBoolean("WardIso", true);
    matTerrain.setFloat("Shininess", 0);

    // GRASS texture
    Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
    grass.setWrap(WrapMode.Repeat);
    matTerrain.setTexture("DiffuseMap", grass);
    matTerrain.setFloat("DiffuseMap_0_scale", grassScale);

    // CREATE THE TERRAIN
    terrain1 = new TerrainQuad("terrain 1", 65, 513, null);
    terrain1.setMaterial(matTerrain);
    terrain1.setLocalTranslation(-256, -100, -256);
    terrain1.setLocalScale(1f, 1f, 1f);
    this.attachChild(terrain1);

    terrain2 = new TerrainQuad("terrain 2", 65, 513, null);
    terrain2.setMaterial(matTerrain);
    terrain2.setLocalTranslation(-256, -100, 256);
    terrain2.setLocalScale(1f, 1f, 1f);
    this.attachChild(terrain2);

    terrain3 = new TerrainQuad("terrain 3", 65, 513, null);
    terrain3.setMaterial(matTerrain);
    terrain3.setLocalTranslation(256, -100, -256);
    terrain3.setLocalScale(1f, 1f, 1f);
    this.attachChild(terrain3);

    terrain4 = new TerrainQuad("terrain 4", 65, 513, null);
    terrain4.setMaterial(matTerrain);
    terrain4.setLocalTranslation(256, -100, 256);
    terrain4.setLocalScale(1f, 1f, 1f);
    this.attachChild(terrain4);
    
    terrain1.setNeighbourFinder(this);
    terrain2.setNeighbourFinder(this);
    terrain3.setNeighbourFinder(this);
    terrain4.setNeighbourFinder(this);
    
    MultiTerrainLodControl lodControl = new MultiTerrainLodControl(getCamera());
    lodControl.setLodCalculator( new DistanceLodCalculator(65, 2.7f) ); // patch size, and a multiplier
    lodControl.addTerrain(terrain1);
    lodControl.addTerrain(terrain2);
    lodControl.addTerrain(terrain3);// order of these seems to matter
    lodControl.addTerrain(terrain4);
    this.addControl(lodControl);
    
}
 
Example 29
protected Spatial doCreateTerrain(Node parent,
                                   int totalSize,
                                   int patchSize,
                                   int alphaTextureSize,
                                   float[] heightmapData,
                                   String sceneName,
                                   org.openide.nodes.Node selectedNode) throws IOException
   {
       final ProjectAssetManager manager = selectedNode.getLookup().lookup(ProjectAssetManager.class);
       
       Terrain terrain = new TerrainQuad("terrain-"+sceneName, patchSize, totalSize, heightmapData); //TODO make this pluggable for different Terrain implementations
       com.jme3.material.Material mat = new com.jme3.material.Material(manager, "Common/MatDefs/Terrain/TerrainLighting.j3md");

       String assetFolder = "";
       if (manager != null && manager instanceof ProjectAssetManager)
           assetFolder = ((ProjectAssetManager)manager).getAssetFolderName();

       // write out 3 alpha blend images
       for (int i=0; i<TerrainEditorController.NUM_ALPHA_TEXTURES; i++) {
           BufferedImage alphaBlend = new BufferedImage(alphaTextureSize, alphaTextureSize, BufferedImage.TYPE_INT_ARGB);
           if (i == 0) {
               // the first alpha level should be opaque so we see the first texture over the whole terrain
               for (int h=0; h<alphaTextureSize; h++)
                   for (int w=0; w<alphaTextureSize; w++)
                       alphaBlend.setRGB(w, h, 0x00FF0000);//argb
           }
           File alphaFolder = new File(assetFolder+"/Textures/terrain-alpha/");
           if (!alphaFolder.exists())
               alphaFolder.mkdir();
           String alphaBlendFileName = "/Textures/terrain-alpha/"+sceneName+"-"+((Node)terrain).getName()+"-alphablend"+i+".png";
           File alphaImageFile = new File(assetFolder+alphaBlendFileName);
           ImageIO.write(alphaBlend, "png", alphaImageFile);
           Texture tex = manager.loadAsset(new TextureKey(alphaBlendFileName, false));
           if (i == 0)
               mat.setTexture("AlphaMap", tex);
           else if (i == 1)
               mat.setTexture("AlphaMap_1", tex);
           else if (i == 2)
               mat.setTexture("AlphaMap_2", tex);
       }
       
       Texture defaultTexture = manager.loadTexture(TerrainEditorController.DEFAULT_TERRAIN_TEXTURE);
       
       // copy the default texture to the assets folder if it doesn't exist there yet
       String dirtTextureName = "/Textures/dirt.jpg";
       File dirtTextureFile = new File(assetFolder+dirtTextureName);
       if (!dirtTextureFile.exists()) {
           BufferedImage bi = ImageToAwt.convert(defaultTexture.getImage(), false, true, 0);
           ImageIO.write(bi, "jpg", dirtTextureFile);
       }
       // give the first layer default texture
       Texture dirtTexture = manager.loadTexture(dirtTextureName);
       dirtTexture.setWrap(WrapMode.Repeat);
       mat.setTexture("DiffuseMap", dirtTexture);
       mat.setFloat("DiffuseMap_0_scale", TerrainEditorController.DEFAULT_TEXTURE_SCALE);
       mat.setBoolean("WardIso", true);

       ((Node)terrain).setMaterial(mat);
       ((Node)terrain).setModelBound(new BoundingBox());
       ((Node)terrain).updateModelBound();
       ((Node)terrain).setLocalTranslation(0, 0, 0);
       ((Node)terrain).setLocalScale(1f, 1f, 1f);

       // add the lod control
       TerrainLodControl control = new TerrainLodControl(terrain, SceneApplication.getApplication().getCamera());
       control.setLodCalculator(new DistanceLodCalculator(patchSize, 2.7f));
((Node)terrain).addControl(control);

       parent.attachChild((Node)terrain);

       //setNeedsSave(true);
       //addSpatialUndo(parent, (Node)terrain, jmeNodeParent);
       
       return (Spatial)terrain;
   }
 
Example 30
public JmeTerrainQuad(TerrainQuad spatial, JmeSpatialChildren children) {
    super(spatial, children);
    getLookupContents().add(spatial);
    this.geom = spatial;
    setName(spatial.getName());
}