• Récent
  • Mots-clés
  • Populaire
  • Utilisateurs
  • Groupes
  • S'inscrire
  • Se connecter
  • S'inscrire
  • Se connecter
  • Recherche
  • Récent
  • Mots-clés
  • Populaire
  • Utilisateurs
  • Groupes

Créateur de heightmap

Le salon libre
1
1
118
Charger plus de messages
  • Du plus ancien au plus récent
  • Du plus récent au plus ancien
  • Les plus votés
Répondre
  • Répondre à l'aide d'un nouveau sujet
Se connecter pour répondre
Ce sujet a été supprimé. Seuls les utilisateurs avec les droits d'administration peuvent le voir.
  • isador
    isador Moddeurs confirmés Modérateurs dernière édition par 7 août 2015, 09:28

    Bonjour a vous, j’ai besoin d’aide aujourd’hui pour la création d’une appli qui permettrai de créer une heightmap a partir d’un modèle 3D, cependant le code que j’essaie de faire ne marche pas, un modèle trop grand fait bug le calcul, et je pense aussi que le rendu de la couleur bug

    voici mon code actuel:

    public class Loader
    {
       static float[] minMaxVertex = new float[6];
       public static void main(String[] args)
       {
           JFileChooser dialogue = new JFileChooser();
           dialogue.setMultiSelectionEnabled(false);
           dialogue.showOpenDialog(null);
           loadObjModel(dialogue.getSelectedFile());
       }
       public static void loadObjModel(File file)
       {
           FileReader fr = null;
           try
           {
               fr = new FileReader(file);
           }
           catch(Exception e)
           {
               System.err.println("Could not load file");
               e.printStackTrace();
           }
           BufferedReader reader = new BufferedReader(fr);
           String line;
           List <vector3f>vertices = new ArrayList<vector3f>();
           try
           {
               while(true)
               {
                   line = reader.readLine();
                   String[] currentLine = line.split(" ");
                   if(line.startsWith("v "))
                   {
                       Vector3f vertex = new Vector3f(Float.parseFloat(currentLine[1]), Float.parseFloat(currentLine[2]), Float.parseFloat(currentLine[3]));
                       vertices.add(vertex);
                   }
                   else if(line.startsWith("vt ") || line.startsWith("vn ") || line.startsWith("f "))
                       break;
               }
           }
           catch(Exception e)
           {
               e.printStackTrace();
           }
           minMaxVertex = getMinMaxVertex(vertices);
           createImage(vertices, file);
       }
       private static void createImage(List <vector3f>vertices, File file)
       {
           BufferedImage image = new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB);
           Vector2f coords = new Vector2f();
           for(Vector3f v : vertices)
           {
               // System.out.println( getColor(v.y) + " " + getColor(v.y).getRGB());
               coords = getCoord(new Vector2f(v.x, v.z));
               // System.out.println(coords);
               image.setRGB(Math.abs((int)coords.x), Math.abs((int)coords.y), getColor(v.y).getRGB());
           }
           try
           {
               ImageIO.write(image, "png", new File(file.getAbsolutePath().substring(0, file.getAbsolutePath().lastIndexOf(".")) + ".png"));
           }
           catch(IOException e)
           {
               System.out.println(coords);
               e.printStackTrace();
           }
       }
       private static Color getColor(float height)
       {
           float value = height / (minMaxVertex[3] - minMaxVertex[2]);
           return new Color(value, value, value);
       }
       private static Vector2f getCoord(Vector2f vertex)
       {
           float coef = 1f;
           float ratioX = (minMaxVertex[1] - minMaxVertex[0]) / 255f;
           float ratioY = (minMaxVertex[5] - minMaxVertex[4]) / 255f;
           // System.out.println(minMaxVertex[5]);
            System.out.println(vertex.y + " " + (minMaxVertex[5] - minMaxVertex[4]) + " " + (minMaxVertex[5] - minMaxVertex[4]) / 255f + " " + vertex.y / ratioY + " " + ((vertex.y / ratioY) + 128));
           return new Vector2f((vertex.x / (coef * ratioX)) + 128, (vertex.y / (coef * ratioY)) + 128);
       }
       private static float[] getMinMaxVertex(List <vector3f>vertexList)
       {
           if(vertexList == null)
               return null;
           List <float>x = new ArrayList<float>();
           List <float>y = new ArrayList<float>();
           List <float>z = new ArrayList<float>();
           for(Vector3f vec : vertexList)
           {
               x.add(vec.x);
               y.add(vec.y);
               z.add(vec.z);
           }
           float minX = 0, maxX = 0;
           for(int i = 0; i < x.size(); i++)
           {
               if(i == 0)
                   minX = maxX = x.get(i);
               else if(x.get(i) < minX)
                   minX = x.get(i);
               else if(x.get(i) > maxX)
                   maxX = x.get(i);
           }
           float minY = 0, maxY = 0;
           for(int i = 0; i < y.size(); i++)
           {
               if(i == 0)
                   minY = maxY = y.get(i);
               else if(y.get(i) < minY)
                   minY = y.get(i);
               else if(y.get(i) > maxY)
                   maxY = y.get(i);
           }
           float minZ = 0, maxZ = 0;
           for(int i = 0; i < z.size(); i++)
           {
               if(i == 0)
                   minZ = maxZ = z.get(i);
               else if(z.get(i) < minZ)
                   minZ = z.get(i);
               else if(z.get(i) > maxZ)
                   maxZ = z.get(i);
           }
           return new float[] {minX, maxX, minY, maxY, minZ, maxZ};
       }
    }

    donc si qqn sais comment m’aider qu’il me fasse signe</float></float></float></float></float></float></vector3f></vector3f></vector3f></vector3f>

    1 réponse Dernière réponse Répondre Citer 0
    • 1 / 1
    1 sur 1
    • Premier message
      1/1
      Dernier message
    Design by Woryk
    Contact / Mentions Légales

    MINECRAFT FORGE FRANCE © 2018

    Powered by NodeBB