Java Code Examples for com.jme3.scene.Node#getChild()

The following examples show how to use com.jme3.scene.Node#getChild() . 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: TestParallax.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void setupFloor() {
    mat = assetManager.loadMaterial("Textures/Terrain/BrickWall/BrickWall2.j3m");
    mat.getTextureParam("DiffuseMap").getTextureValue().setWrap(WrapMode.Repeat);
    mat.getTextureParam("NormalMap").getTextureValue().setWrap(WrapMode.Repeat);
    mat.setFloat("Shininess", 0);

    Node floorGeom = (Node) assetManager.loadAsset("Models/WaterTest/WaterTest.mesh.xml");
    Geometry g = ((Geometry) floorGeom.getChild(0));
    g.getMesh().scaleTextureCoordinates(new Vector2f(10, 10));
    TangentBinormalGenerator.generate(floorGeom);
    floorGeom.setLocalTranslation(0, 22, 0);
    floorGeom.setLocalScale(100);

    floorGeom.setMaterial(mat);        
    rootNode.attachChild(floorGeom);
}
 
Example 2
Source File: TestFancyCar.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private Geometry findGeom(Spatial spatial, String name) {
    if (spatial instanceof Node) {
        Node node = (Node) spatial;
        for (int i = 0; i < node.getQuantity(); i++) {
            Spatial child = node.getChild(i);
            Geometry result = findGeom(child, name);
            if (result != null) {
                return result;
            }
        }
    } else if (spatial instanceof Geometry) {
        if (spatial.getName().startsWith(name)) {
            return (Geometry) spatial;
        }
    }
    return null;
}
 
Example 3
Source File: PMDPhysicsWorld.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void updateRigidBodyPos() {
    for (PMDRigidBody rbarray[] : nodeRigidBodyArray) {
        for (int i = 0; i < rbarray.length; i++) {
            PMDRigidBody rb = rbarray[i];
            if (true) {
                PMDNode pmdNode = rb.getPmdNode();
                Node rigidBodyNode = pmdNode.getRigidBodyNode();
                if (rigidBodyNode != null) {
                    Spatial spaital = rigidBodyNode.getChild(i);
                    spaital.setLocalRotation(rb.getPhysicsRotation());
                    spaital.setLocalTranslation(rb.getPhysicsLocation());
                }
            }
        }
    }
}
 
Example 4
Source File: TestGimpactShape.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private RigidBodyControl drop(Vector3f offset, String model, float scale, float mass) {
    scale *= scaleMod;
    Node n = (Node) assetManager.loadModel(model);
    n.setLocalTranslation(offset);
    n.rotate(0, 0, -FastMath.HALF_PI);

    Geometry tp = ((Geometry) n.getChild(0));
    tp.scale(scale);
    Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    tp.setMaterial(mat);

    Mesh mesh = tp.getMesh();
    GImpactCollisionShape shape = new GImpactCollisionShape(mesh);
    shape.setScale(new Vector3f(scale, scale, scale));

    RigidBodyControl control = new RigidBodyControl(shape, mass);
    n.addControl(control);
    addObject(n);
    return control;
}
 
Example 5
Source File: TestFancyCar.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private Geometry findGeom(Spatial spatial, String name) {
    if (spatial instanceof Node) {
        Node node = (Node) spatial;
        for (int i = 0; i < node.getQuantity(); i++) {
            Spatial child = node.getChild(i);
            Geometry result = findGeom(child, name);
            if (result != null) {
                return result;
            }
        }
    } else if (spatial instanceof Geometry) {
        if (spatial.getName().startsWith(name)) {
            return (Geometry) spatial;
        }
    }
    return null;
}
 
Example 6
Source File: TestIssue1004.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    BulletAppState bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    String sinbadPath = "Models/Sinbad/SinbadOldAnim.j3o";
    Node sinbad = (Node) assetManager.loadModel(sinbadPath);

    Geometry geometry = (Geometry) sinbad.getChild(0);
    Mesh mesh = geometry.getMesh();
    VertexBuffer.Type bufferType = VertexBuffer.Type.BoneIndex;
    VertexBuffer vertexBuffer = mesh.getBuffer(bufferType);

    // Remove the existing bone-index buffer.
    mesh.getBufferList().remove(vertexBuffer);
    mesh.getBuffers().remove(bufferType.ordinal());

    // Copy the 8-bit bone indices to 16-bit indices.
    ByteBuffer oldBuffer = (ByteBuffer) vertexBuffer.getDataReadOnly();
    int numComponents = oldBuffer.limit();
    oldBuffer.rewind();
    short[] shortArray = new short[numComponents];
    for (int index = 0; oldBuffer.hasRemaining(); ++index) {
        shortArray[index] = oldBuffer.get();
    }

    // Add the 16-bit bone indices to the mesh.
    mesh.setBuffer(bufferType, 4, shortArray);

    KinematicRagdollControl ragdoll = new KinematicRagdollControl(0.5f);
    sinbad.addControl(ragdoll);

    stop();
}
 
Example 7
Source File: TestHoverTank.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    Node tank = (Node) assetManager.loadModel("Models/HoverTank/Tank2.mesh.xml");

    flyCam.setEnabled(false);
    ChaseCamera chaseCam = new ChaseCamera(cam, tank, inputManager);
    chaseCam.setSmoothMotion(true);
    chaseCam.setMaxDistance(100000);
    chaseCam.setMinVerticalRotation(-FastMath.PI / 2);
    viewPort.setBackgroundColor(ColorRGBA.DarkGray);

    Geometry tankGeom = (Geometry) tank.getChild(0);
    LodControl control = new LodControl();
    tankGeom.addControl(control);
    rootNode.attachChild(tank);

    Vector3f lightDir = new Vector3f(-0.8719428f, -0.46824604f, 0.14304268f);
    DirectionalLight dl = new DirectionalLight();
    dl.setColor(new ColorRGBA(1.0f, 0.92f, 0.75f, 1f));
    dl.setDirection(lightDir);

    Vector3f lightDir2 = new Vector3f(0.70518064f, 0.5902297f, -0.39287305f);
    DirectionalLight dl2 = new DirectionalLight();
    dl2.setColor(new ColorRGBA(0.7f, 0.85f, 1.0f, 1f));
    dl2.setDirection(lightDir2);

    rootNode.addLight(dl);
    rootNode.addLight(dl2);
    rootNode.attachChild(tank);

    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    BloomFilter bf = new BloomFilter(BloomFilter.GlowMode.Objects);
    bf.setBloomIntensity(2.0f);
    bf.setExposurePower(1.3f);
    fpp.addFilter(bf);
    BloomUI bui = new BloomUI(inputManager, bf);
    viewPort.addProcessor(fpp);
}
 
Example 8
Source File: TestUserData.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    Node scene = (Node) assetManager.loadModel("Scenes/DotScene/DotScene.scene");
    System.out.println("Scene: " + scene);

    Spatial testNode = scene.getChild("TestNode");
    System.out.println("TestNode: "+ testNode);

    for (String key : testNode.getUserDataKeys()){
        System.out.println("Property " + key + " = " + testNode.getUserData(key));
    }
}
 
Example 9
Source File: ModelConverter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static void optimizeScene(Spatial source, boolean toFixed){
    if (source instanceof Geometry){
        Geometry geom = (Geometry) source;
        Mesh mesh = geom.getMesh();
        optimize(mesh, toFixed);
    }else if (source instanceof Node){
        Node node = (Node) source;
        for (int i = node.getQuantity() - 1; i >= 0; i--){
            Spatial child = node.getChild(i);
            optimizeScene(child, toFixed);
        }
    }
}
 
Example 10
Source File: TestBatchLod.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void simpleInitApp() {
//        inputManager.registerKeyBinding("USELOD", KeyInput.KEY_L);

        DirectionalLight dl = new DirectionalLight();
        dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
        rootNode.addLight(dl);

        Node teapotNode = (Node) assetManager.loadModel("Models/Teapot/Teapot.mesh.xml");
        Geometry teapot = (Geometry) teapotNode.getChild(0);

        Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
        mat.setFloat("Shininess", 16f);
        mat.setBoolean("VertexLighting", true);
        teapot.setMaterial(mat);

        // show normals as material
        //Material mat = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
        flyCam.setMoveSpeed(5);
        for (int y = -5; y < 5; y++) {
            for (int x = -5; x < 5; x++) {
                Geometry clonePot = teapot.clone();

                //clonePot.setMaterial(mat);
                clonePot.setLocalTranslation(x * .5f, 0, y * .5f);
                clonePot.setLocalScale(.15f);
                clonePot.setMaterial(mat);
                rootNode.attachChild(clonePot);
            }
        }
        GeometryBatchFactory.optimize(rootNode, true);
        LodControl control = new LodControl();
        rootNode.getChild(0).addControl(control);
        cam.setLocation(new Vector3f(-1.0748308f, 1.35778f, -1.5380064f));
        cam.setRotation(new Quaternion(0.18343268f, 0.34531063f, -0.069015436f, 0.9177962f));

    }
 
Example 11
Source File: TestLodStress.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void simpleInitApp() {
        DirectionalLight dl = new DirectionalLight();
        dl.setDirection(new Vector3f(-1,-1,-1).normalizeLocal());
        rootNode.addLight(dl);

        Node teapotNode = (Node) assetManager.loadModel("Models/Teapot/Teapot.mesh.xml");
        Geometry teapot = (Geometry) teapotNode.getChild(0);
        
//        Sphere sph = new Sphere(16, 16, 4);
//        Geometry teapot = new Geometry("teapot", sph);

        Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
        mat.setFloat("Shininess", 16f);
        mat.setBoolean("VertexLighting", true);
        teapot.setMaterial(mat);
        
       // show normals as material
        //Material mat = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");

        for (int y = -10; y < 10; y++){
            for (int x = -10; x < 10; x++){
                Geometry clonePot = teapot.clone();
                
                //clonePot.setMaterial(mat);
                clonePot.setLocalTranslation(x * .5f, 0, y * .5f);
                clonePot.setLocalScale(.15f);
                
                LodControl control = new LodControl();
                clonePot.addControl(control);
                rootNode.attachChild(clonePot);
            }
        }

        cam.setLocation(new Vector3f(8.378951f, 5.4324f, 8.795956f));
        cam.setRotation(new Quaternion(-0.083419204f, 0.90370524f, -0.20599906f, -0.36595422f));
    }
 
Example 12
Source File: TestUserData.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void simpleInitApp() {
    Node scene = (Node) assetManager.loadModel("Scenes/DotScene/DotScene.scene");
    System.out.println("Scene: " + scene);

    Spatial testNode = scene.getChild("TestNode");
    System.out.println("TestNode: "+ testNode);

    for (String key : testNode.getUserDataKeys()){
        System.out.println("Property " + key + " = " + testNode.getUserData(key));
    }
}
 
Example 13
Source File: TestHoverTank.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    Node tank = (Node) assetManager.loadModel("Models/HoverTank/Tank2.mesh.xml");

    flyCam.setEnabled(false);
    ChaseCamera chaseCam = new ChaseCamera(cam, tank, inputManager);
    chaseCam.setSmoothMotion(true);
    chaseCam.setMaxDistance(100000);
    chaseCam.setMinVerticalRotation(-FastMath.PI / 2);
    viewPort.setBackgroundColor(ColorRGBA.DarkGray);

    Geometry tankGeom = (Geometry) tank.getChild(0);
    LodControl control = new LodControl();
    tankGeom.addControl(control);
    rootNode.attachChild(tank);

    Vector3f lightDir = new Vector3f(-0.8719428f, -0.46824604f, 0.14304268f);
    DirectionalLight dl = new DirectionalLight();
    dl.setColor(new ColorRGBA(1.0f, 0.92f, 0.75f, 1f));
    dl.setDirection(lightDir);

    Vector3f lightDir2 = new Vector3f(0.70518064f, 0.5902297f, -0.39287305f);
    DirectionalLight dl2 = new DirectionalLight();
    dl2.setColor(new ColorRGBA(0.7f, 0.85f, 1.0f, 1f));
    dl2.setDirection(lightDir2);

    rootNode.addLight(dl);
    rootNode.addLight(dl2);
    rootNode.attachChild(tank);

    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    BloomFilter bf = new BloomFilter(BloomFilter.GlowMode.Objects);
    bf.setBloomIntensity(2.0f);
    bf.setExposurePower(1.3f);
    fpp.addFilter(bf);
    BloomUI bui = new BloomUI(inputManager, bf);
    viewPort.addProcessor(fpp);
}
 
Example 14
Source File: TestBlenderObjectAnim.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * This method finds a node of a given name.
 * @param rootNode the root node to search
 * @param name the name of the searched node
 * @return the found node or null
 */
private Spatial findNode(Node rootNode, String name) {
    if (name.equals(rootNode.getName())) {
        return rootNode;
    }
    return rootNode.getChild(name);
}
 
Example 15
Source File: TestBlenderAnim.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * This method finds a node of a given name.
 * @param rootNode the root node to search
 * @param name the name of the searched node
 * @return the found node or null
 */
private Spatial findNode(Node rootNode, String name) {
    if (name.equals(rootNode.getName())) {
        return rootNode;
    }
    return rootNode.getChild(name);
}
 
Example 16
Source File: TestBatchLod.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
    public void simpleInitApp() {
//        inputManager.registerKeyBinding("USELOD", KeyInput.KEY_L);

        DirectionalLight dl = new DirectionalLight();
        dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
        rootNode.addLight(dl);

        Node teapotNode = (Node) assetManager.loadModel("Models/Teapot/Teapot.mesh.xml");
        Geometry teapot = (Geometry) teapotNode.getChild(0);

        Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
        mat.setFloat("Shininess", 16f);
        mat.setBoolean("VertexLighting", true);
        teapot.setMaterial(mat);

        // show normals as material
        //Material mat = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
        flyCam.setMoveSpeed(5);
        for (int y = -5; y < 5; y++) {
            for (int x = -5; x < 5; x++) {
                Geometry clonePot = teapot.clone();

                //clonePot.setMaterial(mat);
                clonePot.setLocalTranslation(x * .5f, 0, y * .5f);
                clonePot.setLocalScale(.15f);
                clonePot.setMaterial(mat);
                rootNode.attachChild(clonePot);
            }
        }
        GeometryBatchFactory.optimize(rootNode, true);
        LodControl control = new LodControl();
        rootNode.getChild(0).addControl(control);
        cam.setLocation(new Vector3f(-1.0748308f, 1.35778f, -1.5380064f));
        cam.setRotation(new Quaternion(0.18343268f, 0.34531063f, -0.069015436f, 0.9177962f));

    }
 
Example 17
Source File: VehicleControl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Control cloneForSpatial(Spatial spatial) {
    VehicleControl control = new VehicleControl(collisionShape, mass);
    control.setAngularFactor(getAngularFactor());
    control.setAngularSleepingThreshold(getAngularSleepingThreshold());
    control.setAngularVelocity(getAngularVelocity());
    control.setCcdMotionThreshold(getCcdMotionThreshold());
    control.setCcdSweptSphereRadius(getCcdSweptSphereRadius());
    control.setCollideWithGroups(getCollideWithGroups());
    control.setCollisionGroup(getCollisionGroup());
    control.setDamping(getLinearDamping(), getAngularDamping());
    control.setFriction(getFriction());
    control.setGravity(getGravity());
    control.setKinematic(isKinematic());
    control.setLinearSleepingThreshold(getLinearSleepingThreshold());
    control.setLinearVelocity(getLinearVelocity());
    control.setPhysicsLocation(getPhysicsLocation());
    control.setPhysicsRotation(getPhysicsRotationMatrix());
    control.setRestitution(getRestitution());

    control.setFrictionSlip(getFrictionSlip());
    control.setMaxSuspensionTravelCm(getMaxSuspensionTravelCm());
    control.setSuspensionStiffness(getSuspensionStiffness());
    control.setSuspensionCompression(tuning.suspensionCompression);
    control.setSuspensionDamping(tuning.suspensionDamping);
    control.setMaxSuspensionForce(getMaxSuspensionForce());

    for (Iterator<VehicleWheel> it = wheels.iterator(); it.hasNext();) {
        VehicleWheel wheel = it.next();
        VehicleWheel newWheel = control.addWheel(wheel.getLocation(), wheel.getDirection(), wheel.getAxle(), wheel.getRestLength(), wheel.getRadius(), wheel.isFrontWheel());
        newWheel.setFrictionSlip(wheel.getFrictionSlip());
        newWheel.setMaxSuspensionTravelCm(wheel.getMaxSuspensionTravelCm());
        newWheel.setSuspensionStiffness(wheel.getSuspensionStiffness());
        newWheel.setWheelsDampingCompression(wheel.getWheelsDampingCompression());
        newWheel.setWheelsDampingRelaxation(wheel.getWheelsDampingRelaxation());
        newWheel.setMaxSuspensionForce(wheel.getMaxSuspensionForce());

        //TODO: bad way finding children!
        if (spatial instanceof Node) {
            Node node = (Node) spatial;
            Spatial wheelSpat = node.getChild(wheel.getWheelSpatial().getName());
            if (wheelSpat != null) {
                newWheel.setWheelSpatial(wheelSpat);
            }
        }
    }
    control.setApplyPhysicsLocal(isApplyPhysicsLocal());

    control.setSpatial(spatial);
    return control;
}
 
Example 18
Source File: VehicleControl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void render(RenderManager rm, ViewPort vp) {
    if (enabled && space != null && space.getDebugManager() != null) {
        if (debugShape == null) {
            attachDebugShape(space.getDebugManager());
        }
        Node debugNode = (Node) debugShape;
        debugShape.setLocalTranslation(spatial.getWorldTranslation());
        debugShape.setLocalRotation(spatial.getWorldRotation());
        int i = 0;
        for (Iterator<VehicleWheel> it = wheels.iterator(); it.hasNext();) {
            VehicleWheel physicsVehicleWheel = it.next();
            Vector3f location = physicsVehicleWheel.getLocation().clone();
            Vector3f direction = physicsVehicleWheel.getDirection().clone();
            Vector3f axle = physicsVehicleWheel.getAxle().clone();
            float restLength = physicsVehicleWheel.getRestLength();
            float radius = physicsVehicleWheel.getRadius();

            Geometry locGeom = (Geometry) debugNode.getChild("WheelLocationDebugShape" + i);
            Geometry dirGeom = (Geometry) debugNode.getChild("WheelDirectionDebugShape" + i);
            Geometry axleGeom = (Geometry) debugNode.getChild("WheelAxleDebugShape" + i);
            Geometry wheelGeom = (Geometry) debugNode.getChild("WheelRadiusDebugShape" + i);

            Arrow locArrow = (Arrow) locGeom.getMesh();
            locArrow.setArrowExtent(location);
            Arrow axleArrow = (Arrow) axleGeom.getMesh();
            axleArrow.setArrowExtent(axle.normalizeLocal().multLocal(0.3f));
            Arrow wheelArrow = (Arrow) wheelGeom.getMesh();
            wheelArrow.setArrowExtent(direction.normalizeLocal().multLocal(radius));
            Arrow dirArrow = (Arrow) dirGeom.getMesh();
            dirArrow.setArrowExtent(direction.normalizeLocal().multLocal(restLength));

            dirGeom.setLocalTranslation(location);
            axleGeom.setLocalTranslation(location.addLocal(direction));
            wheelGeom.setLocalTranslation(location);
            i++;
        }
        debugShape.updateLogicalState(0);
        debugShape.updateGeometricState();
        rm.renderScene(debugShape, vp);
    }
}
 
Example 19
Source File: VehicleControl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Control cloneForSpatial(Spatial spatial) {
    VehicleControl control = new VehicleControl(collisionShape, mass);
    control.setAngularFactor(getAngularFactor());
    control.setAngularSleepingThreshold(getAngularSleepingThreshold());
    control.setAngularVelocity(getAngularVelocity());
    control.setCcdMotionThreshold(getCcdMotionThreshold());
    control.setCcdSweptSphereRadius(getCcdSweptSphereRadius());
    control.setCollideWithGroups(getCollideWithGroups());
    control.setCollisionGroup(getCollisionGroup());
    control.setDamping(getLinearDamping(), getAngularDamping());
    control.setFriction(getFriction());
    control.setGravity(getGravity());
    control.setKinematic(isKinematic());
    control.setLinearSleepingThreshold(getLinearSleepingThreshold());
    control.setLinearVelocity(getLinearVelocity());
    control.setPhysicsLocation(getPhysicsLocation());
    control.setPhysicsRotation(getPhysicsRotationMatrix());
    control.setRestitution(getRestitution());

    control.setFrictionSlip(getFrictionSlip());
    control.setMaxSuspensionTravelCm(getMaxSuspensionTravelCm());
    control.setSuspensionStiffness(getSuspensionStiffness());
    control.setSuspensionCompression(tuning.suspensionCompression);
    control.setSuspensionDamping(tuning.suspensionDamping);
    control.setMaxSuspensionForce(getMaxSuspensionForce());

    for (Iterator<VehicleWheel> it = wheels.iterator(); it.hasNext();) {
        VehicleWheel wheel = it.next();
        VehicleWheel newWheel = control.addWheel(wheel.getLocation(), wheel.getDirection(), wheel.getAxle(), wheel.getRestLength(), wheel.getRadius(), wheel.isFrontWheel());
        newWheel.setFrictionSlip(wheel.getFrictionSlip());
        newWheel.setMaxSuspensionTravelCm(wheel.getMaxSuspensionTravelCm());
        newWheel.setSuspensionStiffness(wheel.getSuspensionStiffness());
        newWheel.setWheelsDampingCompression(wheel.getWheelsDampingCompression());
        newWheel.setWheelsDampingRelaxation(wheel.getWheelsDampingRelaxation());
        newWheel.setMaxSuspensionForce(wheel.getMaxSuspensionForce());

        //TODO: bad way finding children!
        if (spatial instanceof Node) {
            Node node = (Node) spatial;
            Spatial wheelSpat = node.getChild(wheel.getWheelSpatial().getName());
            if (wheelSpat != null) {
                newWheel.setWheelSpatial(wheelSpat);
            }
        }
    }
    control.setApplyPhysicsLocal(isApplyPhysicsLocal());

    control.setSpatial(spatial);
    return control;
}
 
Example 20
Source File: VehicleControl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void render(RenderManager rm, ViewPort vp) {
    if (enabled && space != null && space.getDebugManager() != null) {
        if (debugShape == null) {
            attachDebugShape(space.getDebugManager());
        }
        Node debugNode = (Node) debugShape;
        debugShape.setLocalTranslation(spatial.getWorldTranslation());
        debugShape.setLocalRotation(spatial.getWorldRotation());
        int i = 0;
        for (Iterator<VehicleWheel> it = wheels.iterator(); it.hasNext();) {
            VehicleWheel physicsVehicleWheel = it.next();
            Vector3f location = physicsVehicleWheel.getLocation().clone();
            Vector3f direction = physicsVehicleWheel.getDirection().clone();
            Vector3f axle = physicsVehicleWheel.getAxle().clone();
            float restLength = physicsVehicleWheel.getRestLength();
            float radius = physicsVehicleWheel.getRadius();

            Geometry locGeom = (Geometry) debugNode.getChild("WheelLocationDebugShape" + i);
            Geometry dirGeom = (Geometry) debugNode.getChild("WheelDirectionDebugShape" + i);
            Geometry axleGeom = (Geometry) debugNode.getChild("WheelAxleDebugShape" + i);
            Geometry wheelGeom = (Geometry) debugNode.getChild("WheelRadiusDebugShape" + i);

            Arrow locArrow = (Arrow) locGeom.getMesh();
            locArrow.setArrowExtent(location);
            Arrow axleArrow = (Arrow) axleGeom.getMesh();
            axleArrow.setArrowExtent(axle.normalizeLocal().multLocal(0.3f));
            Arrow wheelArrow = (Arrow) wheelGeom.getMesh();
            wheelArrow.setArrowExtent(direction.normalizeLocal().multLocal(radius));
            Arrow dirArrow = (Arrow) dirGeom.getMesh();
            dirArrow.setArrowExtent(direction.normalizeLocal().multLocal(restLength));

            dirGeom.setLocalTranslation(location);
            axleGeom.setLocalTranslation(location.addLocal(direction));
            wheelGeom.setLocalTranslation(location);
            i++;
        }
        debugShape.updateLogicalState(0);
        debugShape.updateGeometricState();
        rm.renderScene(debugShape, vp);
    }
}