Bugfix: fixed a bug that caused NPE during vertex groups loading when

mesh block was saved without its parent.
cleanup_build_scripts
jmekaelthas 9 years ago
parent 32be69f3e6
commit be3dc06e28
  1. 43
      jme3-blender/src/main/java/com/jme3/scene/plugins/blender/meshes/MeshHelper.java

@ -286,30 +286,33 @@ public class MeshHelper extends AbstractBlenderHelper {
List<Map<String, Float>> result = new ArrayList<Map<String, Float>>(); List<Map<String, Float>> result = new ArrayList<Map<String, Float>>();
Structure parent = blenderContext.peekParent(); Structure parent = blenderContext.peekParent();
Structure defbase = (Structure) parent.getFieldValue("defbase"); if(parent != null) {
List<String> groupNames = new ArrayList<String>(); // the mesh might be saved without its parent (it is then unused)
List<Structure> defs = defbase.evaluateListBase(); Structure defbase = (Structure) parent.getFieldValue("defbase");
for (Structure def : defs) { List<String> groupNames = new ArrayList<String>();
groupNames.add(def.getFieldValue("name").toString()); List<Structure> defs = defbase.evaluateListBase();
} for (Structure def : defs) {
groupNames.add(def.getFieldValue("name").toString());
}
Pointer pDvert = (Pointer) meshStructure.getFieldValue("dvert");// dvert = DeformVERTices Pointer pDvert = (Pointer) meshStructure.getFieldValue("dvert");// dvert = DeformVERTices
if (pDvert.isNotNull()) {// assigning weights and bone indices if (pDvert.isNotNull()) {// assigning weights and bone indices
List<Structure> dverts = pDvert.fetchData(); List<Structure> dverts = pDvert.fetchData();
for (Structure dvert : dverts) { for (Structure dvert : dverts) {
Map<String, Float> weightsForVertex = new HashMap<String, Float>(); Map<String, Float> weightsForVertex = new HashMap<String, Float>();
Pointer pDW = (Pointer) dvert.getFieldValue("dw"); Pointer pDW = (Pointer) dvert.getFieldValue("dw");
if (pDW.isNotNull()) { if (pDW.isNotNull()) {
List<Structure> dw = pDW.fetchData(); List<Structure> dw = pDW.fetchData();
for (Structure deformWeight : dw) { for (Structure deformWeight : dw) {
int groupIndex = ((Number) deformWeight.getFieldValue("def_nr")).intValue(); int groupIndex = ((Number) deformWeight.getFieldValue("def_nr")).intValue();
float weight = ((Number) deformWeight.getFieldValue("weight")).floatValue(); float weight = ((Number) deformWeight.getFieldValue("weight")).floatValue();
String groupName = groupNames.get(groupIndex); String groupName = groupNames.get(groupIndex);
weightsForVertex.put(groupName, weight); weightsForVertex.put(groupName, weight);
}
} }
result.add(weightsForVertex);
} }
result.add(weightsForVertex);
} }
} }
return result; return result;

Loading…
Cancel
Save