Package com.jme3.scene

Examples of com.jme3.scene.Node


    }

    @Override
    protected void controlUpdate(float tpf) {
        if(myShape != body.getCollisionShape()){
            Node node = (Node) this.spatial;
            node.detachChild(geom);
            geom = DebugShapeFactory.getDebugShape(body.getCollisionShape());
            node.attachChild(geom);
        }
        if(body.isActive()){
            geom.setMaterial(debugAppState.DEBUG_MAGENTA);
        }else{
            geom.setMaterial(debugAppState.DEBUG_BLUE);
View Full Code Here


            ConstraintHelper constraintHelper = blenderContext.getHelper(ConstraintHelper.class);
            constraintHelper.bakeConstraints(blenderContext);

            // attach the nodes to the root node at the very end so that the root objects have no parents during constraint applying
            LOGGER.fine("Creating the root node of the model and applying loaded nodes of the scene to it.");
            Node modelRoot = new Node(blenderKey.getName());
            for (Node node : rootObjects) {
                if (node instanceof LightNode) {
                    modelRoot.addLight(((LightNode) node).getLight());
                }
                modelRoot.attachChild(node);
            }

            return modelRoot;
        } catch (BlenderFileException e) {
            throw new IOException(e.getLocalizedMessage(), e);
View Full Code Here

        }
    }

    private void attachDebugNode(Node root) {
        if (debugNode == null) {
            debugNode = new Node();
            Material m = assetManager.loadMaterial("Common/Materials/RedColor.j3m");
            for (Iterator<Vector3f> it = spline.getControlPoints().iterator(); it.hasNext();) {
                Vector3f cp = it.next();
                Geometry geo = new Geometry("box", new Box(cp, 0.3f, 0.3f, 0.3f));
                geo.setMaterial(m);
View Full Code Here

            parent = this.toObject(parentStructure, blenderContext);
        }

        Transform t = this.getTransformation(objectStructure, blenderContext);
        LOGGER.log(Level.FINE, "Importing object of type: {0}", objectType);
        Node result = null;
        try {
            switch (objectType) {
                case EMPTY:
                case ARMATURE:
                    // need to use an empty node to properly create
                    // parent-children relationships between nodes
                    result = new Node(name);
                    break;
                case MESH:
                    result = new Node(name);
                    MeshHelper meshHelper = blenderContext.getHelper(MeshHelper.class);
                    Pointer pMesh = (Pointer) objectStructure.getFieldValue("data");
                    List<Structure> meshesArray = pMesh.fetchData();
                    List<Geometry> geometries = meshHelper.toMesh(meshesArray.get(0), blenderContext);
                    if (geometries != null) {
                        for (Geometry geometry : geometries) {
                            result.attachChild(geometry);
                        }
                    }
                    break;
                case SURF:
                case CURVE:
                    result = new Node(name);
                    Pointer pCurve = (Pointer) objectStructure.getFieldValue("data");
                    if (pCurve.isNotNull()) {
                        CurvesHelper curvesHelper = blenderContext.getHelper(CurvesHelper.class);
                        Structure curveData = pCurve.fetchData().get(0);
                        List<Geometry> curves = curvesHelper.toCurve(curveData, blenderContext);
                        for (Geometry curve : curves) {
                            result.attachChild(curve);
                        }
                    }
                    break;
                case LAMP:
                    Pointer pLamp = (Pointer) objectStructure.getFieldValue("data");
                    if (pLamp.isNotNull()) {
                        LightHelper lightHelper = blenderContext.getHelper(LightHelper.class);
                        List<Structure> lampsArray = pLamp.fetchData();
                        result = lightHelper.toLight(lampsArray.get(0), blenderContext);
                        if(result == null) {
                            //probably some light type is not supported, just create a node so that we can maintain child-parent relationship for nodes
                            result = new Node(name);
                        }
                    }
                    break;
                case CAMERA:
                    Pointer pCamera = (Pointer) objectStructure.getFieldValue("data");
                    if (pCamera.isNotNull()) {
                        CameraHelper cameraHelper = blenderContext.getHelper(CameraHelper.class);
                        List<Structure> camerasArray = pCamera.fetchData();
                        result = cameraHelper.toCamera(camerasArray.get(0), blenderContext);
                    }
                    break;
                default:
                    LOGGER.log(Level.WARNING, "Unsupported object type: {0}", type);
            }
        } finally {
            blenderContext.popParent();
        }

        if (result != null) {
            LOGGER.fine("Storing loaded feature in blender context and applying markers (those will be removed before the final result is released).");
            blenderContext.addLoadedFeatures(objectStructure.getOldMemoryAddress(), name, objectStructure, result);
            blenderContext.addMarker(OMA_MARKER, result, objectStructure.getOldMemoryAddress());
            if (objectType == ObjectType.ARMATURE) {
                blenderContext.addMarker(ARMATURE_NODE_MARKER, result, Boolean.TRUE);
            }
           
            result.setLocalTransform(t);
            result.setCullHint(visible ? CullHint.Always : CullHint.Inherit);
            if (parent instanceof Node) {
                ((Node) parent).attachChild(result);
            }

            if (result.getChildren() != null) {
                for (Spatial child : result.getChildren()) {
                    if (child instanceof Geometry) {
                        this.flipMeshIfRequired((Geometry) child, child.getWorldScale());
                    }
                }
            }

            LOGGER.fine("Reading and applying object's modifiers.");
            ModifierHelper modifierHelper = blenderContext.getHelper(ModifierHelper.class);
            Collection<Modifier> modifiers = modifierHelper.readModifiers(objectStructure, blenderContext);
            for (Modifier modifier : modifiers) {
                modifier.apply(result, blenderContext);
            }

            // I prefer do compute bounding box here than read it from the file
            result.updateModelBound();

            LOGGER.fine("Applying animations to the object if such are defined.");
            AnimationHelper animationHelper = blenderContext.getHelper(AnimationHelper.class);
            animationHelper.applyAnimations(result, blenderContext.getBlenderKey().getNodeAnimationNames(name));
View Full Code Here

     * @param pathSplineType
     */
    public void setPathSplineType(SplineType pathSplineType) {
        spline.setType(pathSplineType);
        if (debugNode != null) {
            Node parent = debugNode.getParent();
            debugNode.removeFromParent();
            debugNode.detachAllChildren();
            debugNode = null;
            attachDebugNode(parent);
        }
View Full Code Here

     * @param curveTension
     */
    public void setCurveTension(float curveTension) {
        spline.setCurveTension(curveTension);
        if (debugNode != null) {
            Node parent = debugNode.getParent();
            debugNode.removeFromParent();
            debugNode.detachAllChildren();
            debugNode = null;
            attachDebugNode(parent);
        }
View Full Code Here

     */
    public void setCycle(boolean cycle) {

        spline.setCycle(cycle);
        if (debugNode != null) {
            Node parent = debugNode.getParent();
            debugNode.removeFromParent();
            debugNode.detachAllChildren();
            debugNode = null;
            attachDebugNode(parent);
        }
View Full Code Here

     *            structure of a scene
     * @return scene's node
     */
    private Node toScene(Structure structure) {
        ObjectHelper objectHelper = blenderContext.getHelper(ObjectHelper.class);
        Node result = new Node(structure.getName());
        try {
            List<Structure> base = ((Structure) structure.getFieldValue("base")).evaluateListBase();
            for (Structure b : base) {
                Pointer pObject = (Pointer) b.getFieldValue("object");
                if (pObject.isNotNull()) {
                    Structure objectStructure = pObject.fetchData().get(0);

                    Object object = objectHelper.toObject(objectStructure, blenderContext);
                    if (object instanceof LightNode) {
                        result.addLight(((LightNode) object).getLight());
                        result.attachChild((LightNode) object);
                    } else if (object instanceof Node) {
                        if (LOGGER.isLoggable(Level.FINE)) {
                            LOGGER.log(Level.FINE, "{0}: {1}--> {2}", new Object[] { ((Node) object).getName(), ((Node) object).getLocalTranslation().toString(), ((Node) object).getParent() == null ? "null" : ((Node) object).getParent().getName() });
                        }
                        if (((Node) object).getParent() == null) {
                            result.attachChild((Spatial) object);
                        }
                    }
                }
            }
        } catch (BlenderFileException e) {
View Full Code Here

        so.setName(name);
        so.setRotation(new Quaternion());
        so.setLinearVelocity(new Vector3f());
        so.setAngularVelocity(new Quaternion());

        Node fighter = new Node(name);
        ControlledSpaceObject cso = new ControlledSpaceObject(so, fighter);
        cso.setDebugDisplay(name);
        cso.setGameThreadCallback(new SpatialUpdater(cso));

        Geometry gSphere = new Geometry("Sphere", new Sphere(10,10,0.25f));
        Geometry gDirection =  new Geometry("Direction-Line", new Line(new Vector3f(0,0,0), new Vector3f(0,0,2)));
       
        gSphere.setMaterial(main);
        gDirection.setMaterial(scnd);

        fighter.attachChild(gSphere);
        fighter.attachChild(gDirection);
       
       
        SimpleBoundingVolumeFactory.createBestBoundingVolume(fighter);
        fighter.setLocalTranslation(pos);
       
        objCtrl.addSpaceObject(cso, true);
        }
      }, (float) (Math.random() * 5));
    }
 
View Full Code Here

    // sign.setMaterial(mat_asteroid);
    // sign.scale(0.02f, 0.02f, 0.02f);
    //
    // rootNode.attachChild(sign);
    //
    Node ship = new Node("Carrier");
    Spatial cube = assetManager
        .loadModel("spaceobject/station/platform/Platform.mesh.xml");

    Material mat_asteroid = new Material(assetManager,
        "Common/MatDefs/Light/Lighting.j3md");
    mat_asteroid.setTexture("DiffuseMap", assetManager
        .loadTexture("spaceobject/station/platform/hull.jpg"));
    cube.setMaterial(mat_asteroid);
    ship.attachChild(cube);

    Spatial wall = assetManager
        .loadModel("spaceobject/station/platform/Towers.mesh.xml");
    Material mat_wall = new Material(assetManager,
        "Common/MatDefs/Light/Lighting.j3md");
    mat_wall.setTexture("DiffuseMap", assetManager
        .loadTexture("spaceobject/station/platform/city2.jpg"));
    mat_wall.setTexture("GlowMap", assetManager
        .loadTexture("spaceobject/station/platform/city2_glow.jpg"));
    wall.setMaterial(mat_wall);
    ship.attachChild(wall);

    // Spatial flight =
    // assetManager.loadModel("spaceobject/station/cube/Flight.mesh.xml");
    // flight.setMaterial(mat_wall);
    // ship.attachChild(flight);
View Full Code Here

TOP

Related Classes of com.jme3.scene.Node

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.