public static CubeMesh operator *(Vector3 scale, CubeMesh cubeMesh) { CubeMesh res = new CubeMesh(cubeMesh); for (int i = 0; i < cubeMesh.vertices.Length; i++) { res.vertices[i] = new Vector3(res.vertices[i].x * scale.x, res.vertices[i].y * scale.y, res.vertices[i].z * scale.z); } return(res); }
public static CubeMesh operator *(float val, CubeMesh cubeMesh) { CubeMesh res = new CubeMesh(cubeMesh); for (int i = 0; i < cubeMesh.vertices.Length; i++) { res.vertices[i] *= val; } return(res); }
public static CubeMesh operator+(Vector3 offset, CubeMesh cubeMesh) { CubeMesh res = new CubeMesh(cubeMesh); for (int i = 0; i < cubeMesh.vertices.Length; i++) { res.vertices[i] += offset; } return(res); }
public CubeMesh ApplyingTransformationToEachVertex(TransformPoint transformation) { CubeMesh res = new CubeMesh(this); for (int i = 0; i < vertices.Length; i++) { res.vertices[i] = transformation(vertices[i]); } return(res); }
public static CubeMesh operator *(Vector2 scale, CubeMesh cubeMesh) { CubeMesh res = new CubeMesh(cubeMesh); for (int i = 0; i < cubeMesh.uvs.Length; i++) { res.uvs[i] = new Vector2(res.uvs[i].x * scale.x, res.uvs[i].y * scale.y); } return(res); }
public CubeMesh(CubeMesh from) { vertices = new Vector3[from.vertices.Length]; uvs = new Vector2[from.uvs.Length]; for (int i = 0; i < from.vertices.Length; i++) { vertices[i] = from.vertices[i]; } for (int i = 0; i < from.uvs.Length; i++) { uvs[i] = from.uvs[i]; } }
public Blocks.RenderTriangle[] ToRenderTriangles(BlockData.BlockRotation blockRotation = BlockData.BlockRotation.Degrees0, int state = 0) { CubeMesh res = new CubeMesh(); // -0.5 to 0.5 -> 0 to 1 //res = res + new Vector3(0.5f, 0.5f, 0.5f); Vector3 fromPos; if (fromVars != null && fromVars.Length == 3) { float fromValX = ParseString(fromVars[0]).GetValue(state); float fromValY = ParseString(fromVars[1]).GetValue(state); float fromValZ = ParseString(fromVars[2]).GetValue(state); fromPos = new Vector3(fromValX, fromValY, fromValZ); } else { fromPos = new Vector3((float)from[0], (float)from[1], (float)from[2]); } Vector3 toPos; if (toVars != null && toVars.Length == 3) { float toValX = ParseString(toVars[0]).GetValue(state); float toValY = ParseString(toVars[1]).GetValue(state); float toValZ = ParseString(toVars[2]).GetValue(state); toPos = new Vector3(toValX, toValY, toValZ); } else { toPos = new Vector3((float)to[0], (float)to[1], (float)to[2]); } // -16 to 32 -> -1 to 2 //fromPos = fromPos + new Vector3(16, 16, 16); fromPos /= 16; //toPos = toPos + new Vector3(16, 16, 16); toPos /= 16; // (0,0,0) to (16,16,16) is a regular cube (0 to 1, 0 to 1, 0 to 1) in minecraft ////// (0,0,0) to (1,1,1) -> fromPos to toPos ///// Vector3 diff = toPos - fromPos; res = res * diff + fromPos; if (rotation != null) { res = res.ApplyingTransformationToEachVertex(x => { return(rotation.ApplyToPoint(x)); }); } int rotationDegrees = 0; if (blockRotation == BlockData.BlockRotation.Degrees0) { } else if (blockRotation == BlockData.BlockRotation.Degrees180) { rotationDegrees = 180; } else if (blockRotation == BlockData.BlockRotation.Degrees270) { rotationDegrees = 270; } else if (blockRotation == BlockData.BlockRotation.Degrees90) { rotationDegrees = 90; } if (rotationDegrees != 0) { BlockModelRotation customRotation = new BlockModelRotation { axis = "y", angle = rotationDegrees, origin = new double[] { 8, 0, 8 } }; res = res.ApplyingTransformationToEachVertex(x => { return(customRotation.ApplyToPoint(x)); }); //Debug.Log("got " + customRotation.ApplyToPoint(new Vector3(0, 0, 1)) + " is the res"); } //Debug.Log("my texture value is " + texture); //Debug.Log("my to value is " + toPos[0] + " " + toPos[1] + " " + toPos[2]); //Debug.Log("my from value is " + fromPos[0] + " " + fromPos[1] + " " + fromPos[2]); // offset uvs x value to match correct texture if (texture != null) { int texIndex = rootModel.TexToIndex(texture); //Debug.Log("tex of " + texture + " maps to index " + texIndex); res += new Vector2(texIndex / 64.0f, 0.0f); } //res = res * new Vector2(1/64.0f, 1.0f/256.0f); //res = res * new Vector2(1.0f, 1.0f); // 0 to 1 -> -0.5 to 0.5 //res = res - new Vector3(0.5f, 0.5f, 0.5f); return(res.ToRenderTriangles()); }