平滑OBB框的渲染

This commit is contained in:
Atsuishio 2025-06-16 01:02:57 +08:00 committed by Light_Quanta
parent 22fadafe08
commit 4498b71573
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
4 changed files with 17 additions and 9 deletions

View file

@ -2,6 +2,7 @@ package com.atsuishio.superbwarfare.client.renderer.special;
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
import com.atsuishio.superbwarfare.tools.OBB;
import com.atsuishio.superbwarfare.tools.VectorTool;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import net.minecraft.client.renderer.LevelRenderer;
@ -18,12 +19,18 @@ public class OBBRenderer {
public static final OBBRenderer INSTANCE = new OBBRenderer();
public void render(VehicleEntity entity, List<OBB> obbList, PoseStack poseStack, VertexConsumer buffer, float red, float green, float blue, float alpha) {
public void render(VehicleEntity entity, List<OBB> obbList, PoseStack poseStack, VertexConsumer buffer, float red, float green, float blue, float alpha, float pPartialTicks) {
Vec3 position = entity.position();
for (OBB obb : obbList) {
Vector3f center = obb.center();
Vector3f halfExtents = obb.extents();
Quaternionf rotation = obb.rotation();
Quaternionf rotation;
if (obb.turret()) {
rotation = VectorTool.combineRotationsTurret(pPartialTicks, entity);
} else {
rotation = VectorTool.combineRotations(pPartialTicks, entity);
}
renderOBB(
poseStack, buffer,
(float) (center.x() - position.x()), (float) (center.y() - position.y()), (float) (center.z() - position.z()),

View file

@ -93,8 +93,8 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
public Yx100Entity(EntityType<Yx100Entity> type, Level world) {
super(type, world);
this.obb = new OBB(this.position().toVector3f(), new Vector3f(2.53125f, 1.0625f, 4.75f), new Quaternionf());
this.obbTurret = new OBB(this.position().toVector3f(), new Vector3f(2, 1, 2), new Quaternionf());
this.obb = new OBB(this.position().toVector3f(), new Vector3f(2.53125f, 1.0625f, 4.75f), new Quaternionf(), false);
this.obbTurret = new OBB(this.position().toVector3f(), new Vector3f(2.375f, 0.5625f, 3f), new Quaternionf(), true);
}
@Override
@ -1307,7 +1307,7 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
this.obb.setRotation(VectorTool.combineRotations(1, this));
Matrix4f transformT = getTurretTransform(1);
Vector4f worldPositionT = transformPosition(transformT, 0, 1, 0);
Vector4f worldPositionT = transformPosition(transformT, 0, 0.5625f, -0.1875f);
this.obbTurret.center().set(new Vector3f(worldPositionT.x, worldPositionT.y, worldPositionT.z));
this.obbTurret.setRotation(VectorTool.combineRotationsTurret(1, this));
}

View file

@ -5,6 +5,7 @@ import com.atsuishio.superbwarfare.entity.OBBEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.EntityRenderDispatcher;
import net.minecraft.world.entity.Entity;
import org.spongepowered.asm.mixin.Mixin;
@ -19,7 +20,7 @@ public class EntityRenderDispatcherMixin {
at = @At("RETURN"))
private static void renderHitbox(PoseStack poseStack, VertexConsumer buffer, Entity p_entity, float red, float green, float blue, float alpha, CallbackInfo ci) {
if (p_entity instanceof OBBEntity obbEntity && p_entity instanceof VehicleEntity vehicle) {
OBBRenderer.INSTANCE.render(vehicle, obbEntity.getOBBs(), poseStack, buffer, 0, 1, 0, 1);
OBBRenderer.INSTANCE.render(vehicle, obbEntity.getOBBs(), poseStack, buffer, 0, 1, 0, 1, Minecraft.getInstance().getTimer().getRealtimeDeltaTicks());
}
}
}

View file

@ -16,7 +16,7 @@ import java.util.Optional;
* @param extents 三个轴向上的半长
* @param rotation 旋转
*/
public record OBB(Vector3f center, Vector3f extents, Quaternionf rotation) {
public record OBB(Vector3f center, Vector3f extents, Quaternionf rotation, boolean turret) {
public void setCenter(Vector3f center) {
this.center.set(center);
@ -214,12 +214,12 @@ public record OBB(Vector3f center, Vector3f extents, Quaternionf rotation) {
public OBB inflate(float amount) {
Vector3f newExtents = new Vector3f(extents).add(amount, amount, amount);
return new OBB(center, newExtents, rotation);
return new OBB(center, newExtents, rotation, false);
}
public OBB inflate(float x, float y, float z) {
Vector3f newExtents = new Vector3f(extents).add(x, y, z);
return new OBB(center, newExtents, rotation);
return new OBB(center, newExtents, rotation, false);
}
/**