SDK : added convenient way to type Vector3f, Vector2f, Quaternions, Emitter shapes. Thanks to kwando

see http://jmonkeyengine.org/groups/jmonkeyplatform/forum/topic/small-change-to-the-properties-pane-in-scenecomposer/?#post-196107

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9935 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
rem..om 12 years ago
parent 76dcabae66
commit 89d1f64739
  1. 2
      sdk/jme3-core/src/com/jme3/gde/core/properties/EmitterShapePropertyEditor.java
  2. 45
      sdk/jme3-core/src/com/jme3/gde/core/properties/QuaternionPropertyEditor.java
  3. 31
      sdk/jme3-core/src/com/jme3/gde/core/properties/Vector2fPropertyEditor.java
  4. 31
      sdk/jme3-core/src/com/jme3/gde/core/properties/Vector3fPropertyEditor.java

@ -123,7 +123,7 @@ public class EmitterShapePropertyEditor implements PropertyEditor {
public void setAsText(String text) throws IllegalArgumentException {
text = text.replace('[', ' ').trim();
text = text.replace(']', ' ').trim();
String[] strings = text.split(",");
String[] strings = text.split("\\s*(,|\\s)\\s*");
EmitterShape old=emitter;
if (strings.length == 0) {
return;

@ -73,26 +73,43 @@ public class QuaternionPropertyEditor implements PropertyEditor {
}
public String getAsText() {
float[] angles=quaternion.toAngles(new float[3]);
return "[" + (float)Math.toDegrees(angles[0]) + ", " + (float)Math.toDegrees(angles[1]) + ", " + (float)Math.toDegrees(angles[2]) + "]";
float[] angles = quaternion.toAngles(new float[3]);
return "[" + (float) Math.toDegrees(angles[0]) + ", " + (float) Math.toDegrees(angles[1]) + ", " + (float) Math.toDegrees(angles[2]) + "]";
}
public void setAsText(String text) throws IllegalArgumentException {
private void parseInto(String text, Quaternion res) throws IllegalArgumentException {
text = text.replace('[', ' ');
text = text.replace(']', ' ');
String[] values = text.split(",");
if (values.length != 3) {
throw (new IllegalArgumentException("String not correct"));
text = text.replace(']', ' ').trim();
String[] a = text.split("\\s*(,|\\s)\\s*");
if (a.length == 1) {
if (text.trim().toLowerCase().equals("nan")) {
res.set(Float.NaN, Float.NaN, Float.NaN, Float.NaN);
return;
}
float f = Float.parseFloat(text);
f = (float) Math.toRadians(f);
res.fromAngles(f, f, f);
return;
}
float[] floats = new float[3];
for (int i = 0; i < values.length; i++) {
String string = values[i];
floats[i] = (float)Math.toRadians(Float.parseFloat(string));
if (a.length == 3) {
float[] floats = new float[3];
for (int i = 0; i < a.length; i++) {
floats[i] = (float) Math.toRadians(Float.parseFloat(a[i]));
}
res.fromAngles(floats);
return;
}
Quaternion old=new Quaternion();
throw new IllegalArgumentException("String not correct");
}
public void setAsText(String text) throws IllegalArgumentException {
Quaternion old = new Quaternion();
old.set(quaternion);
quaternion.fromAngles(floats);
notifyListeners(old,quaternion);
parseInto(text, quaternion);
notifyListeners(old, quaternion);
}
public String[] getTags() {

@ -76,21 +76,32 @@ public class Vector2fPropertyEditor implements PropertyEditor {
return "[" + vector.x + ", " + vector.y + "]";
}
public void setAsText(String text) throws IllegalArgumentException {
private void parseInto(String text, Vector2f res) throws IllegalArgumentException {
text = text.replace('[', ' ');
text = text.replace(']', ' ');
String[] values = text.split(",");
if (values.length != 2) {
throw (new IllegalArgumentException("String not correct"));
text = text.replace(']', ' ').trim();
String[] a = text.split("\\s*(,|\\s)\\s*");
if (a.length == 1) {
if(text.trim().toLowerCase().equals("nan")) {
res.set(new Vector2f(Float.NaN, Float.NaN));
return;
}
float f = Float.parseFloat(text);
res.set(f, f);
return;
}
float[] floats = new float[2];
for (int i = 0; i < values.length; i++) {
String string = values[i];
floats[i] = Float.parseFloat(string);
if (a.length == 2) {
res.set(Float.parseFloat(a[0]), Float.parseFloat(a[1]));
return;
}
throw new IllegalArgumentException("String not correct");
}
public void setAsText(String text) throws IllegalArgumentException {
Vector2f old = new Vector2f();
old.set(vector);
vector.set(floats[0], floats[1]);
parseInto(text, vector);
notifyListeners(old, vector);
}

@ -76,21 +76,32 @@ public class Vector3fPropertyEditor implements PropertyEditor {
return "[" + vector.x + ", " + vector.y + ", " + vector.z + "]";
}
public void setAsText(String text) throws IllegalArgumentException {
private void parseInto(String text, Vector3f res) throws IllegalArgumentException {
text = text.replace('[', ' ');
text = text.replace(']', ' ');
String[] values = text.split(",");
if (values.length != 3) {
throw (new IllegalArgumentException("String not correct"));
text = text.replace(']', ' ').trim();
String[] a = text.split("\\s*(,|\\s)\\s*");
if (a.length == 1) {
if(text.trim().toLowerCase().equals("nan")) {
res.set(Vector3f.NAN);
return;
}
float f = Float.parseFloat(text);
res.set(f, f, f);
return;
}
float[] floats = new float[3];
for (int i = 0; i < values.length; i++) {
String string = values[i];
floats[i] = Float.parseFloat(string);
if (a.length == 3) {
res.set(Float.parseFloat(a[0]), Float.parseFloat(a[1]), Float.parseFloat(a[2]));
return;
}
throw new IllegalArgumentException("String not correct");
}
public void setAsText(String text) throws IllegalArgumentException {
Vector3f old = new Vector3f();
old.set(vector);
vector.set(floats[0], floats[1], floats[2]);
parseInto(text, vector);
notifyListeners(old, vector);
}

Loading…
Cancel
Save