SheetedDecalTextureGenerator.java

com.mojang.blaze3d.vertex.SheetedDecalTextureGenerator

信息

  • 全限定名:com.mojang.blaze3d.vertex.SheetedDecalTextureGenerator
  • 类型:public class
  • 包:com.mojang.blaze3d.vertex
  • 源码路径:src/main/java/com/mojang/blaze3d/vertex/SheetedDecalTextureGenerator.java
  • 起始行号:L11
  • 实现:VertexConsumer
  • 职责:

    TODO

字段/常量

  • delegate

    • 类型: VertexConsumer
    • 修饰符: private final
    • 源码定位: L12
    • 说明:

      TODO

  • cameraInversePose

    • 类型: Matrix4f
    • 修饰符: private final
    • 源码定位: L13
    • 说明:

      TODO

  • normalInversePose

    • 类型: Matrix3f
    • 修饰符: private final
    • 源码定位: L14
    • 说明:

      TODO

  • textureScale

    • 类型: float
    • 修饰符: private final
    • 源码定位: L15
    • 说明:

      TODO

  • worldPos

    • 类型: Vector3f
    • 修饰符: private final
    • 源码定位: L16
    • 说明:

      TODO

  • normal

    • 类型: Vector3f
    • 修饰符: private final
    • 源码定位: L17
    • 说明:

      TODO

  • x

    • 类型: float
    • 修饰符: private
    • 源码定位: L18
    • 说明:

      TODO

  • y

    • 类型: float
    • 修饰符: private
    • 源码定位: L19
    • 说明:

      TODO

  • z

    • 类型: float
    • 修饰符: private
    • 源码定位: L20
    • 说明:

      TODO

内部类/嵌套类型

构造器

public SheetedDecalTextureGenerator(VertexConsumer delegate, PoseStack.Pose cameraPose, float textureScale) @ L22

  • 构造器名:SheetedDecalTextureGenerator
  • 源码定位:L22
  • 修饰符:public

参数:

  • delegate: VertexConsumer
  • cameraPose: PoseStack.Pose
  • textureScale: float

说明:

TODO

方法

下面的方法块按源码顺序生成。

public VertexConsumer addVertex(float x, float y, float z) @ L29

  • 方法名:addVertex
  • 源码定位:L29
  • 返回类型:VertexConsumer
  • 修饰符:public

参数:

  • x: float
  • y: float
  • z: float

说明:

TODO

public VertexConsumer setColor(int r, int g, int b, int a) @ L38

  • 方法名:setColor
  • 源码定位:L38
  • 返回类型:VertexConsumer
  • 修饰符:public

参数:

  • r: int
  • g: int
  • b: int
  • a: int

说明:

TODO

public VertexConsumer setColor(int color) @ L44

  • 方法名:setColor
  • 源码定位:L44
  • 返回类型:VertexConsumer
  • 修饰符:public

参数:

  • color: int

说明:

TODO

public VertexConsumer setUv(float u, float v) @ L50

  • 方法名:setUv
  • 源码定位:L50
  • 返回类型:VertexConsumer
  • 修饰符:public

参数:

  • u: float
  • v: float

说明:

TODO

public VertexConsumer setUv1(int u, int v) @ L55

  • 方法名:setUv1
  • 源码定位:L55
  • 返回类型:VertexConsumer
  • 修饰符:public

参数:

  • u: int
  • v: int

说明:

TODO

public VertexConsumer setUv2(int u, int v) @ L61

  • 方法名:setUv2
  • 源码定位:L61
  • 返回类型:VertexConsumer
  • 修饰符:public

参数:

  • u: int
  • v: int

说明:

TODO

public VertexConsumer setNormal(float x, float y, float z) @ L67

  • 方法名:setNormal
  • 源码定位:L67
  • 返回类型:VertexConsumer
  • 修饰符:public

参数:

  • x: float
  • y: float
  • z: float

说明:

TODO

public VertexConsumer setLineWidth(float width) @ L80

  • 方法名:setLineWidth
  • 源码定位:L80
  • 返回类型:VertexConsumer
  • 修饰符:public

参数:

  • width: float

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class SheetedDecalTextureGenerator implements VertexConsumer {
    private final VertexConsumer delegate;
    private final Matrix4f cameraInversePose;
    private final Matrix3f normalInversePose;
    private final float textureScale;
    private final Vector3f worldPos = new Vector3f();
    private final Vector3f normal = new Vector3f();
    private float x;
    private float y;
    private float z;
 
    public SheetedDecalTextureGenerator(VertexConsumer delegate, PoseStack.Pose cameraPose, float textureScale) {
        this.delegate = delegate;
        this.cameraInversePose = new Matrix4f(cameraPose.pose()).invert();
        this.normalInversePose = new Matrix3f(cameraPose.normal()).invert();
        this.textureScale = textureScale;
    }
 
    @Override
    public VertexConsumer addVertex(float x, float y, float z) {
        this.x = x;
        this.y = y;
        this.z = z;
        this.delegate.addVertex(x, y, z);
        return this;
    }
 
    @Override
    public VertexConsumer setColor(int r, int g, int b, int a) {
        this.delegate.setColor(-1);
        return this;
    }
 
    @Override
    public VertexConsumer setColor(int color) {
        this.delegate.setColor(-1);
        return this;
    }
 
    @Override
    public VertexConsumer setUv(float u, float v) {
        return this;
    }
 
    @Override
    public VertexConsumer setUv1(int u, int v) {
        this.delegate.setUv1(u, v);
        return this;
    }
 
    @Override
    public VertexConsumer setUv2(int u, int v) {
        this.delegate.setUv2(u, v);
        return this;
    }
 
    @Override
    public VertexConsumer setNormal(float x, float y, float z) {
        this.delegate.setNormal(x, y, z);
        Vector3f normal = this.normalInversePose.transform(x, y, z, this.normal);
        Direction direction = Direction.getApproximateNearest(normal.x(), normal.y(), normal.z());
        Vector3f worldPos = this.cameraInversePose.transformPosition(this.x, this.y, this.z, this.worldPos);
        worldPos.rotateY((float) Math.PI);
        worldPos.rotateX((float) (-Math.PI / 2));
        worldPos.rotate(direction.getRotation());
        this.delegate.setUv(-worldPos.x() * this.textureScale, -worldPos.y() * this.textureScale);
        return this;
    }
 
    @Override
    public VertexConsumer setLineWidth(float width) {
        this.delegate.setLineWidth(width);
        return this;
    }
}

引用的其他类

  • PoseStack

    • 引用位置: 参数
  • VertexConsumer

    • 引用位置: 参数/字段/实现/返回值
  • Direction

    • 引用位置: 方法调用
    • 关联成员: Direction.getApproximateNearest()