From 7064a0b63b0be01c4e2d7dac2c725664fb886bb8 Mon Sep 17 00:00:00 2001 From: vinceh121 Date: Sun, 24 Sep 2023 04:30:48 +0200 Subject: [PATCH] feat: children models --- android/assets/machinegunGuntowers.json | 27 +++++++++++++- .../wanderer/entity/DisplayModel.java | 35 +++++++++++++++++-- .../guntower/GuntowerAiController.java | 1 - 3 files changed, 58 insertions(+), 5 deletions(-) diff --git a/android/assets/machinegunGuntowers.json b/android/assets/machinegunGuntowers.json index 62f4cca..1a8da3b 100644 --- a/android/assets/machinegunGuntowers.json +++ b/android/assets/machinegunGuntowers.json @@ -251,7 +251,32 @@ 1.0, 1.0 ] - } + }, + "children": [ + { + "displayModel": "orig/j_guntower01.n/waffe.obj", + "displayTexture": "orig/lib/textures/j_guntower2j_guntower_alpha.ktx", + "animationChannel": "barrelSpin", + "relativeTransform": { + "translation": [ + 0.0, + 3, + 0.0 + ], + "rotation": [ + 0.0, + 0.0, + 0.0, + 1.0 + ], + "scale": [ + 1.0, + 1.0, + 1.0 + ] + } + } + ] } ] } diff --git a/core/src/me/vinceh121/wanderer/entity/DisplayModel.java b/core/src/me/vinceh121/wanderer/entity/DisplayModel.java index 88b877a..a6e6dc4 100644 --- a/core/src/me/vinceh121/wanderer/entity/DisplayModel.java +++ b/core/src/me/vinceh121/wanderer/entity/DisplayModel.java @@ -12,6 +12,7 @@ import com.badlogic.gdx.graphics.g3d.ModelInstance; import com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute; import com.badlogic.gdx.math.Matrix4; +import com.badlogic.gdx.utils.Array; import com.fasterxml.jackson.annotation.JsonIgnore; import me.vinceh121.wanderer.WandererConstants; @@ -24,6 +25,7 @@ public class DisplayModel { * This model's transform relative to the entity's */ private final Matrix4 relativeTransform = new Matrix4(); + private final Array children = new Array<>(); @JsonIgnore private final Matrix4 absoluteTransform = new Matrix4(); private final List textureAttributes = new ArrayList<>(); @@ -52,9 +54,17 @@ public DisplayModel(final DisplayModel from) { this.setDisplayTexture(from.getDisplayTexture()); this.setCacheDisplayModel(from.getCacheDisplayModel()); this.setAnimationChannel(from.getAnimationChannel()); + + for (DisplayModel fromChild : from.getChildren()) { + this.children.add(new DisplayModel(fromChild)); + } } public void render(final ModelBatch batch, final Environment env) { + for (DisplayModel child : this.children) { + child.render(batch, env); + } + if (this.displayModel == null) { return; } @@ -78,6 +88,7 @@ public void render(final ModelBatch batch, final Environment env) { public void loadDisplayModel() { final Model model = WandererConstants.ASSET_MANAGER.get(this.getDisplayModel(), Model.class); final ModelInstance instance = new ModelInstance(model); + if (this.displayTexture != null) { final Texture texture = WandererConstants.ASSET_MANAGER.get(this.displayTexture, Texture.class); texture.setFilter(TextureFilter.MipMapLinearLinear, TextureFilter.Linear); @@ -85,8 +96,13 @@ public void loadDisplayModel() { instance.materials.get(0).set(TextureAttribute.createDiffuse(texture)); instance.materials.get(0).set(this.textureAttributes); // this is called set but it's more like add } + this.setCacheDisplayModel(instance); this.getCacheDisplayModel().transform = this.absoluteTransform; + + for (DisplayModel child : this.children) { + child.loadDisplayModel(); + } } public void updateTransform(final Matrix4 entityTrans) { @@ -97,6 +113,19 @@ public void updateTransform(final Matrix4 entityTrans) { if (this.cacheDisplayModel != null) { this.cacheDisplayModel.transform = this.absoluteTransform; } + + for (DisplayModel child : this.children) { + child.updateTransform(this.absoluteTransform); + } + } + + public Array getChildren() { + return this.children; + } + + public void setChildren(Array children) { + this.children.clear(); + this.children.addAll(children); } public String getDisplayModel() { @@ -169,8 +198,8 @@ public Attribute removeTextureAttribute(final int index) { @Override public String toString() { - return "DisplayModel [relativeTransform=" + this.relativeTransform + ", absoluteTransform=" + this.absoluteTransform - + ", displayModel=" + this.displayModel + ", displayTexture=" + this.displayTexture + ", animationChannel=" - + this.animationChannel + "]"; + return "DisplayModel [relativeTransform=" + this.relativeTransform + ", absoluteTransform=" + + this.absoluteTransform + ", displayModel=" + this.displayModel + ", displayTexture=" + + this.displayTexture + ", animationChannel=" + this.animationChannel + "]"; } } diff --git a/core/src/me/vinceh121/wanderer/guntower/GuntowerAiController.java b/core/src/me/vinceh121/wanderer/guntower/GuntowerAiController.java index 09bf7e2..ed86c09 100644 --- a/core/src/me/vinceh121/wanderer/guntower/GuntowerAiController.java +++ b/core/src/me/vinceh121/wanderer/guntower/GuntowerAiController.java @@ -43,7 +43,6 @@ public void tick(float delta) { .nor(); final Vector3 newDir = this.target.getLookDirection().slerp(closestDir, this.turnSpeed * delta); -// Vector3 newDir = closestDir.cpy(); newDir.rotateRad(Vector3.X, MathUtils.HALF_PI); final float polar = MathUtilsW.getSphericalPolar(newDir.z);