|
@@ -1,5 +1,5 @@
|
|
/*
|
|
/*
|
|
- * Copyright (c) 2009-2018 jMonkeyEngine
|
|
|
|
|
|
+ * Copyright (c) 2009-2019 jMonkeyEngine
|
|
* All rights reserved.
|
|
* All rights reserved.
|
|
*
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* Redistribution and use in source and binary forms, with or without
|
|
@@ -42,9 +42,12 @@ import com.jme3.scene.Geometry;
|
|
import com.jme3.scene.Mesh;
|
|
import com.jme3.scene.Mesh;
|
|
import com.jme3.scene.Node;
|
|
import com.jme3.scene.Node;
|
|
import com.jme3.scene.Spatial;
|
|
import com.jme3.scene.Spatial;
|
|
|
|
+import com.jme3.scene.VertexBuffer;
|
|
import com.jme3.scene.VertexBuffer.Type;
|
|
import com.jme3.scene.VertexBuffer.Type;
|
|
|
|
+import java.nio.Buffer;
|
|
import java.nio.ByteBuffer;
|
|
import java.nio.ByteBuffer;
|
|
import java.nio.FloatBuffer;
|
|
import java.nio.FloatBuffer;
|
|
|
|
+import java.nio.ShortBuffer;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -268,7 +271,8 @@ public class RagdollUtils {
|
|
private static List<Float> getPoints(Mesh mesh, int boneIndex, Vector3f initialScale, Vector3f offset, float weightThreshold) {
|
|
private static List<Float> getPoints(Mesh mesh, int boneIndex, Vector3f initialScale, Vector3f offset, float weightThreshold) {
|
|
|
|
|
|
FloatBuffer vertices = mesh.getFloatBuffer(Type.Position);
|
|
FloatBuffer vertices = mesh.getFloatBuffer(Type.Position);
|
|
- ByteBuffer boneIndices = (ByteBuffer) mesh.getBuffer(Type.BoneIndex).getData();
|
|
|
|
|
|
+ VertexBuffer biBuf = mesh.getBuffer(VertexBuffer.Type.BoneIndex);
|
|
|
|
+ Buffer boneIndices = biBuf.getDataReadOnly();
|
|
FloatBuffer boneWeight = (FloatBuffer) mesh.getBuffer(Type.BoneWeight).getData();
|
|
FloatBuffer boneWeight = (FloatBuffer) mesh.getBuffer(Type.BoneWeight).getData();
|
|
|
|
|
|
vertices.rewind();
|
|
vertices.rewind();
|
|
@@ -284,7 +288,8 @@ public class RagdollUtils {
|
|
boolean add = false;
|
|
boolean add = false;
|
|
int start = i / 3 * 4;
|
|
int start = i / 3 * 4;
|
|
for (k = start; k < start + 4; k++) {
|
|
for (k = start; k < start + 4; k++) {
|
|
- if (boneIndices.get(k) == boneIndex && boneWeight.get(k) >= weightThreshold) {
|
|
|
|
|
|
+ if (readIndex(boneIndices, k) == boneIndex
|
|
|
|
+ && boneWeight.get(k) >= weightThreshold) {
|
|
add = true;
|
|
add = true;
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
@@ -363,8 +368,8 @@ public class RagdollUtils {
|
|
public static boolean hasVertices(int boneIndex, Mesh[] targets,
|
|
public static boolean hasVertices(int boneIndex, Mesh[] targets,
|
|
float weightThreshold) {
|
|
float weightThreshold) {
|
|
for (Mesh mesh : targets) {
|
|
for (Mesh mesh : targets) {
|
|
- ByteBuffer boneIndices
|
|
|
|
- = (ByteBuffer) mesh.getBuffer(Type.BoneIndex).getData();
|
|
|
|
|
|
+ VertexBuffer biBuf = mesh.getBuffer(VertexBuffer.Type.BoneIndex);
|
|
|
|
+ Buffer boneIndices = biBuf.getDataReadOnly();
|
|
FloatBuffer boneWeight
|
|
FloatBuffer boneWeight
|
|
= (FloatBuffer) mesh.getBuffer(Type.BoneWeight).getData();
|
|
= (FloatBuffer) mesh.getBuffer(Type.BoneWeight).getData();
|
|
|
|
|
|
@@ -375,7 +380,7 @@ public class RagdollUtils {
|
|
for (int i = 0; i < vertexComponents; i += 3) {
|
|
for (int i = 0; i < vertexComponents; i += 3) {
|
|
int start = i / 3 * 4;
|
|
int start = i / 3 * 4;
|
|
for (int k = start; k < start + 4; k++) {
|
|
for (int k = start; k < start + 4; k++) {
|
|
- if (boneIndices.get(k) == boneIndex
|
|
|
|
|
|
+ if (readIndex(boneIndices, k) == boneIndex
|
|
&& boneWeight.get(k) >= weightThreshold) {
|
|
&& boneWeight.get(k) >= weightThreshold) {
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
@@ -385,4 +390,29 @@ public class RagdollUtils {
|
|
|
|
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Read an index from a buffer.
|
|
|
|
+ *
|
|
|
|
+ * @param buffer a buffer of bytes or shorts (not null)
|
|
|
|
+ * @param k the position from which the index will be read
|
|
|
|
+ * @return the index value (≥0)
|
|
|
|
+ */
|
|
|
|
+ public static int readIndex(Buffer buffer, int k) {
|
|
|
|
+ int result;
|
|
|
|
+ if (buffer instanceof ByteBuffer) {
|
|
|
|
+ ByteBuffer byteBuffer = (ByteBuffer) buffer;
|
|
|
|
+ byte b = byteBuffer.get(k);
|
|
|
|
+ result = 0xff & b;
|
|
|
|
+ } else if (buffer instanceof ShortBuffer) {
|
|
|
|
+ ShortBuffer shortBuffer = (ShortBuffer) buffer;
|
|
|
|
+ short s = shortBuffer.get(k);
|
|
|
|
+ result = 0xffff & s;
|
|
|
|
+ } else {
|
|
|
|
+ throw new IllegalArgumentException(buffer.getClass().getName());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ assert result >= 0 : result;
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
}
|
|
}
|