8000 Merge pull request #644 from neph1/fix_infinite_scale_error · jMonkeyEngine/sdk@eaf2e3d · GitHub
[go: up one dir, main page]

Skip to content

Commit eaf2e3d

Browse files
authored
Merge pull request #644 from neph1/fix_infinite_scale_error
don't allow bounding scale for marker to be too large
2 parents 09279df + 0aac058 commit eaf2e3d

File tree

1 file changed

+42
-30
lines changed

1 file changed

+42
-30
lines changed

jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneEditTool.java

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
/*
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.
424
*/
525
package com.jme3.gde.scenecomposer;
626

@@ -37,8 +57,6 @@
3757
import com.jme3.util.TempVars;
3858
import java.nio.FloatBuffer;
3959
import java.nio.ShortBuffer;
40-
import java.util.Iterator;
41-
import java.util.concurrent.Callable;
4260
import org.openide.loaders.DataObject;
4361
import org.openide.util.Lookup;
4462

@@ -85,7 +103,8 @@ protected enum AxisMarkerPickType {
85103
* @param toolNode parent node that the marker will attach to
86104
* @param onTopToolNode the node displayed on top of the scene
87105
* @param selectedSpatial the selected spatial
88-
* @param toolController the toolController {@link SceneComposerToolController }
106+
* @param toolController the toolController {@link SceneComposerToolController
107+
* }
89108
*/
90109
public void activate(AssetManager manager, Node toolNode, Node onTopToolNode, Spatial selectedSpatial, SceneComposerToolController toolController) {
91110
this.manager = manager;
@@ -129,36 +148,31 @@ public void setOverrideCameraControl(boolean overrideCameraControl) {
129148

130149
/**
131150
* 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.
134154
*/
135155
public void updateToolsTransformation() {
136156

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;
144160
});
145161
}
146162

147163
public void doUpdateToolsTransformation() {
148164
if (toolController.getSelectedSpatial() != null) {
149165
axisMarker.setLocalTranslation(toolController.getSelectedSpatial().getWorldTranslation());
150166
switch (transformType) {
151-
case local:
167+
case local ->
152168
axisMarker.setLocalRotation(toolController.getSelectedSpatial().getWorldRotation());
153-
break;
154-
case global:
169+
case global ->
155170
axisMarker.setLocalRotation(Quaternion.IDENTITY);
156-
break;
157-
case camera:
171+
case camera -> {
158172
if (camera != null) {
159173
axisMarker.setLocalRotation(camera.getRotation());
160174
}
161-
break;
175+
}
162176
}
163177
setAxisMarkerScale(toolController.getSelectedSpatial());
164178
} else {
@@ -173,10 +187,12 @@ public void doUpdateToolsTransformation() {
173187
*/
174188
private void setAxisMarkerScale(Spatial selected) {
175189
if (selected != null) {
176-
if (selected.getWorldBound() instanceof BoundingBox) {
177-
BoundingBox bbox = (BoundingBox) selected.getWorldBound();
190+
if (selected.getWorldBound() instanceof BoundingBox bbox) {
178191
float smallest = Math.min(Math.min(bbox.getXExtent(), bbox.getYExtent()), bbox.getZExtent());
179192
float scale = Math.max(1, smallest / 2f);
193+
if (scale > 100) {
194+
scale = 1;
195+
}
180196
axisMarker.setLocalScale(scale);
181197
}
182198
} else {
@@ -321,12 +337,8 @@ private static CollisionResult doPick(Camera cam, Vector2f mouseLoc, Node node,
321337
if (exclude == null) {
322338
result = results.getClosestCollision();
323339
} 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)) {
330342
return cr;
331343
}
332344
}
@@ -495,7 +507,7 @@ protected Node createAxisMarker() {
495507
redMat.setColor("Color", ColorRGBA.Red);
496508
redMat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off);
497509
redMat.getAdditionalRenderState().setLineWidth(2f);
498-
510+
499511
greenMat = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
500512
greenMat.getAdditionalRenderState().setWireframe(false);
501513
greenMat.setColor("Color", ColorRGBA.Green);
@@ -535,7 +547,7 @@ protected Node createAxisMarker() {
535547
orangeMat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
536548
orangeMat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off);
537549
orangeMat.getAdditionalRenderState().setLineWidth(2f);
538-
550+
539551
Node axis = new Node();
540552

541553
// create arrows

0 commit comments

Comments
 (0)
0