Merge pull request #154 from abies/master
Speedup for TangengBinormalGenerator
This commit is contained in:
commit
d74d5e6ca9
@ -40,7 +40,9 @@ 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;
|
||||||
import com.jme3.scene.mesh.IndexBuffer;
|
import com.jme3.scene.mesh.IndexBuffer;
|
||||||
|
|
||||||
import static com.jme3.util.BufferUtils.*;
|
import static com.jme3.util.BufferUtils.*;
|
||||||
|
|
||||||
import java.nio.Buffer;
|
import java.nio.Buffer;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.DoubleBuffer;
|
import java.nio.DoubleBuffer;
|
||||||
@ -49,8 +51,12 @@ import java.nio.IntBuffer;
|
|||||||
import java.nio.ShortBuffer;
|
import java.nio.ShortBuffer;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@ -147,6 +153,44 @@ public class TangentBinormalGenerator {
|
|||||||
generate(scene, false);
|
generate(scene, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void generateParallel(Spatial scene, ExecutorService executor) {
|
||||||
|
final Set<Mesh> meshes = new HashSet<Mesh>();
|
||||||
|
scene.breadthFirstTraversal(new SceneGraphVisitor() {
|
||||||
|
@Override
|
||||||
|
public void visit(Spatial spatial) {
|
||||||
|
if (spatial instanceof Geometry) {
|
||||||
|
Geometry geom = (Geometry) spatial;
|
||||||
|
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) {
|
||||||
|
meshes.add(mesh);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
List<Future<?>> futures = new ArrayList<Future<?>>();
|
||||||
|
for (final Mesh m : meshes) {
|
||||||
|
futures.add(executor.submit(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
generate(m, true, false);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
for (Future<?> f : futures) {
|
||||||
|
try {
|
||||||
|
f.get();
|
||||||
|
} catch (Exception exc) {
|
||||||
|
log.log(Level.WARNING, "Error while computing tangents", exc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void generate(Mesh mesh, boolean approxTangents, boolean splitMirrored) {
|
public static void generate(Mesh mesh, boolean approxTangents, boolean splitMirrored) {
|
||||||
int[] index = new int[3];
|
int[] index = new int[3];
|
||||||
Vector3f[] v = new Vector3f[3];
|
Vector3f[] v = new Vector3f[3];
|
||||||
@ -512,14 +556,16 @@ public class TangentBinormalGenerator {
|
|||||||
|
|
||||||
public static TriangleData processTriangle(int[] index,
|
public static TriangleData processTriangle(int[] index,
|
||||||
Vector3f[] v, Vector2f[] t) {
|
Vector3f[] v, Vector2f[] t) {
|
||||||
Vector3f edge1 = new Vector3f();
|
TempVars tmp = TempVars.get();
|
||||||
Vector3f edge2 = new Vector3f();
|
try {
|
||||||
Vector2f edge1uv = new Vector2f();
|
Vector3f edge1 = tmp.vect1;
|
||||||
Vector2f edge2uv = new Vector2f();
|
Vector3f edge2 = tmp.vect2;
|
||||||
|
Vector2f edge1uv = tmp.vect2d;
|
||||||
|
Vector2f edge2uv = tmp.vect2d2;
|
||||||
|
|
||||||
Vector3f tangent = new Vector3f();
|
Vector3f tangent = tmp.vect3;
|
||||||
Vector3f binormal = new Vector3f();
|
Vector3f binormal = tmp.vect4;
|
||||||
Vector3f normal = new Vector3f();
|
Vector3f normal = tmp.vect5;
|
||||||
|
|
||||||
t[1].subtract(t[0], edge1uv);
|
t[1].subtract(t[0], edge1uv);
|
||||||
t[2].subtract(t[0], edge2uv);
|
t[2].subtract(t[0], edge2uv);
|
||||||
@ -573,6 +619,9 @@ public class TangentBinormalGenerator {
|
|||||||
tangent,
|
tangent,
|
||||||
binormal,
|
binormal,
|
||||||
normal);
|
normal);
|
||||||
|
} finally {
|
||||||
|
tmp.release();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setToleranceAngle(float angle) {
|
public static void setToleranceAngle(float angle) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user