com.jme3.terrain.geomipmap.TerrainQuad Java Examples

The following examples show how to use com.jme3.terrain.geomipmap.TerrainQuad. 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
Source File: JmeTerrainQuad.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@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 File: TerrainTestTile.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * 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 #3
Source File: TerrainTestReadWrite.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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 #4
Source File: TerrainTestTile.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * 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 #5
Source File: DefaultTreeNodeFactory.java    From jmonkeybuilder with 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 #6
Source File: TestIssue1125.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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 #7
Source File: TerrainTestTile.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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 #8
Source File: TerrainTestTile.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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 #9
Source File: TerrainTestTile.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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 #10
Source File: TerrainTestTile.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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 #11
Source File: TerrainTestReadWrite.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 #12
Source File: TerrainCollisionTest.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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 #13
Source File: TerrainTestTile.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * 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
Source File: TerrainTestTile.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * 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 File: BresenhamTerrainPicker.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public BresenhamTerrainPicker(TerrainQuad root) {
    this.root = root;
}
 
Example #16
Source File: AddTerrainAction.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
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 #17
Source File: JmeTerrainQuad.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public JmeTerrainQuad(TerrainQuad spatial, JmeSpatialChildren children) {
    super(spatial, children);
    getLookupContents().add(spatial);
    this.geom = spatial;
    setName(spatial.getName());
}
 
Example #18
Source File: JmeTerrainQuad.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Class getExplorerObjectClass() {
    return TerrainQuad.class;
}
 
Example #19
Source File: TerrainTestTile.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
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 #20
Source File: JmeTerrainQuad.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public org.openide.nodes.Node[] createNodes(Object key, DataObject key2, boolean cookie) {
    JmeSpatialChildren children=new JmeSpatialChildren((com.jme3.scene.Spatial)key);
    children.setReadOnly(cookie);
    children.setDataObject(key2);
    return new org.openide.nodes.Node[]{new JmeTerrainQuad((TerrainQuad) key, children).setReadOnly(cookie)};
}
 
Example #21
Source File: SimpleLodThreshold.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public SimpleLodThreshold(Terrain terrain) {
    if (terrain instanceof TerrainQuad)
        this.size = ((TerrainQuad)terrain).getPatchSize();
}
 
Example #22
Source File: ImageTileLoader.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
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 #23
Source File: FractalTileLoader.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
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 #24
Source File: AssetTileLoader.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private TerrainQuad createNewQuad(Vector3f location) {
    TerrainQuad q = new TerrainQuad("Quad" + location, patchSize, quadSize, null);
    return q;
}
 
Example #25
Source File: TerrainTestTile.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
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 #26
Source File: SimpleLodThreshold.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public SimpleLodThreshold(Terrain terrain) {
    if (terrain instanceof TerrainQuad)
        this.size = ((TerrainQuad)terrain).getPatchSize();
}
 
Example #27
Source File: ImageTileLoader.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@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 #28
Source File: FractalTileLoader.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@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 #29
Source File: AssetTileLoader.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private TerrainQuad createNewQuad(Vector3f location) {
    TerrainQuad q = new TerrainQuad("Quad" + location, patchSize, quadSize, null);
    return q;
}
 
Example #30
Source File: BresenhamTerrainPicker.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public BresenhamTerrainPicker(TerrainQuad root) {
    this.root = root;
}