kwando
November 1, 2012, 10:07am
1
This is just a small suggestion to the parsing of the Vector3f properties (Local Scale, Local Translation etc.) in the properties pane (SDK). The proposed changes will the make the SDK a bit more user friendly and should probably not be that difficult to implement. Although I leave the impact analysis to the core guys
Right now only the input format supported is “[1.0, 1.0, 1.0]” and “1.0, 1.0, 1.0”.
Proposed additions to the parsing:
Support SPACE as number delimiter. Example: “1.0 2.0 3.4” would be Vector3f(1.0, 2.0, 3.4)
If only a single numbers is given, repeat it for the other components of the vector. Example: “1.0” would be Vector3f(1.0, 1.0, 1.0).
2 Likes
nehon
November 1, 2012, 5:33pm
2
why not.
Also I thought of being able to set NAN as it’s used in particle emitter for the default facing normal of the particles.
Right now once you have set a normal you can’t reset it to default…
Though it’s not very tied to the vector3f itself but more to this particular field…
I like your ideas, especially number 1.
This may be extended to other vector types, quaternions and maybe particle emitter shapes.
I don’t really have the time right now, but i may do this at some point.
If you are up to make a patch though, you’re very welcome.
the parsing for verctor3f occurs here
http://code.google.com/p/jmonkeyengine/source/browse/trunk/sdk/jme3-core/src/com/jme3/gde/core/properties/Vector3fPropertyEditor.java#79
in the setAsText method.
kwando
November 1, 2012, 8:49pm
3
It should™ work
[patch]
Index: sdk/jme3-core/src/com/jme3/gde/core/properties/Vector2fPropertyEditor.java
===================================================================
— sdk/jme3-core/src/com/jme3/gde/core/properties/Vector2fPropertyEditor.java (revision 9933)
+++ sdk/jme3-core/src/com/jme3/gde/core/properties/Vector2fPropertyEditor.java (working copy)
@@ -75,22 +75,33 @@
public String getAsText() {
return "[" + vector.x + ", " + vector.y + "]";
}
+
private void parseInto(String text, Vector2f res) throws IllegalArgumentException {
text = text.replace('[', ' ');<br />
text = text.replace(']', ' ').trim();<br />
String[] a = text.split("\s*(,|\s)\s*");<br />
- public void setAsText(String text) throws IllegalArgumentException {
- text = text.replace('[', ' ');
- text = text.replace(']', ' ');
- String[] values = text.split(",");
- if (values.length != 2) {
- throw (new IllegalArgumentException("String not correct"));
+ if (a.length == 1) {
+ float f = Float.parseFloat(text);
+ if (f == Float.NaN) {
+ res.set(Vector2f.NAN);
+ return;
+ }
+ res.set(f, f);
+ return;
}
- float[] floats = new float[2];
- for (int i = 0; i < values.length; i++) {
- String string = values
;
- floats = 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);
}
Index: sdk/jme3-core/src/com/jme3/gde/core/properties/Vector3fPropertyEditor.java
===================================================================
--- sdk/jme3-core/src/com/jme3/gde/core/properties/Vector3fPropertyEditor.java (revision 9933)
+++ sdk/jme3-core/src/com/jme3/gde/core/properties/Vector3fPropertyEditor.java (working copy)
@@ -75,22 +75,33 @@
public String getAsText() {
return "[" + vector.x + ", " + vector.y + ", " + vector.z + "]";
}
+
+ private void parseInto(String text, Vector3f res) throws IllegalArgumentException {
+ text = text.replace('[', ' ');
+ text = text.replace(']', ' ').trim();
+ String[] a = text.split("\s*(,|\s)\s*");
- public void setAsText(String text) throws IllegalArgumentException {
- text = text.replace('[', ' ');
- text = text.replace(']', ' ');
- String[] values = text.split(",");
- if (values.length != 3) {
- throw (new IllegalArgumentException("String not correct"));
+ if (a.length == 1) {
+ float f = Float.parseFloat(text);
+ if (f == Float.NaN) {
+ res.set(Vector3f.NAN);
+ return;
+ }
+ res.set(f, f, f);
+ return;
}
- float[] floats = new float[3];
- for (int i = 0; i < values.length; i++) {
- String string = values;
- floats = 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);
}
[/patch]
4 Likes
kwando
November 1, 2012, 8:50pm
4
Ahh, this diff looks like a mess…
Edit: the stupid html escaping code has removed characters from my split regex == BADNESS
kwando
November 1, 2012, 8:58pm
5
There should be double backslashes infront of all “s” in the spilt patterns…
nehon
November 1, 2012, 9:42pm
6
thanks i’ll look into that
nehon
November 2, 2012, 7:14am
7
That’s in last SVN
Thanks for the patch.
I also added this way to type to quaternions, and you can now input Emitter shapes with spaces (ie “sphere 0 0 0 1” will make a sphere shape centered at 0,0,0 and with a 1 unit radius).
Setekh
November 2, 2012, 9:21am
9
@kwando said:
Sweat :)
Sweet* XD u dirty monkey,
kwando
November 2, 2012, 9:34am
10
haha, you are right It is still to early over here