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); }
/** * @param colorable * @param textureSet * @return */ public List<TextureData> filterByColorable( boolean colorable, List<TextureData> textureSet) { List<TextureData> ret = new ArrayList<TextureData>(); for (TextureData td : textureSet) { if (td.isColorable() != null && td.isColorable() == colorable) { ret.add(td); } } return ret; }
/** * 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 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); }
/** * 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 TextureData createEmptyTextureData() { return new TextureData(null, 1, 1); } }
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; }
double uvEnd = dist / pWallTexture.getWidth(); uvEnd = (uvEnd < 0.33) ? 0 : (uvEnd < 1.0) ? 1 : (int) uvEnd;
boolean isOverLayer = facadeTextureData.getTex1() != null; boolean isWindows = adjustedWindowsTextureData != null;
/** * @param pTextureFindCriteria * @param textureSet * @return */ public List<TextureData> filterByBestSizeMatch(TextureFindCriteria pTextureFindCriteria, List<TextureData> textureSet) { TextureData best = null; double bestError = Double.MAX_VALUE; double height = pTextureFindCriteria.getHeight() == null ? 0 : pTextureFindCriteria.getHeight(); double width = pTextureFindCriteria.getWidth() == null ? 0 : pTextureFindCriteria.getWidth(); for (TextureData td : textureSet) { double dH = td.getHeight() - height; double dW = td.getWidth() - width; double err = dH * dH + dW * dW; if (err < bestError) { bestError = err; best = td; } } return Arrays.asList(best); } }
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; }
/** * {@inheritDoc} * * @see kendzi.josm.kendzi3d.service.TextureLibrary#getTextureDefault(java.lang.String) */ @Override public TextureData getTextureDefault(String key) { TextureData texture = getRadnomTextureForKey(key); if (texture == null) { return new TextureData(null, 1, 1); } return texture; }
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(); }
public static TextureData takeWindowsColumnsTextureData(BuildingModel buildingModel, BuildingPart bp, Wall w, WallPart wp, BuildingElementsTextureManager tm) { String mt = null; TextureData td = tm.findTexture(new TextureFindCriteria(Type.WINDOWS, mt, null, null, null, false)); if (td == null) { td = new TextureData(null, 1, 1); } return td; }
/** * Gets wall texture data. * * @param wallType * wall type * @param wallColor * wall color * @param osmPrimitive * primitive * @param TextureLibraryStorageService * texture library service * @return texture data */ public static TextureData takeWallTexture(String wallType, Color wallColor, OsmPrimitive osmPrimitive, TextureLibraryStorageService TextureLibraryStorageService) { String textureKey = TextureLibraryStorageService.getKey(TextureLibraryKey.BARRIER_WALL, wallType); TextureData textureData = TextureLibraryStorageService.getTextureDefault(textureKey); if (!Boolean.FALSE.equals(textureData.isColorable()) && wallColor != null) { return OsmBuildingElementsTextureMenager.colorableTextureData(textureData); } return textureData; }
double uEnd = uLast + point1.distance(point2) / textureData.getWidth(); 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()));
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)); }
public static TextureData takeFloorTextureData(BuildingModel buildingModel, BuildingPart bp, BuildingElementsTextureManager tm, boolean colorable) { String mt = null; if (bp.getFloorMaterialType() != null) { mt = bp.getFloorMaterialType(); } else if (buildingModel.getFloorMaterialType() != null) { mt = buildingModel.getFloorMaterialType(); } TextureData td = tm.findTexture(new TextureFindCriteria(Type.FLOOR, mt, null, null, null, colorable)); if (td == null) { td = new TextureData(null, 1, 1); } return td; }