Package com.jme3.scene

Examples of com.jme3.scene.Spatial


    try {
      Geometry g;
      // need to load vial loadModel, JME does not see obj, etc as
      // Assets..
      t.reset();
      Spatial n = (Spatial) assetMan.loadModel(from.getAbsolutePath());
      time = t.getTimeInSeconds();
      System.out.println("File " + from.getAbsolutePath() + " loaded in "
          + time + " seconds");
      if (n instanceof Geometry) {
        g = (Geometry) n;
        n = new Node(g.getName());
        ((Node)n).attachChild(g);
      } else if (n instanceof Node) {
        if (((Node) n).getChildren().size() > 1)
          throw new Throwable(
              "Mesh with more children detected than one on "
                  + from.getName());
        g = (Geometry) ((Node) n).getChild(0);
      } else
        throw new Throwable("Spatial loaded was unexpected type "
            + n.getClass());
      // jme fucked up the model names, and ignores any object name
      // entries so we fix a bit
      String fName = from.getName().substring(0,
          from.getName().length() - fileEnding.length());// without .nav
      g.setName(fName.toLowerCase());
View Full Code Here


//    if (charSelection != null) {
      if (baseNode == null) { 
//        Asset a = new Asset("troll2/troll.xml.mesh.xml","troll");
//        com.l2client.asset.Singleton.get().getAssetManager().loadAsset(a,true);
        Spatial s = Singleton.get().getAssetManager().getJmeAssetMan().loadModel("models/troll2/troll.xml.mesh.xml");
//        baseNode = (Node) a.getBaseAsset();
        if(s instanceof Node ){
        baseNode = (Node) s;
        baseNode.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X));
        baseNode.setName(name);
View Full Code Here

     * initialize gui
     */
    private void setupScene() {

        /** Load a Ninja model (OgreXML + material + texture from test_data) */
        Spatial ninja = assetManager.loadModel("Models/Ninja/Ninja.mesh.xml");
        ninja.scale(0.05f, 0.05f, 0.05f);
        ninja.rotate(0.0f, -3.0f, 0.0f);
        ninja.setLocalTranslation(0.0f, -5.0f, -2.0f);
        rootNode.attachChild(ninja);
        /** You must add a light to make the model visible */
        DirectionalLight sun = new DirectionalLight();
        sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f).normalizeLocal());
        rootNode.addLight(sun);
View Full Code Here

            if (key.equals("what"))
                continue;
            // parse coords
            int x = Integer.parseInt(key.split(",")[0]);
            int y = Integer.parseInt(key.split(",")[1]);
            Spatial tile = createTile(environment, key, x, y);
            model.worldNode.detachChildNamed(key);
            model.worldNode.attachChild(tile);

            // adding objects
            if (environment.getJSONObject(key).has("objects")) {
View Full Code Here

    }

    @Deprecated
    private Spatial createTile(JSONObject environment, String key, int x, int y) throws JSONException {
        String terrain = environment.getJSONObject(key).get("terrain").toString();
        Spatial tile = model.tileTypes.get(terrain).clone();
        tile.setMaterial(model.materials.get(terrain));
        tile.setName(key);
        tile.move(x, 0, y);
        return tile;
    }
View Full Code Here

            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);
                }
            }
        }
View Full Code Here

     */
    public static Spatial getDebugShape(CollisionShape collisionShape) {
        if (collisionShape == null) {
            return null;
        }
        Spatial debugShape;
        if (collisionShape instanceof CompoundCollisionShape) {
            CompoundCollisionShape shape = (CompoundCollisionShape) collisionShape;
            List<ChildCollisionShape> children = shape.getChildren();
            Node node = new Node("DebugShapeNode");
            for (Iterator<ChildCollisionShape> it = children.iterator(); it.hasNext();) {
                ChildCollisionShape childCollisionShape = it.next();
                CollisionShape ccollisionShape = childCollisionShape.shape;
                Geometry geometry = createDebugShape(ccollisionShape);

                // apply translation
                geometry.setLocalTranslation(childCollisionShape.location);

                // apply rotation
                TempVars vars = TempVars.get();               
                Matrix3f tempRot = vars.tempMat3;

                tempRot.set(geometry.getLocalRotation());
                childCollisionShape.rotation.mult(tempRot, tempRot);
                geometry.setLocalRotation(tempRot);

                vars.release();

                node.attachChild(geometry);
            }
            debugShape = node;
        } else {
            debugShape = createDebugShape(collisionShape);
        }
        if (debugShape == null) {
            return null;
        }
        debugShape.updateGeometricState();
        return debugShape;
    }
View Full Code Here

     *
     * @param time
     *            the current time of the animation
     */
    public void setTime(float time, float weight, AnimControl control, AnimChannel channel, TempVars vars) {
        Spatial spatial = control.getSpatial();
       
        Vector3f tempV = vars.vect1;
        Vector3f tempS = vars.vect2;
        Quaternion tempQ = vars.quat1;
        Vector3f tempV2 = vars.vect3;
        Vector3f tempS2 = vars.vect4;
        Quaternion tempQ2 = vars.quat2;
       
        int lastFrame = times.length - 1;
        if (time < 0 || lastFrame == 0) {
            if (rotations != null)
                rotations.get(0, tempQ);
            if (translations != null)
                translations.get(0, tempV);
            if (scales != null) {
                scales.get(0, tempS);
            }
        } else if (time >= times[lastFrame]) {
            if (rotations != null)
                rotations.get(lastFrame, tempQ);
            if (translations != null)
                translations.get(lastFrame, tempV);
            if (scales != null) {
                scales.get(lastFrame, tempS);
            }
        } else {
            int startFrame = 0;
            int endFrame = 1;
            // use lastFrame so we never overflow the array
            for (int i = 0; i < lastFrame && times[i] < time; ++i) {
                startFrame = i;
                endFrame = i + 1;
            }

            float blend = (time - times[startFrame]) / (times[endFrame] - times[startFrame]);

            if (rotations != null)
                rotations.get(startFrame, tempQ);
            if (translations != null)
                translations.get(startFrame, tempV);
            if (scales != null) {
                scales.get(startFrame, tempS);
            }
            if (rotations != null)
                rotations.get(endFrame, tempQ2);
            if (translations != null)
                translations.get(endFrame, tempV2);
            if (scales != null) {
                scales.get(endFrame, tempS2);
            }
            tempQ.nlerp(tempQ2, blend);
            tempV.interpolateLocal(tempV2, blend);
            tempS.interpolateLocal(tempS2, blend);
        }
       
        if (translations != null)
            spatial.setLocalTranslation(tempV);
        if (rotations != null)
            spatial.setLocalRotation(tempQ);
        if (scales != null) {
            spatial.setLocalScale(tempS);
        }
    }
View Full Code Here

    private void fixRefreshFlags(){
        // force transforms to update below this node
        spatial.updateGeometricState();
       
        // force world bound to update
        Spatial rootNode = spatial;
        while (rootNode.getParent() != null){
            rootNode = rootNode.getParent();
        }
        rootNode.getWorldBound();
    }
View Full Code Here

            if (!constraintUsed) {
                if (constraint instanceof BoneConstraint) {
                    BoneContext boneContext = blenderContext.getBoneContext(constraint.ownerOMA);
                    simulationRootNodes.add(new SimulationNode(boneContext.getArmatureObjectOMA(), blenderContext));
                } else if (constraint instanceof SpatialConstraint) {
                    Spatial spatial = (Spatial) blenderContext.getLoadedFeature(constraint.ownerOMA, LoadedFeatureDataType.LOADED_FEATURE);
                    while (spatial.getParent() != null) {
                        spatial = spatial.getParent();
                    }
                    simulationRootNodes.add(new SimulationNode((Long) blenderContext.getMarkerValue(ObjectHelper.OMA_MARKER, spatial), blenderContext));
                } else {
                    throw new IllegalStateException("Unsupported constraint type: " + constraint);
                }
View Full Code Here

TOP

Related Classes of com.jme3.scene.Spatial

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.