/** * Add material representing texture to model. * * @param textureData * @param model * @return */ private static RoofTextureIndex addMateraialTexture(TextureData textureData, Color color, ModelFactory model) { Material facadeMaterial = null; if (color != null) { facadeMaterial = MaterialFactory.createTextureColorMaterial(textureData.getTex0(), color); } else { facadeMaterial = MaterialFactory.createTextureMaterial(textureData.getTex0()); } int facadeMaterialIndex = model.addMaterial(facadeMaterial); return new RoofTextureIndex(facadeMaterialIndex, textureData); }
private static MeshFactory createRoofMesh(ModelFactory mf, TextureData td, Color color) { Material mat = MaterialFactory.createTextureColorMaterial(td.getTex0(), color); int materialIndex = mf.addMaterial(mat); MeshFactory meshRoof = mf.addMesh("roof_top"); meshRoof.materialID = materialIndex; meshRoof.hasTexture = true; return meshRoof; }
/** * Wall material can few four components like wall color (mixed with base * texture), base texture (mixed with color), optional overlayer texture for * wall material (like bricks) and optional overlayer for wall windows. * * @param facadeColor * facade color * @param facadeTextureData * facade texture data with required base texture, and optional * overlay * @param windowsOverlayerTextureData * optional texture with window overlayer * @return material for facade */ private static Material createWallMaterial(Color facadeColor, TextureData facadeTextureData, TextureData windowsOverlayerTextureData) { Material mat = MaterialFactory.createTextureColorMaterial(facadeTextureData.getTex0(), facadeColor); if (facadeTextureData.getTex1() != null) { mat.getTexturesComponent().add(facadeTextureData.getTex1()); } if (windowsOverlayerTextureData != null) { mat.getTexturesComponent().add(windowsOverlayerTextureData.getTex0()); } return mat; }
public static TextureData colorableTextureData(TextureData textureData) { String tex0 = null; String tex1 = null; double width = 1d; double height = 1d; if (textureData != null) { tex0 = textureData.getTex0(); tex1 = textureData.getTex1(); width = textureData.getWidth(); height = textureData.getHeight(); } if (tex0 == null) { tex0 = "#c=0xffffff"; } else { tex0 = "#bw=" + tex0; } return new TextureData(tex0, tex1, width, height, true); }
private static TextureData generateWindowsOverlayTextureData(Wall wall, double minHeight, double wallHeight, BuildingPart buildingPart, BuildingModel buildingModel, BuildingElementsTextureManager tm, WallPart wallPart, double wallLength) { Integer windowsCols = hasWindowsCloumns(wallPart.getBuildingElements()); if (windowsCols != null && windowsCols != 0) { /* Check if wall has any windows column defined. */ TextureData windowsTextureData = takeWindowsColumnsTextureData(buildingModel, buildingPart, wall, wallPart, tm); double windowsSegmetLength = wallLength / (double) windowsCols; int facadeLevels = getFacadeLevels(wall, buildingPart); /* * Adjust texture data size to match wall size multiply by number of * window columns and levels. */ double windowsSegmentHeight = (wallHeight - minHeight) / facadeLevels; return new TextureData(windowsTextureData.getTex0(), windowsSegmetLength, windowsSegmentHeight); } return null; }
private static BuildingPartOutput buildNodePart(NodeBuildingPart bp, BuildingModel buildingModel, ModelFactory mf, BuildingElementsTextureManager tm) { if (bp instanceof SphereNodeBuildingPart) { Color floorColor = takeFacadeColor(buildingModel, bp, tm); TextureData floorTD = takeFacadeTextureData(buildingModel, bp, tm, floorColor != null); String tex0Key = floorTD.getTex0(); Material mat = MaterialFactory.createTextureColorMaterial(tex0Key, floorColor); MeshFactory mesh = mf.addMesh("NodePart"); mesh.hasTexture = true; mesh.materialID = mf.cacheMaterial(mat); SphereNodeBuildingPart sphere = (SphereNodeBuildingPart) bp; int pIcross = 12; int icross = pIcross + 1; double height = sphere.getHeight(); double radius = sphere.getRadius(); Point2d point = sphere.getPoint(); // create cross section Point2d[] crossSection = new Point2d[icross]; for (int i = 0; i < icross; i++) { double a = Math.toRadians(180) / (icross - 1) * i - Math.toRadians(90); crossSection[i] = new Point2d(Math.cos(a) * radius, Math.sin(a) * radius + height); } int pIsection = 12; RoofType5v6.buildRotaryShape(mesh, point, pIsection, crossSection, true); } return new BuildingPartOutput(); }
private static void buildFloor(BuildingPart bp, BuildingModel buildingModel, ModelFactory mf, BuildingElementsTextureManager tm, TextureData roofTextureData, Color facadeColor, double minHeight) { Color floorColor = takeFloorColor(buildingModel, bp, tm); TextureData floorTD = takeFloorTextureData(buildingModel, bp, tm, floorColor != null); String tex0Key = floorTD.getTex0(); Material mat = MaterialFactory.createTextureColorMaterial(tex0Key, floorColor); MeshFactory mesh = mf.addMesh("FloorPart"); mesh.hasTexture = true; mesh.materialID = mf.cacheMaterial(mat); PolygonWithHolesList2d buildingPolygon = BuildingUtil.buildingPartToPolygonWithHoles(bp); MeshFactoryUtil.addPolygonWithHolesInYRevert(buildingPolygon, minHeight, mesh, roofTextureData, 0, 0, new Vector3d(1, 0, 0)); }
@Override public void buildWorldObject() { if (!(points.size() > 1)) { return; } String fenceType = BarrierFenceRelation.getFenceType(way); double fenceHeight = metadataCacheService.getPropertitesDouble("barrier.fence_{0}.height", FENCE_HEIGHT, fenceType); hight = ModelUtil.getHeight(way, fenceHeight); minHeight = ModelUtil.getMinHeight(way, 0d); TextureData facadeTexture = BarrierFenceRelation.getFenceTexture(fenceType, way, textureLibraryStorageService); ModelFactory modelBuilder = ModelFactory.modelBuilder(); MeshFactory meshBorder = BarrierFenceRelation.createMesh(facadeTexture.getTex0(), null, "fence_border", modelBuilder); BarrierFenceRelation.buildWallModel(points, null, minHeight, hight, 0, meshBorder, facadeTexture); model = modelBuilder.toModel(); model.setUseLight(true); model.setUseTexture(true); model.setUseTextureAlpha(true); model.setUseCullFaces(!PREFER_TWO_SIDED.get()); model.setUseTwoSidedLighting(PREFER_TWO_SIDED.get()); buildModel = true; heightClone = RelationCloneHeight.buildHeightClone(way); }
@Override public void buildWorldObject() { if (!(points.size() > 1)) { // FIXME model = new Model(); buildModel = true; return; } String fenceType = getFenceType(relation); double fenceHeight = metadataCacheService.getPropertitesDouble("barrier.fence_{0}.height", FENCE_HEIGHT, fenceType); hight = ModelUtil.getHeight(relation, fenceHeight); minHeight = ModelUtil.getMinHeight(relation, 0d); TextureData facadeTexture = getFenceTexture(fenceType, relation, textureLibraryStorageService); ModelFactory modelBuilder = ModelFactory.modelBuilder(); MeshFactory meshBorder = createMesh(facadeTexture.getTex0(), null, "fence_border", modelBuilder); buildWallModel(points, heights, minHeight, hight, 0, meshBorder, facadeTexture); model = modelBuilder.toModel(); model.setUseLight(true); model.setUseTexture(true); model.setUseTextureAlpha(true); model.setUseCullFaces(!PREFER_TWO_SIDED.get()); model.setUseTwoSidedLighting(PREFER_TWO_SIDED.get()); buildModel = true; }
@Override public void buildWorldObject() { if (!(points.size() > 1)) { return; } String wallType = getWallType(way); double wallHeight = metadataCacheService.getPropertitesDouble("barrier.wall_{0}.height", WALL_HEIGHT, wallType); hight = ModelUtil.getHeight(way, wallHeight); minHeight = ModelUtil.getMinHeight(way, 0d); // String wallColor = OsmAttributeKeys.COLOUR.primitiveValue(this.way); Color wallColor = takeWallColor(way); TextureData wallTexture = takeWallTexture(wallType, wallColor, way, textureLibraryStorageService); ModelFactory modelBuilder = ModelFactory.modelBuilder(); MeshFactory meshBorder = BarrierFenceRelation.createMesh(wallTexture.getTex0(), wallColor, "wall_border", modelBuilder); BarrierFenceRelation.buildWallModel(points, null, minHeight, hight, 0, meshBorder, wallTexture); model = modelBuilder.toModel(); model.setUseLight(true); model.setUseTexture(true); model.setUseTextureAlpha(true); model.setUseCullFaces(!PREFER_TWO_SIDED.get()); model.setUseTwoSidedLighting(PREFER_TWO_SIDED.get()); buildModel = true; heightClone = RelationCloneHeight.buildHeightClone(way); }
Material fenceMaterial = MaterialFactory.createTextureMaterial(facadeTexture.getTex0());
@Override public void buildWorldObject() { ModelFactory model = ModelFactory.modelBuilder(); MeshFactory mesh = model.addMesh("water"); TextureData waterTexture = getWaterTextureData();// new // TextureData("#c=#008EFF", // 1d, 1d); Material waterMaterial = MaterialFactory.createTextureMaterial(waterTexture.getTex0()); int waterMaterialIndex = model.addMaterial(waterMaterial); mesh.materialID = waterMaterialIndex; mesh.hasTexture = true; Vector3d nt = new Vector3d(0, 1, 0); Point3d planeRightTopPoint = new Point3d(0, 0.05, 0); List<PolygonWithHolesList2d> polyList = getMultiPolygonWithHoles(); for (PolygonWithHolesList2d poly : polyList) { List<Triangle2d> triangles = Poly2TriSimpleUtil.triangulate(poly); Plane3d planeTop = new Plane3d(planeRightTopPoint, nt); Vector3d roofTopLineVector = new Vector3d(-1, 0, 0); MeshFactoryUtil.addPolygonToRoofMesh(mesh, triangles, planeTop, roofTopLineVector, waterTexture, 0, 0); } this.model = model.toModel(); this.model.setUseLight(true); this.model.setUseTexture(true); buildModel = true; }
public void draw(GL2 gl, Point3d cameraPosition) { gl.glEnable(GL2.GL_LIGHTING); gl.glEnable(GL2.GL_TEXTURE_2D); TextureData td = this.textureLibraryStorageService.getTextureDefault("ground.unknown"); Texture texture = this.textureCacheService.getTexture(gl, td.getTex0()); texture.enable(gl); texture.bind(gl); gl.glBegin(GL2.GL_POLYGON); gl.glColor3f((float) 123 / 256, (float) 111 / 256, (float) 100 / 255); double groundSize = 1500.0; Point3d c = cameraPosition; // gl.glTexCoord2d(tc.left(), tc.bottom()); double xRight = c.x + groundSize; double xLeft = c.x - groundSize; double zButtom = c.z + groundSize; double zTop = c.z - groundSize; gl.glNormal3d(0, 1, 0); gl.glTexCoord2d(xRight * td.getWidth(), zButtom * td.getHeight()); gl.glVertex3d(xRight, -0.01, zButtom); gl.glTexCoord2d(xLeft * td.getWidth(), zButtom * td.getHeight()); gl.glVertex3d(xLeft, -0.01, zButtom); gl.glTexCoord2d(xLeft * td.getWidth(), zTop * td.getHeight()); gl.glVertex3d(xLeft, -0.01, zTop); gl.glTexCoord2d(xRight * td.getWidth(), zTop * td.getHeight()); gl.glVertex3d(xRight, -0.01, zTop); gl.glEnd(); texture.disable(gl); gl.glDisable(GL2.GL_TEXTURE_2D); }
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; }
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; }