private static int segmentPointToTextureDataIndex(Point2d point, double offsetX, double offsetY, MeshFactory mesh, TextureData td) { return mesh.addTextCoord(new TextCoord((point.x + offsetX) / td.getWidth(), (point.y + offsetY) / td.getHeight())); }
public static TextureQuadIndex[] buildTextureMappingForCross(MeshFactory meshFactory, Point3d[][] mesh, int pointCount, int crossCount, int i) { TextureQuadIndex[] crossTc = new TextureQuadIndex[crossCount]; double textHeightDown = 0; Point3d[] c1 = mesh[i]; Point3d[] c2 = mesh[(i + 1) % pointCount]; Point3d middleDown = new Point3d((c1[0].x + c2[0].x) / 2d, (c1[0].y + c2[0].y) / 2d, (c1[0].z + c2[0].z) / 2d); double widthDown = middleDown.distance(c2[0]); for (int j = 1; j < crossCount; j++) { Point3d middleTop = new Point3d((c1[j].x + c2[j].x) / 2d, (c1[j].y + c2[j].y) / 2d, (c1[j].z + c2[j].z) / 2d); double widthTop = middleTop.distance(c2[j]); double height = middleDown.distance(middleTop); double textHeightTop = textHeightDown + height; TextureQuadIndex tq = new TextureQuadIndex(); tq.setLd(meshFactory.addTextCoord(new TextCoord(-widthDown, textHeightDown))); tq.setRd(meshFactory.addTextCoord(new TextCoord(widthDown, textHeightDown))); tq.setRt(meshFactory.addTextCoord(new TextCoord(widthTop, textHeightTop))); tq.setLt(meshFactory.addTextCoord(new TextCoord(-widthTop, textHeightTop))); crossTc[j - 1] = tq; middleDown = middleTop; widthDown = widthTop; textHeightDown = textHeightTop; } return crossTc; }
plane2.getPoint(), roofTexture, textureOffsetU, textureOffsetV); int tci = pMeshRoof.addTextCoord(calcUV);
int tcb1 = meshWalls.addTextCoord(new TextCoord(0, 0.99999d)); int tcb2 = meshWalls.addTextCoord(new TextCoord(0, 1 - 0.10d)); int tcb3 = meshWalls.addTextCoord(new TextCoord(0, 0.00001d)); int tcb4 = meshWalls.addTextCoord(new TextCoord(0, 1 - 0.10d)); int tcb5 = meshWalls.addTextCoord(new TextCoord(0, 0.99999d)); int tce1 = meshWalls.addTextCoord(new TextCoord(uEnd, 0.99999d)); int tce2 = meshWalls.addTextCoord(new TextCoord(uEnd, 1 - 0.10d)); int tce3 = meshWalls.addTextCoord(new TextCoord(uEnd, 0.00001d)); int tce4 = meshWalls.addTextCoord(new TextCoord(uEnd, 1 - 0.10d)); int tce5 = meshWalls.addTextCoord(new TextCoord(uEnd, 0.99999d));
TextCoord bh = new TextCoord(0, 1); int bmi = pMeshBorder.addTextCoord(bm); int bhi = pMeshBorder.addTextCoord(bh); TextCoord eh = new TextCoord(uvEnd, 1); int emi = pMeshBorder.addTextCoord(em); int ehi = pMeshBorder.addTextCoord(eh);
/** * @param meshBorder * @param polygons */ public void solidToModel(MeshFactory meshBorder, ArrayList<Polygon> polygons) { for (Polygon polygon : polygons) { Vertex[] vertices = polygon.getVertices(); FaceFactory faceRight = meshBorder.addFace(FaceType.TRIANGLE_FAN); meshBorder.addTextCoord(new TextCoord(0.5, 0.5)); for (Vertex vertex : vertices) { kendzi.math.geometry.Bool.CSG.Vector pos = vertex.getPos(); Vector normal = vertex.getNormal(); int vi = meshBorder.addVertex(new Point3d(pos.x, pos.y, pos.z)); int ni = meshBorder.addNormal(new Vector3d(normal.x, normal.y, normal.z)); faceRight.addVert(vi, 0, ni); } } }
/** * @param pMeshRoof * @param pPlane * @param pTextureVector * @param pTextureData * @param textureOffsetU * @param textureOffsetV * @param normalIndex * @param face * @param point2d */ private static void addPointToTriangleFace(MeshFactory pMeshRoof, Plane3d pPlane, Vector3d pTextureVector, TextureData pTextureData, double textureOffsetU, double textureOffsetV, int normalIndex, FaceFactory face, Point2d point2d) { double h = pPlane.calcYOfPlane(point2d.x, -point2d.y); Point3d point3d = new Point3d(point2d.x, h, -point2d.y); int vi = pMeshRoof.addVertex(point3d); // Point3d point3d = pMeshRoof.vertices.get(vi); face.addVertIndex(vi); face.addNormalIndex(normalIndex); TextCoord calcUV = TextCordFactory.calcFlatSurfaceUV(point3d, pPlane.getNormal(), pTextureVector, pPlane.getPoint(), pTextureData, textureOffsetU, textureOffsetV); int tci = pMeshRoof.addTextCoord(calcUV); face.addCoordIndex(tci); }
private static MultiPolygonList2d applyWindowsEnd(MultiPolygonList2d mPoly, BuildingNodeElement be, Point2d segmentStart, Vector2d segmentDirection, double nodeDisplacement, CatchFaceFactory catchFaceFactory, BuildingElementsTextureManager textureMenager, boolean counterClockwise) { if (be instanceof SquareHoleElement) { SquareHoleElement she = (SquareHoleElement) be; Point2d lbp = new Point2d(nodeDisplacement - she.getWidth() / 2.0, she.getMinHeight()); Point2d mbp = new Point2d(nodeDisplacement, she.getMinHeight()); Point2d mtp = new Point2d(nodeDisplacement, she.getMaxHeight()); Point2d ltp = new Point2d(nodeDisplacement - she.getWidth() / 2.0, she.getMaxHeight()); mPoly = PolygonSplitHelper.unionOfLeftSideOfMultipleCuts(mPoly, new LinePoints2d(lbp, ltp), new LinePoints2d(ltp, mtp), new LinePoints2d(mbp, lbp)); TextureData td = findWindowTextureData(be, textureMenager); MeshFactory mesh = catchFaceFactory.createOrGetMeshFactory(td.getTex0()); FaceFactory face = mesh.addFace(FaceType.QUADS); Vector3d n = new Vector3d(-segmentDirection.y, 0, -segmentDirection.x); n.negate(); int iN = mesh.addNormal(n); int imbTc = mesh.addTextCoord(new TextCoord(0.5, 0)); int imtTc = mesh.addTextCoord(new TextCoord(0.5, 1)); int ilbTc = mesh.addTextCoord(new TextCoord(0, 0)); int iltTc = mesh.addTextCoord(new TextCoord(0, 1)); face.addVert(segmentPointToVertex3dIndex(lbp, segmentStart, segmentDirection, mesh), ilbTc, iN); face.addVert(segmentPointToVertex3dIndex(mbp, segmentStart, segmentDirection, mesh), imbTc, iN); face.addVert(segmentPointToVertex3dIndex(mtp, segmentStart, segmentDirection, mesh), imtTc, iN); face.addVert(segmentPointToVertex3dIndex(ltp, segmentStart, segmentDirection, mesh), iltTc, iN); } return mPoly; }
private static MultiPolygonList2d applyWindowsBegin(MultiPolygonList2d mPoly, BuildingNodeElement be, Point2d segmentStart, Vector2d segmentDirection, double nodeDisplacement, CatchFaceFactory pCatchFaceFactory, BuildingElementsTextureManager pTextureMenager, boolean counterClockwise) { if (be instanceof SquareHoleElement) { SquareHoleElement she = (SquareHoleElement) be; Point2d mbp = new Point2d(0, she.getMinHeight()); Point2d rbp = new Point2d(she.getWidth() / 2.0, she.getMinHeight()); Point2d rtp = new Point2d(she.getWidth() / 2.0, she.getMaxHeight()); Point2d mtp = new Point2d(0, she.getMaxHeight()); mPoly = PolygonSplitHelper.unionOfLeftSideOfMultipleCuts(mPoly, new LinePoints2d(rtp, rbp), new LinePoints2d(mtp, rtp), new LinePoints2d(rbp, mbp)); TextureData td = findWindowTextureData(be, pTextureMenager); MeshFactory mesh = pCatchFaceFactory.createOrGetMeshFactory(td.getTex0()); FaceFactory face = mesh.addFace(FaceType.QUADS); Vector3d n = new Vector3d(-segmentDirection.y, 0, -segmentDirection.x); // if (counterClockwise) { n.negate(); // } int iN = mesh.addNormal(n); int imbTc = mesh.addTextCoord(new TextCoord(0.5, 0)); int imtTc = mesh.addTextCoord(new TextCoord(0.5, 1)); int irbTc = mesh.addTextCoord(new TextCoord(1, 0)); int irtTc = mesh.addTextCoord(new TextCoord(1, 1)); face.addVert(segmentPointToVertex3dIndex(mbp, segmentStart, segmentDirection, mesh), imbTc, iN); face.addVert(segmentPointToVertex3dIndex(rbp, segmentStart, segmentDirection, mesh), irbTc, iN); face.addVert(segmentPointToVertex3dIndex(rtp, segmentStart, segmentDirection, mesh), irtTc, iN); face.addVert(segmentPointToVertex3dIndex(mtp, segmentStart, segmentDirection, mesh), imtTc, iN); } return mPoly; }
int nb2 = border.addNormal(new Vector3d(0, 0, -1)); int t_0_0 = border.addTextCoord(new TextCoord(0, 0)); int t_u15_v1 = border.addTextCoord(new TextCoord(u1/2, v1)); int t_u1_0 = border.addTextCoord(new TextCoord(u1, 0)); Vector3d roofLineVector2 = new Vector3d(0, 0, -1); int tc1 = top.addTextCoord(calcUV(p1, tn1, roofLineVector1, p1, roofTexture)); int tc2 = top.addTextCoord(calcUV(p25, tn1, roofLineVector1, p1, roofTexture)); int tc3 = top.addTextCoord(calcUV(p38, tn1, roofLineVector1, p1, roofTexture)); int tc4 = top.addTextCoord(calcUV(p4, tn1, roofLineVector1, p1, roofTexture)); int tc5 = top.addTextCoord(calcUV(p25, tn2, roofLineVector2, p7, roofTexture)); int tc6 = top.addTextCoord(calcUV(p6, tn2, roofLineVector2, p7, roofTexture)); int tc7 = top.addTextCoord(calcUV(p7, tn2, roofLineVector2, p7, roofTexture)); int tc8 = top.addTextCoord(calcUV(p38, tn2, roofLineVector2, p7, roofTexture));
int t_0_0 = border.addTextCoord(new TextCoord(0, 0)); int t_0_v1 = border.addTextCoord(new TextCoord(0, v1)); int t_u1_0 = border.addTextCoord(new TextCoord(u1, 0)); int t_u1_v1 = border.addTextCoord(new TextCoord(u1, v1)); int t_u2_0 = border.addTextCoord(new TextCoord(u2, 0)); int t_u2_v2 = border.addTextCoord(new TextCoord(u2, v2)); int t_0_v2 = border.addTextCoord(new TextCoord(0, v2)); int t_u1_v2 = border.addTextCoord(new TextCoord(u1, v2)); int tc1 = top.addTextCoord(calcUV(p1, tn, roofLineVector, p1, roofTexture)); int tc2 = top.addTextCoord(calcUV(p2, tn, roofLineVector, p1, roofTexture)); int tc3 = top.addTextCoord(calcUV(p3, tn, roofLineVector, p1, roofTexture)); int tc4 = top.addTextCoord(calcUV(p4, tn, roofLineVector, p1, roofTexture));
uLast = uEnd; int tc_0_0 = mesh.addTextCoord(new TextCoord(uBegin, minHeight1 / textureData.getHeight())); int tc_0_v = mesh.addTextCoord(new TextCoord(uBegin, height1 / textureData.getHeight())); int tc_u_0 = mesh.addTextCoord(new TextCoord(uEnd, minHeight2 / textureData.getHeight())); int tc_u_v = mesh.addTextCoord(new TextCoord(uEnd, height2 / textureData.getHeight()));
double sz = size.z / 2d; int tld = mf.addTextCoord(new TextCoord(0, 0)); int trd = mf.addTextCoord(new TextCoord(1, 0)); int tlu = mf.addTextCoord(new TextCoord(0, 1)); int tru = mf.addTextCoord(new TextCoord(1, 1));
meshBorder.addTextCoord(new TextCoord(0.5, 0.5));