* Remove most common usage of IntMap.iterator()

* Correct small typo in UniformBinding
 * Make IntMap.iterator() make new iterator each time 
 * Prevent TangentBinormalGenerator from crashing when it encounters some mesh without texcoord/normal buffers
 * AWTLoader now properly fails when AWT can't load the image instead of returning null 

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9219 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
Sha..rd 13 years ago
parent 5cf9954814
commit be7a22e3d5
  1. 7
      engine/src/core/com/jme3/renderer/RenderManager.java
  2. 6
      engine/src/core/com/jme3/scene/BatchNode.java
  3. 26
      engine/src/core/com/jme3/scene/Mesh.java
  4. 2
      engine/src/core/com/jme3/shader/UniformBinding.java
  5. 7
      engine/src/core/com/jme3/util/IntMap.java
  6. 12
      engine/src/core/com/jme3/util/TangentBinormalGenerator.java
  7. 14
      engine/src/desktop/com/jme3/texture/plugins/AWTLoader.java
  8. 5
      engine/src/ogre/com/jme3/scene/plugins/ogre/MeshLoader.java
  9. 4
      engine/src/tools/jme3tools/converters/model/ModelConverter.java
  10. 6
      engine/src/tools/jme3tools/optimize/GeometryBatchFactory.java

@ -730,10 +730,9 @@ public class RenderManager {
gm.getMaterial().preload(this); gm.getMaterial().preload(this);
Mesh mesh = gm.getMesh(); Mesh mesh = gm.getMesh();
if (mesh != null) { if (mesh != null) {
for (Entry<VertexBuffer> entry : mesh.getBuffers()) { for (VertexBuffer vb : mesh.getBufferList().getArray()) {
VertexBuffer buf = entry.getValue(); if (vb.getData() != null) {
if (buf.getData() != null) { renderer.updateBufferData(vb);
renderer.updateBufferData(buf);
} }
} }
} }

@ -408,9 +408,9 @@ public class BatchNode extends Node implements Savable {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
for (Entry<VertexBuffer> entry : geom.getMesh().getBuffers()) { for (VertexBuffer vb : geom.getMesh().getBufferList().getArray()) {
compsForBuf[entry.getKey()] = entry.getValue().getNumComponents(); compsForBuf[vb.getBufferType().ordinal()] = vb.getNumComponents();
formatForBuf[entry.getKey()] = entry.getValue().getFormat(); formatForBuf[vb.getBufferType().ordinal()] = vb.getFormat();
} }
if (mode != null && mode != listMode) { if (mode != null && mode != listMode) {

@ -43,7 +43,6 @@ import com.jme3.math.Matrix4f;
import com.jme3.math.Triangle; import com.jme3.math.Triangle;
import com.jme3.math.Vector2f; import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.scene.VertexBuffer;
import com.jme3.scene.VertexBuffer.Format; import com.jme3.scene.VertexBuffer.Format;
import com.jme3.scene.VertexBuffer.Type; import com.jme3.scene.VertexBuffer.Type;
import com.jme3.scene.VertexBuffer.Usage; import com.jme3.scene.VertexBuffer.Usage;
@ -55,8 +54,6 @@ import com.jme3.util.SafeArrayList;
import java.io.IOException; import java.io.IOException;
import java.nio.*; import java.nio.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
/** /**
* <code>Mesh</code> is used to store rendering data. * <code>Mesh</code> is used to store rendering data.
@ -237,9 +234,9 @@ public class Mesh implements Savable, Cloneable {
clone.buffers = new IntMap<VertexBuffer>(); clone.buffers = new IntMap<VertexBuffer>();
clone.buffersList = new SafeArrayList<VertexBuffer>(VertexBuffer.class); clone.buffersList = new SafeArrayList<VertexBuffer>(VertexBuffer.class);
for (Entry<VertexBuffer> ent : buffers){ for (VertexBuffer vb : buffersList.getArray()){
VertexBuffer bufClone = ent.getValue().clone(); VertexBuffer bufClone = vb.clone();
clone.buffers.put(ent.getKey(), bufClone); clone.buffers.put(vb.getBufferType().ordinal(), bufClone);
clone.buffersList.add(bufClone); clone.buffersList.add(bufClone);
} }
@ -540,8 +537,8 @@ public class Mesh implements Savable, Cloneable {
* for all {@link VertexBuffer vertex buffers} on this Mesh. * for all {@link VertexBuffer vertex buffers} on this Mesh.
*/ */
public void setStatic() { public void setStatic() {
for (Entry<VertexBuffer> entry : buffers){ for (VertexBuffer vb : buffersList.getArray()){
entry.getValue().setUsage(Usage.Static); vb.setUsage(Usage.Static);
} }
} }
@ -551,8 +548,8 @@ public class Mesh implements Savable, Cloneable {
* for all {@link VertexBuffer vertex buffers} on this Mesh. * for all {@link VertexBuffer vertex buffers} on this Mesh.
*/ */
public void setDynamic() { public void setDynamic() {
for (Entry<VertexBuffer> entry : buffers){ for (VertexBuffer vb : buffersList.getArray()){
entry.getValue().setUsage(Usage.Dynamic); vb.setUsage(Usage.Dynamic);
} }
} }
@ -562,8 +559,8 @@ public class Mesh implements Savable, Cloneable {
* for all {@link VertexBuffer vertex buffers} on this Mesh. * for all {@link VertexBuffer vertex buffers} on this Mesh.
*/ */
public void setStreamed(){ public void setStreamed(){
for (Entry<VertexBuffer> entry : buffers){ for (VertexBuffer vb : buffersList.getArray()){
entry.getValue().setUsage(Usage.Stream); vb.setUsage(Usage.Stream);
} }
} }
@ -575,9 +572,8 @@ public class Mesh implements Savable, Cloneable {
@Deprecated @Deprecated
public void setInterleaved(){ public void setInterleaved(){
ArrayList<VertexBuffer> vbs = new ArrayList<VertexBuffer>(); ArrayList<VertexBuffer> vbs = new ArrayList<VertexBuffer>();
for (Entry<VertexBuffer> entry : buffers){ vbs.addAll(buffersList);
vbs.add(entry.getValue());
}
// ArrayList<VertexBuffer> vbs = new ArrayList<VertexBuffer>(buffers.values()); // ArrayList<VertexBuffer> vbs = new ArrayList<VertexBuffer>(buffers.values());
// index buffer not included when interleaving // index buffer not included when interleaving
vbs.remove(getBuffer(Type.Index)); vbs.remove(getBuffer(Type.Index));

@ -73,7 +73,7 @@ public enum UniformBinding {
WorldViewProjectionMatrix, WorldViewProjectionMatrix,
/** /**
* The view projection matrix. Converts Model space to Clip/Projection * The view projection matrix. Converts World space to Clip/Projection
* space. * space.
* Type: mat4 * Type: mat4
*/ */

@ -45,8 +45,6 @@ import java.util.Map;
*/ */
public final class IntMap<T> implements Iterable<Entry<T>>, Cloneable { public final class IntMap<T> implements Iterable<Entry<T>>, Cloneable {
private final IntMapIterator iterator = new IntMapIterator();
private Entry[] table; private Entry[] table;
private final float loadFactor; private final float loadFactor;
private int size, mask, capacity, threshold; private int size, mask, capacity, threshold;
@ -200,8 +198,9 @@ public final class IntMap<T> implements Iterable<Entry<T>>, Cloneable {
} }
public Iterator<Entry<T>> iterator() { public Iterator<Entry<T>> iterator() {
iterator.beginUse(); IntMapIterator it = new IntMapIterator();
return iterator; it.beginUse();
return it;
} }
final class IntMapIterator implements Iterator<Entry<T>> { final class IntMapIterator implements Iterator<Entry<T>> {

@ -117,7 +117,13 @@ public class TangentBinormalGenerator {
} }
} else { } else {
Geometry geom = (Geometry) scene; Geometry geom = (Geometry) scene;
generate(geom.getMesh()); Mesh mesh = geom.getMesh();
// Check to ensure mesh has texcoords and normals before generating
if (mesh.getBuffer(Type.TexCoord) != null
&& mesh.getBuffer(Type.Normal) != null){
generate(geom.getMesh());
}
} }
} }
@ -640,7 +646,7 @@ public class TangentBinormalGenerator {
lineMesh.setBuffer(Type.Color, 4, lineColor); lineMesh.setBuffer(Type.Color, 4, lineColor);
lineMesh.setStatic(); lineMesh.setStatic();
lineMesh.setInterleaved(); //lineMesh.setInterleaved();
return lineMesh; return lineMesh;
} }
@ -733,7 +739,7 @@ public class TangentBinormalGenerator {
lineMesh.setBuffer(Type.Color, 4, lineColor); lineMesh.setBuffer(Type.Color, 4, lineColor);
lineMesh.setStatic(); lineMesh.setStatic();
lineMesh.setInterleaved(); //lineMesh.setInterleaved();
return lineMesh; return lineMesh;
} }
} }

@ -33,6 +33,7 @@
package com.jme3.texture.plugins; package com.jme3.texture.plugins;
import com.jme3.asset.AssetInfo; import com.jme3.asset.AssetInfo;
import com.jme3.asset.AssetLoadException;
import com.jme3.asset.AssetLoader; import com.jme3.asset.AssetLoader;
import com.jme3.asset.TextureKey; import com.jme3.asset.TextureKey;
import com.jme3.texture.Image; import com.jme3.texture.Image;
@ -185,27 +186,30 @@ public class AWTLoader implements AssetLoader {
public Image load(InputStream in, boolean flipY) throws IOException{ public Image load(InputStream in, boolean flipY) throws IOException{
ImageIO.setUseCache(false); ImageIO.setUseCache(false);
BufferedImage img = ImageIO.read(in); BufferedImage img = ImageIO.read(in);
if (img == null) if (img == null){
return null; return null;
}
return load(img, flipY); return load(img, flipY);
} }
public Object load(AssetInfo info) throws IOException { public Object load(AssetInfo info) throws IOException {
if (ImageIO.getImageWritersBySuffix(info.getKey().getExtension()) != null){ if (ImageIO.getImageReadersBySuffix(info.getKey().getExtension()) != null){
boolean flip = ((TextureKey) info.getKey()).isFlipY(); boolean flip = ((TextureKey) info.getKey()).isFlipY();
InputStream in = null; InputStream in = null;
try { try {
in = info.openStream(); in = info.openStream();
Image img = load(in, flip); Image img = load(in, flip);
if (img == null){
throw new AssetLoadException("The given image cannot be loaded " + info.getKey());
}
return img; return img;
} finally { } finally {
if (in != null){ if (in != null){
in.close(); in.close();
} }
} }
}else{
throw new AssetLoadException("The extension " + info.getKey().getExtension() + " is not supported");
} }
return null;
} }
} }

@ -712,9 +712,8 @@ public class MeshLoader extends DefaultHandler implements AssetLoader {
} else if (qName.equals("geometry") } else if (qName.equals("geometry")
|| qName.equals("sharedgeometry")) { || qName.equals("sharedgeometry")) {
// finish writing to buffers // finish writing to buffers
IntMap<VertexBuffer> bufs = mesh.getBuffers(); for (VertexBuffer buf : mesh.getBufferList().getArray()) {
for (Entry<VertexBuffer> entry : bufs) { Buffer data = buf.getData();
Buffer data = entry.getValue().getData();
if (data.position() != 0) { if (data.position() != 0) {
data.flip(); data.flip();
} }

@ -69,7 +69,7 @@ public class ModelConverter {
ts.setListsOnly(listOnly); ts.setListsOnly(listOnly);
ts.setMinStripSize(minStripSize); ts.setMinStripSize(minStripSize);
IndexBuffer ib = mesh.getIndexBuffer(); IndexBuffer ib = mesh.getIndicesAsList();
int[] indices = new int[ib.size()]; int[] indices = new int[ib.size()];
for (int i = 0; i < indices.length; i++) for (int i = 0; i < indices.length; i++)
indices[i] = ib.get(i); indices[i] = ib.get(i);
@ -157,7 +157,7 @@ public class ModelConverter {
mesh.setBuffer(vb); mesh.setBuffer(vb);
} }
} }
mesh.setInterleaved(); //mesh.setInterleaved();
} }
private static void optimizeScene(Spatial source, boolean toFixed){ private static void optimizeScene(Spatial source, boolean toFixed){

@ -130,9 +130,9 @@ public class GeometryBatchFactory {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
for (Entry<VertexBuffer> entry : geom.getMesh().getBuffers()) { for (VertexBuffer vb : geom.getMesh().getBufferList().getArray()){
compsForBuf[entry.getKey()] = entry.getValue().getNumComponents(); compsForBuf[vb.getBufferType().ordinal()] = vb.getNumComponents();
formatForBuf[entry.getKey()] = entry.getValue().getFormat(); formatForBuf[vb.getBufferType().ordinal()] = vb.getFormat();
} }
if (mode != null && mode != listMode) { if (mode != null && mode != listMode) {

Loading…
Cancel
Save