private float findClosestIndex(Color color) { int best = 0; float minDist = Float.MAX_VALUE; for (int i = 0; i < colors.size(); i++) { Color other = colors.get(i); float dr = other.rf() - color.rf(); float dg = other.gf() - color.gf(); float db = other.bf() - color.bf(); // there are certainly smarter ways to measure color distance, // but Euclidean distance is good enough for the purpose float dist = dr * dr + dg * dg + db * db; if (dist < minDist) { minDist = dist; best = i; } } float max = colors.size() - 1; return best / max; }
public Vector3f toVector3f() { return new Vector3f(rf(), gf(), bf()); }
public Vector4f toVector4f() { return new Vector4f(rf(), gf(), bf(), af()); }
public MeshBuilder addColor(Color c1, Color... colors) { meshData.getColors().add(c1.rf()); meshData.getColors().add(c1.gf()); meshData.getColors().add(c1.bf()); meshData.getColors().add(c1.af()); for (Color c : colors) { meshData.getColors().add(c.rf()); meshData.getColors().add(c.gf()); meshData.getColors().add(c.bf()); meshData.getColors().add(c.af()); } return this; }
@Override public void renderOverlay() { if (entityToRegionOutlineMap.isEmpty()) { return; // skip everything if there is nothing to do to avoid possibly costly draw mode changes } glDisable(GL_DEPTH_TEST); glLineWidth(2); Vector3f cameraPosition = worldRenderer.getActiveCamera().getPosition(); FloatBuffer tempMatrixBuffer44 = BufferUtils.createFloatBuffer(16); FloatBuffer tempMatrixBuffer33 = BufferUtils.createFloatBuffer(12); material.setFloat("sunlight", 1.0f, true); material.setFloat("blockLight", 1.0f, true); material.setMatrix4("projectionMatrix", worldRenderer.getActiveCamera().getProjectionMatrix()); Vector3f worldPos = new Vector3f(); Vector3f worldPositionCameraSpace = new Vector3f(); worldPositionCameraSpace.sub(worldPos, cameraPosition); Matrix4f matrixCameraSpace = new Matrix4f(new Quat4f(0, 0, 0, 1), worldPositionCameraSpace, 1.0f); Matrix4f modelViewMatrix = MatrixUtils.calcModelViewMatrix(worldRenderer.getActiveCamera().getViewMatrix(), matrixCameraSpace); MatrixUtils.matrixToFloatBuffer(modelViewMatrix, tempMatrixBuffer44); material.setMatrix4("worldViewMatrix", tempMatrixBuffer44, true); MatrixUtils.matrixToFloatBuffer(MatrixUtils.calcNormalMatrix(modelViewMatrix), tempMatrixBuffer33); material.setMatrix3("normalMatrix", tempMatrixBuffer33, true); for (RegionOutlineComponent regionOutline: entityToRegionOutlineMap.values()) { material.setFloat3("colorOffset", regionOutline.color.rf(), regionOutline.color.gf(), regionOutline.color.bf(), true); drawRegionOutline(regionOutline); } glEnable(GL_DEPTH_TEST); }
skeletalMesh.material.setFloat("sunlight", 1.0f, true); skeletalMesh.material.setFloat("blockLight", 1.0f, true); skeletalMesh.material.setFloat3("colorOffset", skeletalMesh.color.rf(), skeletalMesh.color.gf(), skeletalMesh.color.bf(), true);
material.setMatrix3("normalMatrix", tempMatrixBuffer33, true); material.setFloat3("colorOffset", meshComp.color.rf(), meshComp.color.gf(), meshComp.color.bf(), true); material.setFloat("sunlight", worldRenderer.getMainLightIntensityAt(worldPos), true); material.setFloat("blockLight", Math.max(worldRenderer.getBlockLightIntensityAt(worldPos), meshComp.selfLuminance), true);
textureMat.setFloat4("color", color.rf(), color.gf(), color.bf(), color.af() * alpha); textureMat.bindTextures(); mesh.render();