Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 13th, 2013  |  syntax: None  |  size: 22.93 KB  |  hits: 23  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
  2. at java.nio.HeapIntBuffer.<init>(HeapIntBuffer.java:39)
  3. at java.nio.IntBuffer.allocate(IntBuffer.java:312)
  4. at com.sonogenics.model.ModelRenderer.<init>
  5.        
  6. -ea -server -Djava.library.path="../deploy64" -Dsun.java2d.noddraw=true -Dsun.java2d.opengl=True -Xmx1024m -Xms1024m -Xloggc:ClientGC.log -XX:+UseConcMarkSweepGC -XX:MaxNewSize=8M -XX:MaxDirectMemorySize=2056M -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=9000 -Dcom.sun.management.jmxremote.ssl=false
  7.        
  8. public abstract class AbstractModelHandler
  9. {
  10. protected static final String MODEL_PATH = "assets/models/";
  11.  
  12. private final int activePointer = 1;
  13.  
  14. private boolean initialised;
  15.  
  16. protected boolean loaded;
  17. protected AbstractModel model;
  18.  
  19. private final String modelName;
  20. protected final List<ModelRenderer> renderers;
  21. private final HashMap<String, Integer> textureMap = new HashMap<String, Integer>();
  22.  
  23. public AbstractModelHandler(final String modelName)
  24. {
  25.     this.renderers = new ArrayList<ModelRenderer>();
  26.     this.modelName = modelName;
  27.     this.loaded = false;
  28.     this.initialised = false;
  29. }
  30.  
  31. public abstract void addModelInstance(final double tx, final double ty, final double tz, final double rx,
  32.         final double ry, final double rz, final double sx, final double sy, final double sz, final Color color);
  33.  
  34. public void augmentModel(final int index, final double tx, final double ty, final double tz, final double rx,
  35.         final double ry, final double rz, final double sx, final double sy, final double sz)
  36. {
  37.     if (getInstanceForIndex(index) != null)
  38.     {
  39.         if (sx != 0 || sy != 0 || sz != 0)
  40.         {
  41.             augmentModelScale(index, sx, sy, sz);
  42.         }
  43.         if (tx != 0 || ty != 0 || tz != 0)
  44.         {
  45.             augmentModelTranslation(index, tx, ty, tz);
  46.         }
  47.         if (rx != 0 || ry != 0 || rz != 0)
  48.         {
  49.             augmentModelRotation(index, rx, ry, rz);
  50.         }
  51.     }
  52. }
  53.  
  54. public void augmentModelRotation(final int index, final double rx, final double ry, final double rz)
  55. {
  56.     final Matrix4d augmentation = new Matrix4d();
  57.     augmentation.setIdentity();
  58.     createRotationMatrix(augmentation, rx, ry, rz);
  59.     getInstanceForIndex(index).getTransform().getRotation().mul(augmentation);
  60. }
  61.  
  62. public void augmentModelScale(final int index, final double sx, final double sy, final double sz)
  63. {
  64.     final Matrix4d augmentation = new Matrix4d();
  65.     augmentation.setIdentity();
  66.     createScaleMatrix(augmentation, sx, sy, sz);
  67.     getInstanceForIndex(index).getTransform().getScale().mul(augmentation);
  68. }
  69.  
  70. public void augmentModelTranslation(final int index, final double tx, final double ty, final double tz)
  71. {
  72.     final Matrix4d augmentation = new Matrix4d();
  73.     augmentation.setIdentity();
  74.     createTranslationMatrix(augmentation, tx, ty, tz);
  75.     getInstanceForIndex(index).getTransform().getTranslation().mul(augmentation);
  76. }
  77.  
  78. public void clear()
  79. {
  80.     for (final ModelRenderer renderer : renderers)
  81.     {
  82.         renderer.getModelInstances().clear();
  83.     }
  84. }
  85.  
  86. protected void createRotationMatrix(final Matrix4d transform, final double rotX, final double rotY,
  87.         final double rotZ)
  88. {
  89.     transform.setIdentity();
  90.     final Matrix4d temp = new Matrix4d();
  91.     temp.rotX(rotX);
  92.     transform.mul(temp);
  93.     temp.rotY(rotY);
  94.     transform.mul(temp);
  95.     temp.rotZ(rotZ);
  96.     transform.mul(temp);
  97. }
  98.  
  99. protected void createScaleMatrix(final Matrix4d transform, final double scaleX, final double scaleY,
  100.         final double scaleZ)
  101. {
  102.     transform.setIdentity();
  103.     transform.m00 = scaleX;
  104.     transform.m11 = scaleY;
  105.     transform.m22 = scaleZ;
  106. }
  107.  
  108. protected void createTranslationMatrix(final Matrix4d transform, final double tx, final double ty, final double tz)
  109. {
  110.     transform.setIdentity();
  111.     transform.m03 = tx;
  112.     transform.m13 = ty;
  113.     transform.m23 = tz;
  114. }
  115.  
  116. public AbstractModelInstance getInstance(final int index)
  117. {
  118.     return getInstanceForIndex(index);
  119. }
  120.  
  121. public AbstractModelInstance getInstanceForIndex(final int index)
  122. {
  123.     if (!renderers.isEmpty())
  124.     {
  125.         final int numRenderers = renderers.size();
  126.         if (numRenderers > 1)
  127.         {
  128.             return renderers.get(index).getModelInstances().get(0);
  129.         }
  130.         else
  131.         {
  132.             return renderers.get(0).getModelInstances().get(index);
  133.         }
  134.     }
  135.     else
  136.     {
  137.         return null;
  138.     }
  139. }
  140.  
  141. public AbstractModel getModel()
  142. {
  143.     return this.model;
  144. }
  145.  
  146. public float getModelWidth()
  147. {
  148.     return this.model.getWidth();
  149. }
  150.  
  151. public abstract int getNumInstances();
  152.  
  153. public List<ModelRenderer> getRenderers()
  154. {
  155.     return this.renderers;
  156. }
  157.  
  158. public void init(final GL gl)
  159. {
  160.     for (final ModelRenderer renderer : renderers)
  161.     {
  162.         renderer.init(gl);
  163.     }
  164.     initialised = true;
  165. }
  166.  
  167. public void initTextures(final GLContext context)
  168. {
  169.     if (model.usesTextures())
  170.     {
  171.         for (int i = 0; i < model.getMaterials().size(); ++i)
  172.         {
  173.             final String textureName = model.getMaterials().get(i).textureName;
  174.             if (textureName == null)
  175.                 return;
  176.             final FileTexture textureGenerator = new FileTexture(this.getClass().getResourceAsStream(textureName),
  177.                     true, false, context);
  178.             final int textureId = textureGenerator.getTextureId();
  179.             textureMap.put(model.getMaterials().get(i).matName, textureId);
  180.             System.out.println("Generating texture from: '" + textureName + "' ["
  181.                     + model.getMaterials().get(i).matName + "(" + textureId + ")]");
  182.             context.getGL().glActiveTexture(GL.GL_TEXTURE0 + i);
  183.             context.getGL().glBindTexture(GL.GL_TEXTURE_2D, textureId);
  184.             context.getGL().glClientActiveTexture(GL.GL_TEXTURE0 + activePointer);
  185.         }
  186.     }
  187. }
  188.  
  189. public boolean isEmpty()
  190. {
  191.     boolean isEmpty = true;
  192.     for (final ModelRenderer renderer : renderers)
  193.     {
  194.         isEmpty = renderer.isEmpty();
  195.     }
  196.     return isEmpty;
  197. }
  198.  
  199. public boolean isEnabled(final int index)
  200. {
  201.     if (getNumInstances() < index || getNumInstances() == 0)
  202.         return false;
  203.     else
  204.         return getInstanceForIndex(index).isEnabled();
  205. }
  206.  
  207. public boolean isInitialised()
  208. {
  209.     return this.initialised;
  210. }
  211.  
  212. public abstract boolean isMutable();
  213.  
  214. public void render(final GL gl, final SimpleProjection projection, final float disparityTop,
  215.         final float disparityBottom, final float disparityBlend, final Field field)
  216. {
  217.     for (int i = 0; i < renderers.size(); ++i)
  218.     {
  219.         final ModelRenderer renderer = renderers.get(i);
  220.         if (renderer != null && isInitialised() && projection != null && isEnabled(i))
  221.         {
  222.             renderer.display(gl, projection, disparityTop, disparityBottom, disparityBlend, field);
  223.         }
  224.     }
  225. }
  226.  
  227. public void setEnabled(final int index, final boolean enabled)
  228. {
  229.     if (isEnabled(index) != enabled)
  230.     {
  231.         getInstanceForIndex(index).setEnabled(enabled);
  232.     }
  233. }
  234.  
  235. public void setModelRotation(final int index, final double rx, final double ry, final double rz)
  236. {
  237.     createRotationMatrix(getInstanceForIndex(index).getTransform().getRotation(), rx, ry, rz);
  238. }
  239.  
  240. public void setModelScale(final int index, final double scale)
  241. {
  242.     createScaleMatrix(getInstanceForIndex(index).getTransform().getScale(), scale, scale, scale);
  243. }
  244.  
  245. public void setModelScale(final int index, final double sx, final double sy, final double sz)
  246. {
  247.     createScaleMatrix(getInstanceForIndex(index).getTransform().getScale(), sx, sy, sz);
  248. }
  249.  
  250. public void setModelTranslation(final int index, final double tx, final double ty, final double tz)
  251. {
  252.     createTranslationMatrix(getInstanceForIndex(index).getTransform().getTranslation(), tx, ty, tz);
  253. }
  254.  
  255. public void updateVertices(final int index)
  256. {
  257.     renderers.get(renderers.size() > 1 ? index : 0).updateVertices();
  258. }
  259. }
  260.        
  261. public class ModelRenderer implements ModelRendererInterface
  262. {
  263. private boolean requiresRedraw = true;
  264. private final int currentGlComparison = GL.GL_LESS;
  265.  
  266. private final FloatBuffer vertices;
  267. private final FloatBuffer normals;
  268. private final FloatBuffer colors;
  269. private final FloatBuffer texCoords;
  270. private final IntBuffer indices;
  271. private final int[] bufferObjects;
  272.  
  273. private boolean packed;
  274. private final ModelData modelData;
  275. private final ArrayList<AbstractModelInstance> modelInstances;
  276. private boolean initialisedRenderer;
  277. private PlayoutShaderProgram layerTextureShader;
  278.  
  279. public ModelRenderer(final ModelData modelData)
  280. {
  281.     this.modelData = modelData;
  282.     this.modelInstances = new ArrayList<AbstractModelInstance>();
  283.     this.initialisedRenderer = false;
  284.  
  285.     final int maxVertices = 1000000;
  286.     vertices = FloatBuffer.allocate(maxVertices * 3);
  287.     normals = FloatBuffer.allocate(maxVertices * 3);
  288.     texCoords = FloatBuffer.allocate(maxVertices * 2);
  289.     colors = FloatBuffer.allocate(maxVertices * 4);
  290.     indices = IntBuffer.allocate(maxVertices * 6);
  291.  
  292.     bufferObjects = new int[5];
  293.     populateBuffers();
  294. }
  295.  
  296. public List<AbstractModelInstance> getModelInstances()
  297. {
  298.     return this.modelInstances;
  299. }
  300.  
  301. private void addTriangle(final int vertex1, final int vertex2, final int vertex3)
  302. {
  303.     indices.put(vertex1);
  304.     indices.put(vertex2);
  305.     indices.put(vertex3);
  306. }
  307.  
  308. public void addModelInstance(final AbstractModelInstance modelInstance)
  309. {
  310.     this.modelInstances.add(modelInstance);
  311. }
  312.  
  313. private int addVertex(final float x, final float y, final float z, final float tx, final float ty, final float nx,
  314.         final float ny, final float nz, final Color color)
  315. {
  316.     if (texCoords.position() < texCoords.limit())
  317.     {
  318.         vertices.put(x);
  319.         vertices.put(y);
  320.         vertices.put(z);
  321.         colors.put(color.getRed() / 255.0f);
  322.         colors.put(color.getGreen() / 255.0f);
  323.         colors.put(color.getBlue() / 255.0f);
  324.         colors.put(color.getAlpha() / 255.0f);
  325.         texCoords.put(tx);
  326.         texCoords.put(ty);
  327.         normals.put(nx);
  328.         normals.put(ny);
  329.         normals.put(nz);
  330.         return (texCoords.position() >> 1) - 1;
  331.     }
  332.     else
  333.     {
  334.         throw new FMEERuntimeException("Too many vertices");
  335.     }
  336. }
  337.  
  338. private void clear()
  339. {
  340.     vertices.clear();
  341.     normals.clear();
  342.     colors.clear();
  343.     indices.clear();
  344.     texCoords.clear();
  345.     packed = false;
  346. }
  347.  
  348. private void display(final GL gl)
  349. {
  350.     gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
  351.     gl.glBindBuffer(GL.GL_ARRAY_BUFFER, getVertexBufferObject());
  352.     gl.glVertexPointer(3, GL.GL_FLOAT, 0, 0);
  353.  
  354.     gl.glEnableClientState(GL.GL_NORMAL_ARRAY);
  355.     gl.glBindBuffer(GL.GL_ARRAY_BUFFER, getNormalsBufferObject());
  356.     gl.glNormalPointer(GL.GL_FLOAT, 0, 0);
  357.  
  358.     gl.glEnableClientState(GL.GL_COLOR_ARRAY);
  359.     gl.glBindBuffer(GL.GL_ARRAY_BUFFER, getColorBufferObject());
  360.     gl.glColorPointer(4, GL.GL_FLOAT, 0, 0);
  361.  
  362.     gl.glClientActiveTexture(GL.GL_TEXTURE0);
  363.  
  364.     gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY);
  365.     gl.glBindBuffer(GL.GL_ARRAY_BUFFER, getTexCoordBufferObject());
  366.     gl.glTexCoordPointer(2, GL.GL_FLOAT, 0, 0);
  367.  
  368.     gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, getIndicesBufferObject());
  369.  
  370.     final int count = getNoOfIndices();
  371.     gl.glDrawElements(GL.GL_TRIANGLES, count, GL.GL_UNSIGNED_INT, 0);
  372.     gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0);
  373.     gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
  374.  
  375.     gl.glDisableClientState(GL.GL_VERTEX_ARRAY);
  376.     gl.glDisableClientState(GL.GL_NORMAL_ARRAY);
  377.     gl.glDisableClientState(GL.GL_COLOR_ARRAY);
  378.     gl.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY);
  379. }
  380.  
  381. @Override
  382. public void display(final GL gl, final SimpleProjection projection, final float disparityTop,
  383.         final float disparityBottom, final float disparityBlend, final Field field)
  384. {
  385.     if (!this.initialisedRenderer)
  386.     {
  387.         init(gl);
  388.     }
  389.  
  390.     if (this.initialisedRenderer)
  391.     {
  392.         if (requiresRedraw)
  393.         {
  394.             clear();
  395.             populateBuffers();
  396.             pack();
  397.             requiresRedraw = false;
  398.             final int usage = GL.GL_STATIC_DRAW;
  399.  
  400.             gl.glBindBuffer(GL.GL_ARRAY_BUFFER, getVertexBufferObject());
  401.             gl.glBufferData(GL.GL_ARRAY_BUFFER, getNoOfVertices() * 3 * 4, getVertices(), usage);
  402.             gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
  403.  
  404.             gl.glBindBuffer(GL.GL_ARRAY_BUFFER, getNormalsBufferObject());
  405.             gl.glBufferData(GL.GL_ARRAY_BUFFER, getNoOfNormals() * 3 * 4, getNormals(), usage);
  406.             gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
  407.  
  408.             gl.glBindBuffer(GL.GL_ARRAY_BUFFER, getTexCoordBufferObject());
  409.             gl.glBufferData(GL.GL_ARRAY_BUFFER, getNoOfVertices() * 2 * 4, getTexCoords(), usage);
  410.             gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
  411.  
  412.             gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, getIndicesBufferObject());
  413.             gl.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, getNoOfIndices() * 4, getIndices(), usage);
  414.             gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0);
  415.  
  416.             gl.glBindBuffer(GL.GL_ARRAY_BUFFER, getColorBufferObject());
  417.             gl.glBufferData(GL.GL_ARRAY_BUFFER, getNoOfVertices() * 4 * 4, getColors(), usage);
  418.             gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
  419.         }
  420.  
  421.         gl.glDepthFunc(currentGlComparison);
  422.  
  423.         gl.glEnable(GL.GL_TEXTURE_2D);
  424.         gl.glActiveTexture(GL.GL_TEXTURE0);
  425.  
  426.         for (int i = 0; i < modelInstances.size(); ++i)
  427.         {
  428.             if (modelInstances.get(i).isEnabled())
  429.             {
  430.                 layerTextureShader.updateShader(gl, projection, disparityTop, disparityBottom, disparityBlend,
  431.                         field, modelInstances.get(i).getTransform().getRotation(),
  432.                         modelInstances.get(i).getTransform().getScale(),
  433.                         modelInstances.get(i).getTransform().getTranslation(), modelInstances.get(i).getKeyColor());
  434.                 layerTextureShader.use(gl);
  435.                 display(gl);
  436.                 layerTextureShader.release(gl);
  437.             }
  438.         }
  439.         gl.glDisable(GL.GL_TEXTURE_2D);
  440.     }
  441. }
  442.  
  443. private int getColorBufferObject()
  444. {
  445.     return bufferObjects[1];
  446. }
  447.  
  448. private FloatBuffer getColors()
  449. {
  450.     pack();
  451.     return colors;
  452. }
  453.  
  454. private IntBuffer getIndices()
  455. {
  456.     pack();
  457.     return indices;
  458. }
  459.  
  460. private int getIndicesBufferObject()
  461. {
  462.     return bufferObjects[2];
  463. }
  464.  
  465. private int getNoOfIndices()
  466. {
  467.     pack();
  468.     return indices.limit();
  469. }
  470.  
  471. private int getNoOfNormals()
  472. {
  473.     pack();
  474.     return normals.limit();
  475. }
  476.  
  477. private int getNoOfVertices()
  478. {
  479.     pack();
  480.     return vertices.limit() / 3;
  481. }
  482.  
  483. private FloatBuffer getNormals()
  484. {
  485.     pack();
  486.     return normals;
  487. }
  488.  
  489. private int getNormalsBufferObject()
  490. {
  491.     return bufferObjects[4];
  492. }
  493.  
  494. private int getTexCoordBufferObject()
  495. {
  496.     return bufferObjects[3];
  497. }
  498.  
  499. private FloatBuffer getTexCoords()
  500. {
  501.     pack();
  502.     return texCoords;
  503. }
  504.  
  505. private int getVertexBufferObject()
  506. {
  507.     return bufferObjects[0];
  508. }
  509.  
  510. private FloatBuffer getVertices()
  511. {
  512.     pack();
  513.     return vertices;
  514. }
  515.  
  516. public void init(final GL gl)
  517. {
  518.     gl.glGenBuffers(5, bufferObjects, 0);
  519.     try
  520.     {
  521.         layerTextureShader = new PlayoutShaderProgram(gl, getClass().getResourceAsStream("modelVertex.glsl"),
  522.                 getClass().getResourceAsStream("modelFrag.glsl"));
  523.     }
  524.     catch (final IOException e)
  525.     {
  526.         ErrorReporter.error(this, "Failed to create shader", e.getMessage(), e, ErrorHandler.CONTINUE_APPLICATION);
  527.     }
  528.     this.initialisedRenderer = true;
  529. }
  530.  
  531. public boolean isEmpty()
  532. {
  533.     pack();
  534.     return vertices.limit() == 0;
  535. }
  536.  
  537. private void pack()
  538. {
  539.     if (!packed)
  540.     {
  541.         indices.flip();
  542.         vertices.flip();
  543.         colors.flip();
  544.         texCoords.flip();
  545.         normals.flip();
  546.         packed = true;
  547.     }
  548. }
  549.  
  550. @SuppressWarnings("unused")
  551. public void populateBuffers()
  552. {
  553.     final List<float[]> vertices = modelData.getVertices();
  554.     final List<int[]> faceAnchors = modelData.getFaces();
  555.     final List<float[]> colors = modelData.getColors();
  556.     final List<float[]> vertexTextures = modelData.getVertexTextures();
  557.     final List<int[]> faceTextures = modelData.getFacesTextures();
  558.     final List<String> textures = modelData.getFaceMaterial();
  559.     final List<float[]> normals = modelData.getVertexNormals();
  560.     final List<int[]> faceNormalAnchors = modelData.getFacesNormals();
  561.  
  562.     for (int i = 0; i < faceAnchors.size(); ++i)
  563.     {
  564.         if (faceAnchors.get(i).length >= 4)
  565.         {
  566.             final int index1 = faceAnchors.get(i)[0] - 1;
  567.             final int index2 = faceAnchors.get(i)[1] - 1;
  568.             final int index3 = faceAnchors.get(i)[2] - 1;
  569.             final int index4 = faceAnchors.get(i)[3] - 1;
  570.  
  571.             final Tuple3f v1 = new Vector3f(vertices.get(index1)[0], vertices.get(index1)[1],
  572.                     vertices.get(index1)[2]);
  573.  
  574.             final Tuple3f v2 = new Vector3f(vertices.get(index2)[0], vertices.get(index2)[1],
  575.                     vertices.get(index2)[2]);
  576.  
  577.             final Tuple3f v3 = new Vector3f(vertices.get(index3)[0], vertices.get(index3)[1],
  578.                     vertices.get(index3)[2]);
  579.  
  580.             final Tuple3f v4 = new Vector3f(vertices.get(index4)[0], vertices.get(index4)[1],
  581.                     vertices.get(index4)[2]);
  582.  
  583.             final Tuple3f n1;
  584.             final Tuple3f n2;
  585.             final Tuple3f n3;
  586.             final Tuple3f n4;
  587.  
  588.             if (!normals.isEmpty() && normals != null && normals.get(index1) != null && normals.get(index2) != null
  589.                     && normals.get(index3) != null && normals.get(index4) != null)
  590.             {
  591.                 final int nIndex1;
  592.                 final int nIndex2;
  593.                 final int nIndex3;
  594.                 final int nIndex4;
  595.                 if (faceNormalAnchors.isEmpty() || faceNormalAnchors.get(i)[0] == -1)
  596.                 {
  597.                     nIndex1 = faceNormalAnchors.get(i)[0] - 1;
  598.                     nIndex2 = faceNormalAnchors.get(i)[1] - 1;
  599.                     nIndex3 = faceNormalAnchors.get(i)[2] - 1;
  600.                     nIndex4 = faceNormalAnchors.get(i)[3] - 1;
  601.                 }
  602.                 else
  603.                 {
  604.                     nIndex1 = index1;
  605.                     nIndex2 = index2;
  606.                     nIndex3 = index3;
  607.                     nIndex4 = index4;
  608.                 }
  609.  
  610.                 n1 = new Vector3f(normals.get(nIndex1)[0], normals.get(nIndex1)[1], normals.get(nIndex1)[2]);
  611.                 n2 = new Vector3f(normals.get(nIndex2)[0], normals.get(nIndex2)[1], normals.get(nIndex2)[2]);
  612.                 n3 = new Vector3f(normals.get(nIndex3)[0], normals.get(nIndex3)[1], normals.get(nIndex3)[2]);
  613.                 n4 = new Vector3f(normals.get(nIndex4)[0], normals.get(nIndex4)[1], normals.get(nIndex4)[2]);
  614.             }
  615.             else
  616.             {
  617.                 System.err.println("Something has gone seriously wrong, no normals have been found");
  618.                 n1 = new Vector3f(0, 0, 0);
  619.                 n2 = new Vector3f(0, 0, 0);
  620.                 n3 = new Vector3f(0, 0, 0);
  621.                 n4 = new Vector3f(0, 0, 0);
  622.             }
  623.  
  624.             // if (model.usesTextures())
  625.             // {
  626.             // final int texIndex1 = faceTextures.get(i)[0] - 1;
  627.             // final int texIndex2 = faceTextures.get(i)[1] - 1;
  628.             // final int texIndex3 = faceTextures.get(i)[2] - 1;
  629.             // final int texIndex4 = faceTextures.get(i)[3] - 1;
  630.             //
  631.             // final float texCoord1x = vertexTextures.get(texIndex1)[0];
  632.             // final float texCoord1y = vertexTextures.get(texIndex1)[1];
  633.             // final float texCoord2x = vertexTextures.get(texIndex2)[0];
  634.             // final float texCoord2y = vertexTextures.get(texIndex2)[1];
  635.             // final float texCoord3x = vertexTextures.get(texIndex3)[0];
  636.             // final float texCoord3y = vertexTextures.get(texIndex3)[1];
  637.             // final float texCoord4x = vertexTextures.get(texIndex4)[0];
  638.             // final float texCoord4y = vertexTextures.get(texIndex4)[1];
  639.             // projectQuad(v1, v2, v3, v4, texCoord1x, texCoord1y, texCoord2x, texCoord2y, texCoord3x,
  640.             // texCoord3y, texCoord4x, texCoord4y, n1, n2, n3, n4, new Color(colors.get(i)[0],
  641.             // colors.get(i)[1], colors.get(i)[2], colors.get(i)[3]));
  642.             // }
  643.             // else
  644.             // {
  645.             projectQuad(v1, v2, v3, v4, n1, n2, n3, n4, new Color(colors.get(i)[0], colors.get(i)[1],
  646.                     colors.get(i)[2], colors.get(i)[3]));
  647.             // }
  648.         }
  649.         else if (faceAnchors.get(i).length == 3)
  650.         {
  651.             final int index1 = faceAnchors.get(i)[0] - 1;
  652.             final int index2 = faceAnchors.get(i)[1] - 1;
  653.             final int index3 = faceAnchors.get(i)[2] - 1;
  654.  
  655.             final Tuple3f v1 = new Vector3f(vertices.get(index1)[0], vertices.get(index1)[1],
  656.                     vertices.get(index1)[2]);
  657.  
  658.             final Tuple3f v2 = new Vector3f(vertices.get(index2)[0], vertices.get(index2)[1],
  659.                     vertices.get(index2)[2]);
  660.  
  661.             final Tuple3f v3 = new Vector3f(vertices.get(index3)[0], vertices.get(index3)[1],
  662.                     vertices.get(index3)[2]);
  663.  
  664.             final Tuple3f n1 = new Vector3f(normals.get(index1)[0], normals.get(index1)[1], normals.get(index1)[2]);
  665.             final Tuple3f n2 = new Vector3f(normals.get(index2)[0], normals.get(index2)[1], normals.get(index2)[2]);
  666.             final Tuple3f n3 = new Vector3f(normals.get(index3)[0], normals.get(index3)[1], normals.get(index3)[2]);
  667.  
  668.             projectTriangle(v1, v2, v3, n1, n2, n3, new Color(colors.get(i)[0], colors.get(i)[1], colors.get(i)[2],
  669.                     colors.get(i)[3]));
  670.         }
  671.         else
  672.         {
  673.             System.out.println("Number of faces: " + faceAnchors.get(i).length);
  674.         }
  675.     }
  676. }
  677.  
  678. private synchronized void projectQuad(final Tuple3f point1, final Tuple3f point2, final Tuple3f point3,
  679.         final Tuple3f point4, final Tuple3f nPoint1, final Tuple3f nPoint2, final Tuple3f nPoint3,
  680.         final Tuple3f nPoint4, final Color color)
  681. {
  682.     final int vertex1 = addVertex(point1.getX(), point1.getY(), point1.getZ(), 0f, 0f, nPoint1.getX(),
  683.             nPoint1.getY(), nPoint1.getZ(), color);
  684.     final int vertex2 = addVertex(point2.getX(), point2.getY(), point2.getZ(), 0f, 1f, nPoint2.getX(),
  685.             nPoint2.getY(), nPoint2.getZ(), color);
  686.     final int vertex3 = addVertex(point3.getX(), point3.getY(), point3.getZ(), 1f, 1f, nPoint3.getX(),
  687.             nPoint3.getY(), nPoint3.getZ(), color);
  688.     final int vertex4 = addVertex(point4.getX(), point4.getY(), point4.getZ(), 1f, 0f, nPoint4.getX(),
  689.             nPoint4.getY(), nPoint4.getZ(), color);
  690.  
  691.     addTriangle(vertex1, vertex2, vertex4);
  692.     addTriangle(vertex2, vertex3, vertex4);
  693. }
  694.  
  695. private synchronized void projectTriangle(final Tuple3f point1, final Tuple3f point2, final Tuple3f point3,
  696.         final Tuple3f nPoint1, final Tuple3f nPoint2, final Tuple3f nPoint3, final Color color)
  697. {
  698.     final int vertex1 = addVertex(point1.getX(), point1.getY(), point1.getZ(), 0f, 0f, nPoint1.getX(),
  699.             nPoint1.getY(), nPoint1.getZ(), color);
  700.     final int vertex2 = addVertex(point2.getX(), point2.getY(), point2.getZ(), 0f, 1f, nPoint2.getX(),
  701.             nPoint2.getY(), nPoint2.getZ(), color);
  702.     final int vertex3 = addVertex(point3.getX(), point3.getY(), point3.getZ(), 1f, 1f, nPoint3.getX(),
  703.             nPoint3.getY(), nPoint3.getZ(), color);
  704.  
  705.     addTriangle(vertex1, vertex2, vertex3);
  706. }
  707.  
  708. @Override
  709. public void updateVertices()
  710. {
  711.     requiresRedraw = true;
  712. }
  713. }