Package com.jme3.scene.plugins.blender.meshes.builders

Examples of com.jme3.scene.plugins.blender.meshes.builders.MeshBuilder


    public Node shirt;
    public Node skin;

// ============= Constructors ============== //
    public Model(){
  root = new Node("Model");
    }
View Full Code Here


    }
// ============= Public Methods ============== //
    public Model loadModel(Avatar avatar){
  // TEST, just load
  Model model = new Model();
  Node node = null;
  // load the body
  Node body = baseTable.loadBody(avatar.skin.color,avatar.shirt.color);
  Node head = baseTable.loadHead(avatar.head.type,avatar.skin.color);
        baseTable.loadEyes(avatar.eye,head);
  if(head != null && body != null){
      model.load(head,body);
  }
View Full Code Here

    /**
     * Handles loading a single node from file.
     * @param obj the path to the object.
     **/
    public Node loadNode(String obj){
  Node node = new Node();
  try{
            Spatial spatial = assetManager.loadModel(obj);
            //Material mat = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
            //spatial.setMaterial(mat);
            node.attachChild(spatial);

      node.setModelBound(new BoundingSphere());
      node.updateModelBound();
  } catch (Exception e) {
            e.printStackTrace();
      //logger.logp(Level.SEVERE, this.getClass().toString(),"loadNode()", "Exception", e);
      node = null;
  }
View Full Code Here

   
    setPointLight(true);
   
    guiNode.detachChildNamed("Statistics View");

    camNode = new Node("Cam Node");

    flyCam.setEnabled(false);
    ChaseCamera chaseCam = new ChaseCamera(cam, camNode, inputManager);
    chaseCam.setSmoothMotion(true);
    chaseCam.setMaxDistance(100000);
View Full Code Here

        if (path.startsWith(File.separator)) {
          relPath = path.substring(1);
        } else {
          relPath = path;
        }
        Node model = (Node) assetManager.loadModel(relPath);
        if (model == null) {
          assetLogger.modelFinished();
          logger.log(Level.SEVERE, "Couldn't load model "+path);
          return null;
        }
        Geometry modelGeom = (Geometry) model.getChild(0);

        try {
          // trows an Exception if lod is not supported
          modelGeom.setLodLevel(0);
View Full Code Here

     * @param obj the path to the object.
     **/
    public Node loadNode(String obj){
  Node node = new Node();
  try{
            Spatial spatial = assetManager.loadModel(obj);
            //Material mat = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
            //spatial.setMaterial(mat);
            node.attachChild(spatial);

      node.setModelBound(new BoundingSphere());
View Full Code Here

        app.start();
    }

    @Override
    public void simpleInitApp() {
        Spatial teapot = assetManager.loadModel("Models/Teapot/Teapot.obj");
      
        teapot.setLocalScale(2f);
        Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
        mat.setFloat("m_Shininess", 32f);
        mat.setBoolean("m_UseMaterialColors", true);

        mat.setColor("m_Ambient",  ColorRGBA.Black);
        mat.setColor("m_Diffuse",  ColorRGBA.Green);
        mat.setColor("m_Specular", ColorRGBA.Red);
       
        teapot.setMaterial(mat);
        rootNode.attachChild(teapot);

        lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
        lightMdl.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
        lightMdl.getMesh().setStatic();
View Full Code Here

        try {
          // trows an Exception if lod is not supported
          modelGeom.setLodLevel(0);

          LodControl control = new LodControl();
          modelGeom.addControl(control);
        } catch (Exception e) {}
        assetLogger.modelFinished();
        camNode.detachAllChildren();
        camNode.attachChild(model);
View Full Code Here

        if ((blenderContext.getBlenderKey().getFeaturesToLoad() & FeaturesToLoad.MATERIALS) != 0) {
            materials = materialHelper.getMaterials(structure, blenderContext);
        }

        LOGGER.fine("Reading vertices.");
        MeshBuilder meshBuilder = new MeshBuilder(structure, materials, blenderContext);
        if (meshBuilder.isEmpty()) {
            LOGGER.fine("The geometry is empty.");
            geometries = new ArrayList<Geometry>(0);
            blenderContext.addLoadedFeatures(structure.getOldMemoryAddress(), structure.getName(), structure, geometries);
            blenderContext.setMeshContext(structure.getOldMemoryAddress(), meshContext);
            return geometries;
        }

        meshContext.setVertexReferenceMap(meshBuilder.getVertexReferenceMap());

        LOGGER.fine("Reading vertices groups (from the Object structure).");
        Structure parent = blenderContext.peekParent();
        Structure defbase = (Structure) parent.getFieldValue("defbase");
        List<Structure> defs = defbase.evaluateListBase();
        String[] verticesGroups = new String[defs.size()];
        int defIndex = 0;
        for (Structure def : defs) {
            verticesGroups[defIndex++] = def.getFieldValue("name").toString();
        }

        LOGGER.fine("Reading custom properties.");
        Properties properties = this.loadProperties(structure, blenderContext);

        LOGGER.fine("Generating meshes.");
        Map<Integer, List<Mesh>> meshes = meshBuilder.buildMeshes();
        geometries = new ArrayList<Geometry>(meshes.size());
        for (Entry<Integer, List<Mesh>> meshEntry : meshes.entrySet()) {
            int materialIndex = meshEntry.getKey();
            for (Mesh mesh : meshEntry.getValue()) {
                LOGGER.fine("Preparing the result part.");
                Geometry geometry = new Geometry(name + (geometries.size() + 1), mesh);
                if (properties != null && properties.getValue() != null) {
                    this.applyProperties(geometry, properties);
                }
                geometries.add(geometry);
                meshContext.putGeometry(materialIndex, geometry);
            }
        }

        // store the data in blender context before applying the material
        blenderContext.addLoadedFeatures(structure.getOldMemoryAddress(), structure.getName(), structure, geometries);
        blenderContext.setMeshContext(structure.getOldMemoryAddress(), meshContext);

        // apply materials only when all geometries are in place
        if (materials != null) {
            for (Geometry geometry : geometries) {
                int materialNumber = meshContext.getMaterialIndex(geometry);
                if (materialNumber < 0) {
                    geometry.setMaterial(this.getBlackUnshadedMaterial(blenderContext));
                } else if (materials[materialNumber] != null) {
                    LinkedHashMap<String, List<Vector2f>> uvCoordinates = meshBuilder.getUVCoordinates(materialNumber);
                    MaterialContext materialContext = materials[materialNumber];
                    materialContext.applyMaterial(geometry, structure.getOldMemoryAddress(), uvCoordinates, blenderContext);
                } else {
                    geometry.setMaterial(blenderContext.getDefaultMaterial());
                    LOGGER.warning("The importer came accross mesh that points to a null material. Default material is used to prevent loader from crashing, " + "but the model might look not the way it should. Sometimes blender does not assign materials properly. " + "Enter the edit mode and assign materials once more to your faces.");
                }
            }
        } else {
            // add UV coordinates if they are defined even if the material is not applied to the model
            List<VertexBuffer> uvCoordsBuffer = null;
            if (meshBuilder.hasUVCoordinates()) {
                Map<String, List<Vector2f>> uvs = meshBuilder.getUVCoordinates(0);
                if (uvs != null && uvs.size() > 0) {
                    uvCoordsBuffer = new ArrayList<VertexBuffer>(uvs.size());
                    int uvIndex = 0;
                    for (Entry<String, List<Vector2f>> entry : uvs.entrySet()) {
                        VertexBuffer buffer = new VertexBuffer(TextureHelper.TEXCOORD_TYPES[uvIndex++]);
View Full Code Here

        app.start();
    }

    @Override
    public void simpleInitApp() {
        Box b = new Box(Vector3f.ZERO, 1, 1, 1);
        Geometry geom = new Geometry("Box", b);
        geom.updateModelBound();

        Material mat = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");
        mat.setColor("m_Color", ColorRGBA.Blue);
View Full Code Here

TOP

Related Classes of com.jme3.scene.plugins.blender.meshes.builders.MeshBuilder

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.