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);
}
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;
}
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;
}
}
}
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;
}
Aggregations