public static MeshFactory meshBuilder(String string) { return new MeshFactory(string); }
/** * @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); } } }
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; }
/** * @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); }
public static int[][] addVertexToMeshFactory(MeshFactory meshFactory, Point3d[][] mesh, int pointCount, int crossCount) { int[][] pointsIntex = new int[pointCount][]; for (int i = 0; i < pointCount; i++) { pointsIntex[i] = new int[crossCount]; for (int j = 0; j < crossCount; j++) { Point3d p = mesh[i][j]; int ip = meshFactory.addVertex(p); pointsIntex[i][j] = ip; } } return pointsIntex; }
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 int[][] buildNormalsIndexs(MeshFactory meshFactory, Point3d[][] mesh, Point3d center3d, int pointCount, int crossCount) { int[][] softNormalsIndexs = new int[pointCount][]; for (int i = 0; i < pointCount; i++) { softNormalsIndexs[i] = new int[crossCount]; for (int j = 0; j < crossCount; j++) { Point3d p = mesh[i][j]; Vector3d n = Vector3dUtil.fromTo(center3d, p); n.normalize(); int in = meshFactory.addNormal(n); softNormalsIndexs[i][j] = in; } } return softNormalsIndexs; }
FaceFactory face = meshFactory.addFace(FaceType.QUADS);
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 int cachePointIndex(Point2d point, int pointIndex, double height, Integer[] pointsIndexCache, MeshFactory meshBorder) { if (pointsIndexCache[pointIndex] == null) { pointsIndexCache[pointIndex] = meshBorder.addVertex(new Point3d(point.x, height, -point.y)); } return pointsIndexCache[pointIndex]; }
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; }
private static int[][] buildSoftNormalsIndexs(MeshFactory meshFactory, int sectionCount, Point2d[] crossSection, int crossCount) { Vector2d[] crossSectionSoftNormals = calsSoftNormals(crossSection); int[][] softNormalsIntex = new int[sectionCount][]; for (int i = 0; i < sectionCount; i++) { double a = Math.toRadians(360) / sectionCount * i; SimpleMatrix rotY = TransformationMatrix3d.rotYA(a); softNormalsIntex[i] = new int[crossCount]; for (int j = 0; j < crossSection.length; j++) { // point Vector2d n2d = crossSectionSoftNormals[j]; Vector3d n = new Vector3d(n2d.x, n2d.y, 0); Vector3d transform = TransformationMatrix3d.transform(n, rotY); int in = meshFactory.addNormal(transform); softNormalsIntex[i][j] = in; } } return softNormalsIntex; }
FaceFactory faceRight = pMeshBorder.addFace(FaceType.QUADS); FaceFactory faceLeft = null; if (!PREFER_TWO_SIDED.get()) { faceLeft = pMeshBorder.addFace(FaceType.QUADS); Double startHeight = getHeight(0, pHeights); int startMi = pMeshBorder.addVertex(new Point3d(start.x, startHeight + pMinHeight, -start.y)); int startHi = pMeshBorder.addVertex(new Point3d(start.x, startHeight + pHeight, -start.y)); int bmi = pMeshBorder.addTextCoord(bm); int bhi = pMeshBorder.addTextCoord(bh); Double endHeight = getHeight(i, pHeights); int endMi = pMeshBorder.addVertex(new Point3d(end.x, endHeight + pMinHeight, -end.y)); int endHi = pMeshBorder.addVertex(new Point3d(end.x, endHeight + pHeight, -end.y)); int n1i = pMeshBorder.addNormal(normal); TextCoord eh = new TextCoord(uvEnd, 1); int emi = pMeshBorder.addTextCoord(em); int ehi = pMeshBorder.addTextCoord(eh); Vector3d normal2 = new Vector3d(-normal.x, -normal.y, -normal.z); int n2i = pMeshBorder.addNormal(normal2);
Integer[] topPointsIndex = new Integer[size]; FaceFactory face = mesh.addFace(FaceType.TRIANGLES); int normalIndex = mesh.addNormal(n); 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()));
/** Add mesh to model. * @param pName name of mesh * @return added mesh */ public MeshFactory addMesh(String pName) { MeshFactory mf = new MeshFactory(); mf.name = pName; this.mashFactory.add(mf); return mf; }
private static int segmentPointToVertex3dIndex(Point2d point, Point2d start, Vector2d direction, MeshFactory mesh) { Point3d vertex = new Point3d(direction.x, 0, -direction.y); vertex.scale(point.x); vertex.x += start.x; vertex.z -= start.y; vertex.y = point.y; int iV = mesh.addVertex(vertex); return iV; }
public static kendzi.jogl.model.factory.MeshFactory cubeMesh(Point3d start, Vector3d size) { MeshFactory mf = new MeshFactory(); FaceFactory face = mf.addFace(FaceType.QUADS); 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)); int nf = mf.addNormal(new Vector3d(0, 0, 1)); int nb = mf.addNormal(new Vector3d(0, 0, -1)); int nl = mf.addNormal(new Vector3d(-1, 0, 0)); int nr = mf.addNormal(new Vector3d(1, 0, 0)); int nt = mf.addNormal(new Vector3d(0, 1, 0)); int nd = mf.addNormal(new Vector3d(0, -1, 0)); int ruf = mf.addVertex(new Point3d(x + sx, y + sy, z + sz)); int rub = mf.addVertex(new Point3d(x + sx, y + sy, z - sz)); int rdf = mf.addVertex(new Point3d(x + sx, y - sy, z + sz)); int rdb = mf.addVertex(new Point3d(x + sx, y - sy, z - sz)); int luf = mf.addVertex(new Point3d(x - sx, y + sy, z + sz)); int lub = mf.addVertex(new Point3d(x - sx, y + sy, z - sz)); int ldf = mf.addVertex(new Point3d(x - sx, y - sy, z + sz)); int ldb = mf.addVertex(new Point3d(x - sx, y - sy, z - sz));