1
1
/*
2
- * To change this template, choose Tools | Templates
3
- * and open the template in the editor.
2
+ * Copyright (c) 2009-2024 jMonkeyEngine All rights reserved. <p/>
3
+ * Redistribution and use in source and binary forms, with or without
4
+ * modification, are permitted provided that the following conditions are met:
5
+ *
6
+ * * Redistributions of source code must retain the above copyright notice,
7
+ * this list of conditions and the following disclaimer. <p/> * Redistributions
8
+ * in binary form must reproduce the above copyright notice, this list of
9
+ * conditions and the following disclaimer in the documentation and/or other
10
+ * materials provided with the distribution. <p/> * Neither the name of
11
+ * 'jMonkeyEngine' nor the names of its contributors may be used to endorse or
12
+ * promote products derived from this software without specific prior written
13
+ * permission. <p/> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
14
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
15
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
16
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
<
10000
/code>
18
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
22
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
23
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4
24
*/
5
25
package com .jme3 .gde .scenecomposer ;
6
26
37
57
import com .jme3 .util .TempVars ;
38
58
import java .nio .FloatBuffer ;
39
59
import java .nio .ShortBuffer ;
40
- import java .util .Iterator ;
41
- import java .util .concurrent .Callable ;
42
60
import org .openide .loaders .DataObject ;
43
61
import org .openide .util .Lookup ;
44
62
@@ -85,7 +103,8 @@ protected enum AxisMarkerPickType {
85
103
* @param toolNode parent node that the marker will attach to
86
104
* @param onTopToolNode the node displayed on top of the scene
87
105
* @param selectedSpatial the selected spatial
88
- * @param toolController the toolController {@link SceneComposerToolController }
106
+ * @param toolController the toolController {@link SceneComposerToolController
107
+ * }
89
108
*/
90
109
public void activate (AssetManager manager , Node toolNode , Node onTopToolNode , Spatial selectedSpatial , SceneComposerToolController toolController ) {
91
110
this .manager = manager ;
@@ -129,36 +148,31 @@ public void setOverrideCameraControl(boolean overrideCameraControl) {
129
148
130
149
/**
131
150
* Called when the selected spatial has been modified outside of the tool.
132
- * @TODO: why? just move the tool where the object is each frame?
133
- * Proposed Answer: Performance.
151
+ *
152
+ * @TODO: why? just move the tool where the object is each frame? Proposed
153
+ * Answer: Performance.
134
154
*/
135
155
public void updateToolsTransformation () {
136
156
137
- SceneApplication .getApplication ().enqueue (new Callable <Object >() {
138
-
139
- @ Override
140
- public Object call () throws Exception {
141
- doUpdateToolsTransformation ();
142
- return null ;
143
- }
157
+ SceneApplication .getApplication ().enqueue (() -> {
158
+ doUpdateToolsTransformation ();
159
+ return null ;
144
160
});
145
161
}
146
162
147
163
public void doUpdateToolsTransformation () {
148
164
if (toolController .getSelectedSpatial () != null ) {
149
165
axisMarker .setLocalTranslation (toolController .getSelectedSpatial ().getWorldTranslation ());
150
166
switch (transformType ) {
151
- case local :
167
+ case local ->
152
168
axisMarker .setLocalRotation (toolController .getSelectedSpatial ().getWorldRotation ());
153
- break ;
154
- case global :
169
+ case global ->
155
170
axisMarker .setLocalRotation (Quaternion .IDENTITY );
156
- break ;
157
- case camera :
171
+ case camera -> {
158
172
if (camera != null ) {
159
173
axisMarker .setLocalRotation (camera .getRotation ());
160
174
}
161
- break ;
175
+ }
162
176
}
163
177
setAxisMarkerScale (toolController .getSelectedSpatial ());
164
178
} else {
@@ -173,10 +187,12 @@ public void doUpdateToolsTransformation() {
173
187
*/
174
188
private void setAxisMarkerScale (Spatial selected ) {
175
189
if (selected != null ) {
176
- if (selected .getWorldBound () instanceof BoundingBox ) {
177
- BoundingBox bbox = (BoundingBox ) selected .getWorldBound ();
190
+ if (selected .getWorldBound () instanceof BoundingBox bbox ) {
178
191
float smallest = Math .min (Math .min (bbox .getXExtent (), bbox .getYExtent ()), bbox .getZExtent ());
179
192
float scale = Math .max (1 , smallest / 2f );
193
+ if (scale > 100 ) {
194
+ scale = 1 ;
195
+ }
180
196
axisMarker .setLocalScale (scale );
181
197
}
182
198
} else {
@@ -321,12 +337,8 @@ private static CollisionResult doPick(Camera cam, Vector2f mouseLoc, Node node,
321
337
if (exclude == null ) {
322
338
result = results .getClosestCollision ();
323
339
} else {
324
- Iterator <CollisionResult > it = results .iterator ();
325
- while (it .hasNext ()) {
326
- CollisionResult cr = it .next ();
327
- if (isExcluded (cr .getGeometry (), exclude )) {
328
- continue ;
329
- } else {
340
+ for (CollisionResult cr : results ) {
341
+ if (!isExcluded (cr .getGeometry (), exclude )) {
330
342
return cr ;
331
343
}
332
344
}
@@ -495,7 +507,7 @@ protected Node createAxisMarker() {
495
507
redMat .setColor ("Color" , ColorRGBA .Red );
496
508
redMat .getAdditionalRenderState ().setFaceCullMode (FaceCullMode .Off );
497
509
redMat .getAdditionalRenderState ().setLineWidth (2f );
498
-
510
+
499
511
greenMat = new Material (manager , "Common/MatDefs/Misc/Unshaded.j3md" );
500
512
greenMat .getAdditionalRenderState ().setWireframe (false );
501
513
greenMat .setColor ("Color" , ColorRGBA .Green );
@@ -535,7 +547,7 @@ protected Node createAxisMarker() {
535
547
orangeMat .getAdditionalRenderState ().setBlendMode (BlendMode .Alpha );
536
548
orangeMat .getAdditionalRenderState ().setFaceCullMode (FaceCullMode .Off );
537
549
orangeMat .getAdditionalRenderState ().setLineWidth (2f );
538
-
550
+
539
551
Node axis = new Node ();
540
552
541
553
// create arrows
0 commit comments