Java Code Examples for com.jme3.scene.Geometry#updateGeometricState()

The following examples show how to use com.jme3.scene.Geometry#updateGeometricState() . 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: TestGeometryShader.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    Mesh mesh = new Mesh();
    mesh.setBuffer(VertexBuffer.Type.Index, 1, BufferUtils.createIntBuffer(new int[]{1}));
    mesh.setBuffer(VertexBuffer.Type.Position, 3, BufferUtils.createFloatBuffer(new float[]{0, 0, 0}));
    mesh.setMode(Mesh.Mode.Points);
    mesh.setBound(new BoundingBox(new Vector3f(0, 0, 0), 10, 10, 10));
    mesh.updateCounts();
    Geometry geometry = new Geometry("Test", mesh);
    geometry.updateGeometricState();
    geometry.setMaterial(new Material(assetManager, "Materials/Geom/SimpleGeom.j3md"));
    //geometry.getMaterial().getAdditionalRenderState().setFaceCullMode(RenderState.FaceCullMode.Off);
    //geometry.setMaterial(assetManager.loadMaterial("Materials/Geom/SimpleTess.j3md"));
    rootNode.attachChild(geometry);

    Geometry geometry1 = new Geometry("T1", new Sphere(10, 10, 1));
    geometry1.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"));
    rootNode.attachChild(geometry1);

}
 
Example 2
Source File: LightFilterTest.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Before
public void setUp() {
    filter = new DefaultLightFilter();
    
    cam = new Camera(512, 512);
    cam.setFrustumPerspective(45, 1, 1, 1000);
    cam.setLocation(Vector3f.ZERO);
    cam.lookAtDirection(Vector3f.UNIT_Z, Vector3f.UNIT_Y);
    filter.setCamera(cam);
    
    Box box = new Box(1, 1, 1);
    geom = new Geometry("geom", box);
    geom.setLocalTranslation(0, 0, 10);
    geom.updateGeometricState();
    list = new LightList(geom);
}
 
Example 3
Source File: AbstractShadowRendererVR.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * debug function to create a visible frustum
 */
protected Geometry createFrustum(Vector3f[] pts, int i) {
    WireFrustum frustum = new WireFrustum(pts);
    Geometry frustumMdl = new Geometry("f", frustum);
    frustumMdl.setCullHint(Spatial.CullHint.Never);
    frustumMdl.setShadowMode(ShadowMode.Off);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.getAdditionalRenderState().setWireframe(true);
    frustumMdl.setMaterial(mat);
    switch (i) {
        case 0:
            frustumMdl.getMaterial().setColor("Color", ColorRGBA.Pink);
            break;
        case 1:
            frustumMdl.getMaterial().setColor("Color", ColorRGBA.Red);
            break;
        case 2:
            frustumMdl.getMaterial().setColor("Color", ColorRGBA.Green);
            break;
        case 3:
            frustumMdl.getMaterial().setColor("Color", ColorRGBA.Blue);
            break;
        default:
            frustumMdl.getMaterial().setColor("Color", ColorRGBA.White);
            break;
    }

    frustumMdl.updateGeometricState();
    return frustumMdl;
}
 
Example 4
Source File: AbstractShadowRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * debug function to create a visible frustum
 */
protected Geometry createFrustum(Vector3f[] pts, int i) {
    WireFrustum frustum = new WireFrustum(pts);
    Geometry frustumMdl = new Geometry("f", frustum);
    frustumMdl.setCullHint(Spatial.CullHint.Never);
    frustumMdl.setShadowMode(ShadowMode.Off);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.getAdditionalRenderState().setWireframe(true);
    frustumMdl.setMaterial(mat);
    switch (i) {
        case 0:
            frustumMdl.getMaterial().setColor("Color", ColorRGBA.Pink);
            break;
        case 1:
            frustumMdl.getMaterial().setColor("Color", ColorRGBA.Red);
            break;
        case 2:
            frustumMdl.getMaterial().setColor("Color", ColorRGBA.Green);
            break;
        case 3:
            frustumMdl.getMaterial().setColor("Color", ColorRGBA.Blue);
            break;
        default:
            frustumMdl.getMaterial().setColor("Color", ColorRGBA.White);
            break;
    }

    frustumMdl.updateGeometricState();
    return frustumMdl;
}
 
Example 5
Source File: PssmShadowRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Geometry createFrustum(Vector3f[] pts, int i) {
    WireFrustum frustum = new WireFrustum(pts);
    Geometry frustumMdl = new Geometry("f", frustum);
    frustumMdl.setCullHint(Spatial.CullHint.Never);
    frustumMdl.setShadowMode(ShadowMode.Off);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.getAdditionalRenderState().setWireframe(true);
    frustumMdl.setMaterial(mat);
    switch (i) {
        case 0:
            frustumMdl.getMaterial().setColor("Color", ColorRGBA.Pink);
            break;
        case 1:
            frustumMdl.getMaterial().setColor("Color", ColorRGBA.Red);
            break;
        case 2:
            frustumMdl.getMaterial().setColor("Color", ColorRGBA.Green);
            break;
        case 3:
            frustumMdl.getMaterial().setColor("Color", ColorRGBA.Blue);
            break;
        default:
            frustumMdl.getMaterial().setColor("Color", ColorRGBA.White);
            break;
    }

    frustumMdl.updateGeometricState();
    return frustumMdl;
}
 
Example 6
Source File: PssmShadowRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Geometry createFrustum(Vector3f[] pts, int i) {
    WireFrustum frustum = new WireFrustum(pts);
    Geometry frustumMdl = new Geometry("f", frustum);
    frustumMdl.setCullHint(Spatial.CullHint.Never);
    frustumMdl.setShadowMode(ShadowMode.Off);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.getAdditionalRenderState().setWireframe(true);
    frustumMdl.setMaterial(mat);
    switch (i) {
        case 0:
            frustumMdl.getMaterial().setColor("Color", ColorRGBA.Pink);
            break;
        case 1:
            frustumMdl.getMaterial().setColor("Color", ColorRGBA.Red);
            break;
        case 2:
            frustumMdl.getMaterial().setColor("Color", ColorRGBA.Green);
            break;
        case 3:
            frustumMdl.getMaterial().setColor("Color", ColorRGBA.Blue);
            break;
        default:
            frustumMdl.getMaterial().setColor("Color", ColorRGBA.White);
            break;
    }

    frustumMdl.updateGeometricState();
    return frustumMdl;
}
 
Example 7
Source File: Octnode.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void renderBounds(RenderQueue rq, Matrix4f transform, WireBox box, Material mat){
        int numChilds = 0;
        for (int i = 0; i < 8; i++){
            if (children[i] != null){
                numChilds ++;
                break;
            }
        }
        if (geoms != null && numChilds == 0){
            BoundingBox bbox2 = new BoundingBox(bbox);
            bbox.transform(transform, bbox2);
//            WireBox box = new WireBox(bbox2.getXExtent(), bbox2.getYExtent(),
//                                      bbox2.getZExtent());
//            WireBox box = new WireBox(1,1,1);

            Geometry geom = new Geometry("bound", box);
            geom.setLocalTranslation(bbox2.getCenter());
            geom.setLocalScale(bbox2.getXExtent(), bbox2.getYExtent(),
                               bbox2.getZExtent());
            geom.updateGeometricState();
            geom.setMaterial(mat);
            rq.addToQueue(geom, Bucket.Opaque);
            box = null;
            geom = null;
        }
        for (int i = 0; i < 8; i++){
            if (children[i] != null){
                children[i].renderBounds(rq, transform, box, mat);
            }
        }
    }
 
Example 8
Source File: CubeField.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
   * Core Game Logic
   */
  private void gameLogic(float tpf){
  	//Subtract difficulty level in accordance to speed every 10 seconds
  	if(timer.getTimeInSeconds()>=coreTime2){
	coreTime2=timer.getTimeInSeconds()+10;
	if(difficulty<=lowCap){
		difficulty=lowCap;
	}
	else if(difficulty>lowCap){
		difficulty-=5;
		diffHelp+=1;
	}
}
  	
      if(speed<.1f){
          speed+=.000001f*tpf*fpsRate;
      }

      player.move(speed * tpf * fpsRate, 0, 0);
      if (cubeField.size() > difficulty){
          cubeField.remove(0);
      }else if (cubeField.size() != difficulty){
          randomizeCube();
      }

      if (cubeField.isEmpty()){
          requestClose(false);
      }else{
          for (int i = 0; i < cubeField.size(); i++){
          	
          	//better way to check collision
              Geometry playerModel = (Geometry) player.getChild(0);
              Geometry cubeModel = cubeField.get(i);
              cubeModel.updateGeometricState();

              BoundingVolume pVol = playerModel.getWorldBound();
              BoundingVolume vVol = cubeModel.getWorldBound();

              if (pVol.intersects(vVol)){
                  gameLost();
                  return;
              }
              //Remove cube if 10 world units behind player
              if (cubeField.get(i).getLocalTranslation().getX() + 10 < player.getLocalTranslation().getX()){
                  cubeField.get(i).removeFromParent();
                  cubeField.remove(cubeField.get(i));
              }

          }
      }

      Score += fpsRate * tpf;
      fpsScoreText.setText("Current Score: "+Score);
  }
 
Example 9
Source File: TestOctree.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void simpleInitApp() {
//        this.flyCam.setMoveSpeed(2000);
//        this.cam.setFrustumFar(10000);
        MeshLoader.AUTO_INTERLEAVE = false;

//        mat = new Material(assetManager, "Common/MatDefs/Misc/WireColor.j3md");
//        mat.setColor("Color", ColorRGBA.White);

//        mat2 = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");

        assetManager.registerLocator("quake3level.zip", "com.jme3.asset.plugins.ZipLocator");
        MaterialList matList = (MaterialList) assetManager.loadAsset("Scene.material");
        OgreMeshKey key = new OgreMeshKey("main.meshxml", matList);
        Spatial scene = assetManager.loadModel(key);

//        Spatial scene = assetManager.loadModel("Models/Teapot/teapot.obj");
//        scene.scale(3);

        DirectionalLight dl = new DirectionalLight();
        dl.setColor(ColorRGBA.White);
        dl.setDirection(new Vector3f(-1, -1, -1).normalize());
        rootNode.addLight(dl);

        DirectionalLight dl2 = new DirectionalLight();
        dl2.setColor(ColorRGBA.White);
        dl2.setDirection(new Vector3f(1, -1, 1).normalize());
        rootNode.addLight(dl2);

        // generate octree
//        tree = new Octree(scene, 20000);
        tree = new Octree(scene, 50);
        tree.construct();
        
        ArrayList<Geometry> globalGeomList = new ArrayList<Geometry>();
        tree.createFastOctnodes(globalGeomList);
        tree.generateFastOctnodeLinks();

        for (Geometry geom : globalGeomList){
            geom.addLight(dl);
            geom.addLight(dl2);
            geom.updateGeometricState();
        }
        
        globalGeoms = globalGeomList.toArray(new Geometry[0]);
        fastRoot = tree.getFastRoot();
        octBox = tree.getBound();

        viewPort.addProcessor(this);
    }