Skip to content

Commit e908655

Browse files
authored
Fix issue 1705 (serialize 6 mesh subclasses) (#1754)
* jme3-vr: implement serialization for CenterQuad * ArmatureInterJointsWire: add a no-arg constructor * jme3-core: implement serialization for skeleton debug meshes * TestCloneMesh: enable testing of skeleton-debug meshes * Surface: implement serialization
1 parent 0768b85 commit e908655

File tree

7 files changed

+365
-10
lines changed

7 files changed

+365
-10
lines changed

jme3-core/src/main/java/com/jme3/scene/debug/SkeletonInterBoneWire.java

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,19 @@
3636

3737
import com.jme3.animation.Bone;
3838
import com.jme3.animation.Skeleton;
39+
import com.jme3.export.InputCapsule;
40+
import com.jme3.export.JmeExporter;
41+
import com.jme3.export.JmeImporter;
42+
import com.jme3.export.OutputCapsule;
3943
import com.jme3.math.Vector3f;
4044
import com.jme3.scene.Mesh;
4145
import com.jme3.scene.VertexBuffer;
4246
import com.jme3.scene.VertexBuffer.Format;
4347
import com.jme3.scene.VertexBuffer.Type;
4448
import com.jme3.scene.VertexBuffer.Usage;
4549
import com.jme3.util.BufferUtils;
50+
import java.io.IOException;
51+
import java.util.HashMap;
4652

4753
/**
4854
* A class that displays a dotted line between a bone tail and its children's heads.
@@ -54,9 +60,9 @@ public class SkeletonInterBoneWire extends Mesh {
5460
/** The amount of connections between bones. */
5561
private int connectionsAmount;
5662
/** The skeleton that will be showed. */
57-
final private Skeleton skeleton;
63+
private Skeleton skeleton;
5864
/** The map between the bone index and its length. */
59-
final private Map<Integer, Float> boneLengths;
65+
private Map<Integer, Float> boneLengths;
6066

6167
/**
6268
* Creates buffers for points. Each line has POINT_AMOUNT of points.
@@ -83,6 +89,12 @@ public SkeletonInterBoneWire(Skeleton skeleton, Map<Integer, Float> boneLengths)
8389
this.updateCounts();
8490
}
8591

92+
/**
93+
* For serialization only. Do not use.
94+
*/
95+
protected SkeletonInterBoneWire() {
96+
}
97+
8698
/**
8799
* This method updates the geometry according to the positions of the bones.
88100
*/
@@ -112,6 +124,65 @@ public void updateGeometry() {
112124
this.updateBound();
113125
}
114126

127+
/**
128+
* De-serializes from the specified importer, for example when loading from
129+
* a J3O file.
130+
*
131+
* @param importer the importer to use (not null)
132+
* @throws IOException from the importer
133+
*/
134+
@Override
135+
public void read(JmeImporter importer) throws IOException {
136+
super.read(importer);
137+
InputCapsule capsule = importer.getCapsule(this);
138+
139+
connectionsAmount = capsule.readInt("connectionsAmount", 1);
140+
skeleton = (Skeleton) capsule.readSavable("skeleton", null);
141+
142+
int[] blKeys = capsule.readIntArray("blKeys", null);
143+
float[] blValues = capsule.readFloatArray("blValues", null);
144+
if (blKeys == null) {
145+
boneLengths = null;
146+
} else {
147+
assert blValues.length == blKeys.length;
148+
int numLengths = blKeys.length;
149+
boneLengths = new HashMap<>(numLengths);
150+
for (int i = 0; i < numLengths; ++i) {
151+
boneLengths.put(blKeys[i], blValues[i]);
152+
}
153+
}
154+
}
155+
156+
/**
157+
* Serializes to the specified exporter, for example when saving to a J3O
158+
* file. The current instance is unaffected.
159+
*
160+
* @param exporter the exporter to use (not null)
161+
* @throws IOException from the exporter
162+
*/
163+
@Override
164+
public void write(JmeExporter exporter) throws IOException {
165+
super.write(exporter);
166+
OutputCapsule capsule = exporter.getCapsule(this);
167+
168+
capsule.write(connectionsAmount, "connectionsAmount", 1);
169+
capsule.write(skeleton, "skeleton", null);
170+
171+
if (boneLengths != null) {
172+
int numLengths = boneLengths.size();
173+
int[] blKeys = new int[numLengths];
174+
float[] blValues = new float[numLengths];
175+
int i = 0;
176+
for (Map.Entry<Integer, Float> entry : boneLengths.entrySet()) {
177+
blKeys[i] = entry.getKey();
178+
blValues[i] = entry.getValue();
179+
++i;
180+
}
181+
capsule.write(blKeys, "blKeys", null);
182+
capsule.write(blValues, "blValues", null);
183+
}
184+
}
185+
115186
/**
116187
* This method counts the connections between bones.
117188
* @param bone

jme3-core/src/main/java/com/jme3/scene/debug/SkeletonPoints.java

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,21 @@
3333

3434
import com.jme3.animation.Bone;
3535
import com.jme3.animation.Skeleton;
36+
import com.jme3.export.InputCapsule;
37+
import com.jme3.export.JmeExporter;
38+
import com.jme3.export.JmeImporter;
39+
import com.jme3.export.OutputCapsule;
3640
import com.jme3.math.Vector3f;
3741
import com.jme3.scene.Mesh;
3842
import com.jme3.scene.VertexBuffer;
3943
import com.jme3.scene.VertexBuffer.Format;
4044
import com.jme3.scene.VertexBuffer.Type;
4145
import com.jme3.scene.VertexBuffer.Usage;
4246
import com.jme3.util.BufferUtils;
47+
import java.io.IOException;
4348

4449
import java.nio.FloatBuffer;
50+
import java.util.HashMap;
4551
import java.util.Map;
4652

4753
/**
@@ -88,6 +94,12 @@ public SkeletonPoints(Skeleton skeleton, Map<Integer, Float> boneLengths) {
8894

8995
}
9096

97+
/**
98+
* For serialization only. Do not use.
99+
*/
100+
protected SkeletonPoints() {
101+
}
102+
91103
/**
92104
* The method updates the geometry according to the positions of the bones.
93105
*/
@@ -110,4 +122,61 @@ public void updateGeometry() {
110122

111123
this.updateBound();
112124
}
125+
126+
/**
127+
* De-serializes from the specified importer, for example when loading from
128+
* a J3O file.
129+
*
130+
* @param importer the importer to use (not null)
131+
* @throws IOException from the importer
132+
*/
133+
@Override
134+
public void read(JmeImporter importer) throws IOException {
135+
super.read(importer);
136+
InputCapsule capsule = importer.getCapsule(this);
137+
138+
skeleton = (Skeleton) capsule.readSavable("skeleton", null);
139+
140+
int[] blKeys = capsule.readIntArray("blKeys", null);
141+
float[] blValues = capsule.readFloatArray("blValues", null);
142+
if (blKeys == null) {
143+
boneLengths = null;
144+
} else {
145+
assert blValues.length == blKeys.length;
146+
int numLengths = blKeys.length;
147+
boneLengths = new HashMap<>(numLengths);
148+
for (int i = 0; i < numLengths; ++i) {
149+
boneLengths.put(blKeys[i], blValues[i]);
150+
}
151+
}
152+
}
153+
154+
/**
155+
* Serializes to the specified exporter, for example when saving to a J3O
156+
* file. The current instance is unaffected.
157+
*
158+
* @param exporter the exporter to use (not null)
159+
* @throws IOException from the exporter
160+
*/
161+
@Override
162+
public void write(JmeExporter exporter) throws IOException {
163+
super.write(exporter);
164+
OutputCapsule capsule = exporter.getCapsule(this);
165+
166+
capsule.write(skeleton, "skeleton", null);
167+
168+
if (boneLengths != null) {
169+
int numLengths = boneLengths.size();
170+
int[] blKeys = new int[numLengths];
171+
float[] blValues = new float[numLengths];
172+
int i = 0;
173+
for (Map.Entry<Integer, Float> entry : boneLengths.entrySet()) {
174+
blKeys[i] = entry.getKey();
175+
blValues[i] = entry.getValue();
176+
++i;
177+
}
178+
capsule.write(blKeys, "blKeys", null);
179+
capsule.write(blValues, "blValues", null);
180+
}
181+
}
113182
}

jme3-core/src/main/java/com/jme3/scene/debug/SkeletonWire.java

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,19 @@
3737

3838
import com.jme3.animation.Bone;
3939
import com.jme3.animation.Skeleton;
40+
import com.jme3.export.InputCapsule;
41+
import com.jme3.export.JmeExporter;
42+
import com.jme3.export.JmeImporter;
43+
import com.jme3.export.OutputCapsule;
4044
import com.jme3.math.Vector3f;
4145
import com.jme3.scene.Mesh;
4246
import com.jme3.scene.VertexBuffer;
4347
import com.jme3.scene.VertexBuffer.Format;
4448
import com.jme3.scene.VertexBuffer.Type;
4549
import com.jme3.scene.VertexBuffer.Usage;
4650
import com.jme3.util.BufferUtils;
51+
import java.io.IOException;
52+
import java.util.HashMap;
4753

4854
/**
4955
* The class that displays either wires between the bones' heads if no length data is supplied and
@@ -111,6 +117,12 @@ public SkeletonWire(Skeleton skeleton, Map<Integer, Float> boneLengths) {
111117
this.updateCounts();
112118
}
113119

120+
/**
121+
* For serialization only. Do not use.
122+
*/
123+
protected SkeletonWire() {
124+
}
125+
114126
/**
115127
* This method updates the geometry according to the positions of the bones.
116128
*/
@@ -134,6 +146,65 @@ public void updateGeometry() {
134146
this.updateBound();
135147
}
136148

149+
/**
150+
* De-serializes from the specified importer, for example when loading from
151+
* a J3O file.
152+
*
153+
* @param importer the importer to use (not null)
154+
* @throws IOException from the importer
155+
*/
156+
@Override
157+
public void read(JmeImporter importer) throws IOException {
158+
super.read(importer);
159+
InputCapsule capsule = importer.getCapsule(this);
160+
161+
numConnections = capsule.readInt("numConnections", 1);
162+
skeleton = (Skeleton) capsule.readSavable("skeleton", null);
163+
164+
int[] blKeys = capsule.readIntArray("blKeys", null);
165+
float[] blValues = capsule.readFloatArray("blValues", null);
166+
if (blKeys == null) {
167+
boneLengths = null;
168+
} else {
169+
assert blValues.length == blKeys.length;
170+
int numLengths = blKeys.length;
171+
boneLengths = new HashMap<>(numLengths);
172+
for (int i = 0; i < numLengths; ++i) {
173+
boneLengths.put(blKeys[i], blValues[i]);
174+
}
175+
}
176+
}
177+
178+
/**
179+
* Serializes to the specified exporter, for example when saving to a J3O
180+
* file. The current instance is unaffected.
181+
*
182+
* @param exporter the exporter to use (not null)
183+
* @throws IOException from the exporter
184+
*/
185+
@Override
186+
public void write(JmeExporter exporter) throws IOException {
187+
super.write(exporter);
188+
OutputCapsule capsule = exporter.getCapsule(this);
189+
190+
capsule.write(numConnections, "numConnections", 1);
191+
capsule.write(skeleton, "skeleton", null);
192+
193+
if (boneLengths != null) {
194+
int numLengths = boneLengths.size();
195+
int[] blKeys = new int[numLengths];
196+
float[] blValues = new float[numLengths];
197+
int i = 0;
198+
for (Map.Entry<Integer, Float> entry : boneLengths.entrySet()) {
199+
blKeys[i] = entry.getKey();
200+
blValues[i] = entry.getValue();
201+
++i;
202+
}
203+
capsule.write(blKeys, "blKeys", null);
204+
capsule.write(blValues, "blValues", null);
205+
}
206+
}
207+
137208
/**
138209
* This method counts the connections between bones.
139210
* @param bone

jme3-core/src/main/java/com/jme3/scene/debug/custom/ArmatureInterJointsWire.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ public ArmatureInterJointsWire(Vector3f start, Vector3f[] ends) {
5454
updateGeometry(start, ends);
5555
}
5656

57+
/**
58+
* For serialization only. Do not use.
59+
*/
60+
protected ArmatureInterJointsWire() {
61+
}
62+
5763
protected void updateGeometry(Vector3f start, Vector3f[] ends) {
5864
float[] pos = new float[ends.length * 3 + 3];
5965
pos[0] = start.x;

0 commit comments

Comments
 (0)