|
8 | 8 | import static com.ss.rlib.util.ClassUtils.unsafeCast; |
9 | 9 | import static com.ss.rlib.util.ObjectUtils.notNull; |
10 | 10 | import static javafx.collections.FXCollections.observableArrayList; |
11 | | - |
12 | 11 | import com.jme3.asset.AssetManager; |
13 | 12 | import com.jme3.asset.MaterialKey; |
14 | 13 | import com.jme3.asset.ModelKey; |
15 | 14 | import com.jme3.audio.AudioNode; |
| 15 | +import com.jme3.bounding.BoundingBox; |
| 16 | +import com.jme3.bounding.BoundingSphere; |
| 17 | +import com.jme3.bounding.BoundingVolume; |
| 18 | +import com.jme3.bullet.control.PhysicsControl; |
16 | 19 | import com.jme3.export.binary.BinaryExporter; |
17 | 20 | import com.jme3.light.DirectionalLight; |
18 | 21 | import com.jme3.light.Light; |
19 | 22 | import com.jme3.light.PointLight; |
20 | 23 | import com.jme3.light.SpotLight; |
21 | 24 | import com.jme3.material.Material; |
| 25 | +import com.jme3.math.Quaternion; |
22 | 26 | import com.jme3.math.Vector3f; |
23 | 27 | import com.jme3.renderer.Camera; |
24 | 28 | import com.jme3.scene.AssetLinkNode; |
|
44 | 48 | import com.ss.editor.model.scene.WrapperNode; |
45 | 49 | import com.ss.editor.model.undo.editor.ChangeConsumer; |
46 | 50 | import com.ss.editor.model.undo.editor.ModelChangeConsumer; |
| 51 | +import com.ss.editor.model.undo.impl.AddChildOperation; |
47 | 52 | import com.ss.editor.part3d.editor.impl.Stats3DPart; |
48 | 53 | import com.ss.editor.part3d.editor.impl.scene.AbstractSceneEditor3DPart; |
49 | 54 | import com.ss.editor.plugin.api.RenderFilterExtension; |
|
58 | 63 | import com.ss.editor.ui.control.model.ModelPropertyEditor; |
59 | 64 | import com.ss.editor.ui.control.property.operation.PropertyOperation; |
60 | 65 | import com.ss.editor.ui.control.tree.action.impl.multi.RemoveElementsAction; |
61 | | -import com.ss.editor.model.undo.impl.AddChildOperation; |
62 | 66 | import com.ss.editor.ui.control.tree.node.TreeNode; |
63 | 67 | import com.ss.editor.ui.css.CssClasses; |
64 | 68 | import com.ss.editor.ui.event.impl.FileChangedEvent; |
65 | 69 | import com.ss.editor.ui.util.DynamicIconSupport; |
66 | 70 | import com.ss.editor.ui.util.UiUtils; |
| 71 | +import com.ss.editor.util.ControlUtils; |
67 | 72 | import com.ss.editor.util.*; |
68 | 73 | import com.ss.rlib.ui.util.FXUtils; |
69 | 74 | import com.ss.rlib.util.FileUtils; |
@@ -1317,6 +1322,36 @@ private void addNewModel(@NotNull final DragEvent dragEvent, @NotNull final Path |
1317 | 1322 | camera.getHeight() - (float) areaPoint.getY()); |
1318 | 1323 | final Vector3f result = local.nextVector(scenePoint) |
1319 | 1324 | .subtractLocal(parent.getWorldTranslation()); |
| 1325 | + |
| 1326 | + final boolean isPhysics = NodeUtils.children(loadedModel) |
| 1327 | + .flatMap(ControlUtils::controls) |
| 1328 | + .anyMatch(PhysicsControl.class::isInstance); |
| 1329 | + |
| 1330 | + if (isPhysics) { |
| 1331 | + |
| 1332 | + NodeUtils.updateWorldBound(loadedModel); |
| 1333 | + |
| 1334 | + final BoundingVolume worldBound = loadedModel.getWorldBound(); |
| 1335 | + |
| 1336 | + float height = 0; |
| 1337 | + |
| 1338 | + if (worldBound instanceof BoundingBox) { |
| 1339 | + height = ((BoundingBox) worldBound).getYExtent(); |
| 1340 | + height = Math.min(((BoundingBox) worldBound).getXExtent(), height); |
| 1341 | + height = Math.min(((BoundingBox) worldBound).getZExtent(), height); |
| 1342 | + } else if (worldBound instanceof BoundingSphere) { |
| 1343 | + height = ((BoundingSphere) worldBound).getRadius(); |
| 1344 | + } |
| 1345 | + |
| 1346 | + height /= 2F; |
| 1347 | + |
| 1348 | + final Quaternion localRotation = assetLinkNode.getLocalRotation(); |
| 1349 | + final Vector3f up = GeomUtils.getUp(localRotation, local.nextVector()); |
| 1350 | + up.multLocal(height); |
| 1351 | + |
| 1352 | + result.addLocal(up); |
| 1353 | + } |
| 1354 | + |
1320 | 1355 |
|
1321 | 1356 | assetLinkNode.setLocalTranslation(result); |
1322 | 1357 |
|
|
0 commit comments