Search in sources :

Example 16 with Vector4f

use of javax.vecmath.Vector4f in project MinecraftForge by MinecraftForge.

the class ForgeHooksClient method transform.

public static void transform(org.lwjgl.util.vector.Vector3f vec, Matrix4f m) {
    Vector4f tmp = new Vector4f(vec.x, vec.y, vec.z, 1f);
    m.transform(tmp);
    if (Math.abs(tmp.w - 1f) > 1e-5)
        tmp.scale(1f / tmp.w);
    vec.set(tmp.x, tmp.y, tmp.z);
}
Also used : Vector4f(javax.vecmath.Vector4f)

Example 17 with Vector4f

use of javax.vecmath.Vector4f in project MinecraftForge by MinecraftForge.

the class TRSRTransformation method lerp.

public static Vector4f lerp(Tuple4f from, Tuple4f to, float progress) {
    Vector4f res = new Vector4f(from);
    res.interpolate(from, to, progress);
    return res;
}
Also used : Vector4f(javax.vecmath.Vector4f)

Example 18 with Vector4f

use of javax.vecmath.Vector4f in project BetterWithAddons by DaedalusGame.

the class ModelToolShardInner method putVertex.

private static void putVertex(UnpackedBakedQuad.Builder builder, VertexFormat format, Optional<TRSRTransformation> transform, EnumFacing side, int color, float x, float y, float z, float u, float v) {
    Vector4f vec = new Vector4f();
    for (int e = 0; e < format.getElementCount(); e++) {
        switch(format.getElement(e).getUsage()) {
            case POSITION:
                if (transform.isPresent()) {
                    vec.x = x;
                    vec.y = y;
                    vec.z = z;
                    vec.w = 1;
                    transform.get().getMatrix().transform(vec);
                    builder.put(e, vec.x, vec.y, vec.z, vec.w);
                } else {
                    builder.put(e, x, y, z, 1);
                }
                break;
            case COLOR:
                // red
                float r = ((color >> 16) & 0xFF) / 255f;
                // green
                float g = ((color >> 8) & 0xFF) / 255f;
                // blue
                float b = ((color >> 0) & 0xFF) / 255f;
                // alpha
                float a = ((color >> 24) & 0xFF) / 255f;
                builder.put(e, r, g, b, a);
                break;
            case UV:
                if (format.getElement(e).getIndex() == 0) {
                    builder.put(e, u, v, 0f, 1f);
                    break;
                }
            case NORMAL:
                builder.put(e, (float) side.getFrontOffsetX(), (float) side.getFrontOffsetY(), (float) side.getFrontOffsetZ(), 0f);
                break;
            default:
                builder.put(e);
                break;
        }
    }
}
Also used : Vector4f(javax.vecmath.Vector4f)

Example 19 with Vector4f

use of javax.vecmath.Vector4f in project Almura by AlmuraDev.

the class OBJBakedModel method getQuads.

@Override
public List<BakedQuad> getQuads(@Nullable final IBlockState state, @Nullable final EnumFacing side, final long rand) {
    if (this.quads == null) {
        this.quads = new LinkedList<>();
        final TRSRTransformation transformation = this.state.apply(Optional.empty()).orElse(null);
        Face particleFace = null;
        TextureAtlasSprite particleAtlasSprite = null;
        for (final Group group : this.model.getGroups()) {
            final MaterialDefinition materialDefinition = group.getMaterialDefinition().orElse(null);
            TextureAtlasSprite diffuseSprite = this.spriteOverride;
            if (diffuseSprite == null) {
                if (materialDefinition != null) {
                    if (materialDefinition.getDiffuseTexture().isPresent()) {
                        final ResourceLocation diffuseLocation = materialDefinition.getDiffuseTexture().orElse(null);
                        if (diffuseLocation != null) {
                            if (diffuseLocation.getResourcePath().endsWith(".png")) {
                                diffuseSprite = this.bakedTextureGetter.apply(new ResourceLocation(diffuseLocation.getResourceDomain(), diffuseLocation.getResourcePath().split("\\.")[0]));
                            } else {
                                diffuseSprite = this.bakedTextureGetter.apply(diffuseLocation);
                            }
                        }
                    }
                }
            }
            if (diffuseSprite == null) {
                diffuseSprite = ModelLoader.White.INSTANCE;
            }
            particleAtlasSprite = diffuseSprite;
            for (final Face face : group.getFaces()) {
                particleFace = face;
                final UnpackedBakedQuad.Builder quadBuilder = new UnpackedBakedQuad.Builder(this.format);
                quadBuilder.setContractUVs(true);
                quadBuilder.setTexture(diffuseSprite);
                VertexNormal normal = null;
                for (final VertexDefinition vertexDef : face.getVertices()) {
                    if (normal == null) {
                        normal = vertexDef.getNormal().orElse(null);
                    }
                    for (int e = 0; e < this.format.getElementCount(); e++) {
                        switch(this.format.getElement(e).getUsage()) {
                            case POSITION:
                                final Vertex vertex = vertexDef.getVertex();
                                if (transformation != null) {
                                    final Matrix4f transform = transformation.getMatrix();
                                    final Vector4f position = new Vector4f(vertex.getX(), vertex.getY(), vertex.getZ(), 1f);
                                    final Vector4f transformed = new Vector4f();
                                    transform.transform(position, transformed);
                                    quadBuilder.put(e, transformed.getX(), transformed.getY(), transformed.getZ());
                                } else {
                                    quadBuilder.put(e, vertex.getX(), vertex.getY(), vertex.getZ());
                                }
                                break;
                            case UV:
                                final float u;
                                final float v;
                                if (this.spriteOverride == null) {
                                    final VertexTextureCoordinate textureCoordinate = vertexDef.getTextureCoordinate().orElse(null);
                                    if (textureCoordinate != null) {
                                        u = textureCoordinate.getU();
                                        v = 1f - textureCoordinate.getV();
                                    } else {
                                        u = 0f;
                                        v = 1f;
                                    }
                                } else {
                                    switch(vertexDef.getIndex()) {
                                        case 1:
                                            u = 0f;
                                            v = 0f;
                                            break;
                                        case 2:
                                            u = 1f;
                                            v = 0f;
                                            break;
                                        case 3:
                                            u = 1f;
                                            v = 1f;
                                            break;
                                        case 4:
                                            u = 0f;
                                            v = 1f;
                                            break;
                                        default:
                                            u = 0f;
                                            v = 0f;
                                    }
                                }
                                quadBuilder.put(e, diffuseSprite.getInterpolatedU(u * 16f), diffuseSprite.getInterpolatedV(v * 16f));
                                break;
                            case NORMAL:
                                if (normal != null) {
                                    quadBuilder.put(e, normal.getX(), normal.getY(), normal.getZ());
                                }
                                break;
                            case COLOR:
                                quadBuilder.put(e, 1f, 1f, 1f, 1f);
                                break;
                            default:
                                quadBuilder.put(e);
                        }
                    }
                }
                if (normal != null) {
                    quadBuilder.setQuadOrientation(EnumFacing.getFacingFromVector(normal.getX(), normal.getY(), normal.getZ()));
                }
                this.quads.add(quadBuilder.build());
            }
        }
        if (particleFace != null && particleAtlasSprite != null) {
            // For now, last face = particle generation
            this.particleDiffuseSprite = this.createParticleSpriteFor(particleFace, particleAtlasSprite);
        }
    }
    return this.quads;
}
Also used : TRSRTransformation(net.minecraftforge.common.model.TRSRTransformation) Group(com.almuradev.content.model.obj.geometry.Group) Vertex(com.almuradev.content.model.obj.geometry.Vertex) UnpackedBakedQuad(net.minecraftforge.client.model.pipeline.UnpackedBakedQuad) IMixinTextureAtlasSprite(com.almuradev.content.mixin.iface.IMixinTextureAtlasSprite) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) VertexNormal(com.almuradev.content.model.obj.geometry.VertexNormal) VertexDefinition(com.almuradev.content.model.obj.geometry.VertexDefinition) VertexTextureCoordinate(com.almuradev.content.model.obj.geometry.VertexTextureCoordinate) Matrix4f(javax.vecmath.Matrix4f) Vector4f(javax.vecmath.Vector4f) MaterialDefinition(com.almuradev.content.model.obj.material.MaterialDefinition) ResourceLocation(net.minecraft.util.ResourceLocation) Face(com.almuradev.content.model.obj.geometry.Face)

Aggregations

Vector4f (javax.vecmath.Vector4f)19 Stack (com.bulletphysics.util.Stack)8 Vector3f (javax.vecmath.Vector3f)8 Matrix4f (javax.vecmath.Matrix4f)2 TRSRTransformation (net.minecraftforge.common.model.TRSRTransformation)2 IMixinTextureAtlasSprite (com.almuradev.content.mixin.iface.IMixinTextureAtlasSprite)1 Face (com.almuradev.content.model.obj.geometry.Face)1 Group (com.almuradev.content.model.obj.geometry.Group)1 Vertex (com.almuradev.content.model.obj.geometry.Vertex)1 VertexDefinition (com.almuradev.content.model.obj.geometry.VertexDefinition)1 VertexNormal (com.almuradev.content.model.obj.geometry.VertexNormal)1 VertexTextureCoordinate (com.almuradev.content.model.obj.geometry.VertexTextureCoordinate)1 MaterialDefinition (com.almuradev.content.model.obj.material.MaterialDefinition)1 StaticPlaneShape (com.bulletphysics.collision.shapes.StaticPlaneShape)1 AABB (com.bulletphysics.extras.gimpact.BoxCollision.AABB)1 Transform (com.bulletphysics.linearmath.Transform)1 Matrix3f (javax.vecmath.Matrix3f)1 BlockFaceUV (net.minecraft.client.renderer.block.model.BlockFaceUV)1 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)1 ResourceLocation (net.minecraft.util.ResourceLocation)1