* 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);
Mesh mesh = gm.getMesh();
if (mesh != null) {
for (Entry<VertexBuffer> entry : mesh.getBuffers()) {
VertexBuffer buf = entry.getValue();
if (buf.getData() != null) {
renderer.updateBufferData(buf);
for (VertexBuffer vb : mesh.getBufferList().getArray()) {
if (vb.getData() != null) {
renderer.updateBufferData(vb);
}
}
}

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

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

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

@ -45,8 +45,6 @@ import java.util.Map;
*/
public final class IntMap<T> implements Iterable<Entry<T>>, Cloneable {
private final IntMapIterator iterator = new IntMapIterator();
private Entry[] table;
private final float loadFactor;
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() {
iterator.beginUse();
return iterator;
IntMapIterator it = new IntMapIterator();
it.beginUse();
return it;
}
final class IntMapIterator implements Iterator<Entry<T>> {

@ -117,7 +117,13 @@ public class TangentBinormalGenerator {
}
} else {
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.setStatic();
lineMesh.setInterleaved();
//lineMesh.setInterleaved();
return lineMesh;
}
@ -733,7 +739,7 @@ public class TangentBinormalGenerator {
lineMesh.setBuffer(Type.Color, 4, lineColor);
lineMesh.setStatic();
lineMesh.setInterleaved();
//lineMesh.setInterleaved();
return lineMesh;
}
}

@ -33,6 +33,7 @@
package com.jme3.texture.plugins;
import com.jme3.asset.AssetInfo;
import com.jme3.asset.AssetLoadException;
import com.jme3.asset.AssetLoader;
import com.jme3.asset.TextureKey;
import com.jme3.texture.Image;
@ -185,27 +186,30 @@ public class AWTLoader implements AssetLoader {
public Image load(InputStream in, boolean flipY) throws IOException{
ImageIO.setUseCache(false);
BufferedImage img = ImageIO.read(in);
if (img == null)
if (img == null){
return null;
}
return load(img, flipY);
}
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();
InputStream in = null;
try {
in = info.openStream();
Image img = load(in, flip);
if (img == null){
throw new AssetLoadException("The given image cannot be loaded " + info.getKey());
}
return img;
} finally {
if (in != null){
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")
|| qName.equals("sharedgeometry")) {
// finish writing to buffers
IntMap<VertexBuffer> bufs = mesh.getBuffers();
for (Entry<VertexBuffer> entry : bufs) {
Buffer data = entry.getValue().getData();
for (VertexBuffer buf : mesh.getBufferList().getArray()) {
Buffer data = buf.getData();
if (data.position() != 0) {
data.flip();
}

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

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

Loading…
Cancel
Save