/** * @param tex0Key * @param textColor * @param meshName * @param modelBuilder * @return */ public static MeshFactory createMesh(String tex0Key, Color textColor, String meshName, ModelFactory modelBuilder) { MeshFactory meshBorder = modelBuilder.addMesh(meshName); // Material fenceMaterial = MaterialFactory.createTextureMaterial(tex0); Material mat = MaterialFactory.createTextureColorMaterial(tex0Key, textColor); int facadeMaterialIndex = modelBuilder.addMaterial(mat); meshBorder.materialID = facadeMaterialIndex; meshBorder.hasTexture = true; return meshBorder; }
public static ModelFactory modelBuilder() { return new ModelFactory(); }
private static MeshFactory createWallMesh(ModelFactory mf, int partNumber, Material mat) { MeshFactory mesh = mf.addMesh("WallPart: " + partNumber); mesh.hasTexture = true; mesh.materialID = mf.cacheMaterial(mat); return mesh; }
@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; }
/** * Build 3d Model of building. * * @param buildingModel * building model * @param tm * texture manager * @return building model and debug informations */ public static BuildingOutput buildModel(BuildingModel buildingModel, BuildingElementsTextureManager tm) { List<BuildingPartOutput> partsOut = new ArrayList<BuildingPartOutput>(); ModelFactory mf = ModelFactory.modelBuilder(); if (buildingModel.getParts() != null) { for (BuildingPart bp : buildingModel.getParts()) { partsOut.add(buildPart(bp, buildingModel, mf, tm)); } } if (buildingModel.getNodeParts() != null) { for (NodeBuildingPart bp : buildingModel.getNodeParts()) { partsOut.add(buildNodePart(bp, buildingModel, mf, tm)); } } BuildingOutput out = new BuildingOutput(); out.setModel(mf.toModel()); out.setBuildingPartOutput(partsOut); return out; }
public int cacheMaterial(Material mat) { int i = this.materials.indexOf(mat); if ( i >= 0 ) { return i; } return addMaterial(mat); }
/** Add mesh to model. * @return added mesh */ public MeshFactory addMesh() { return addMesh((String) null); }
ModelFactory modelBuilder = ModelFactory.modelBuilder(); MeshFactory meshBorder = modelBuilder.addMesh("fence_border"); MeshFactory testMesh = modelBuilder.addMesh("test"); Material fenceMaterial = MaterialFactory.createTextureMaterial(facadeTexture.getTex0()); int facadeMaterialIndex = modelBuilder.addMaterial(fenceMaterial); meshBorder.hasTexture = true; modelBuilder.addMesh(meshBorder); MeshFactory cubeMesh = MeshFactoryUtil.cubeMesh(new Point3d(start.x, 3, -start.y)); modelBuilder.addMesh(cubeMesh); model = modelBuilder.toModel(); model.setUseLight(true); model.setUseTexture(true);
@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); }
/** * 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 void buildModel(RoofTypeOutput rto, List<RoofDormerTypeOutput> roofExtensionsList, ModelFactory modelFactory) { for (MeshFactory mf : rto.getMesh()) { transformMeshFactory(mf, rto.getTransformationMatrix()); modelFactory.addMesh(mf); } for (RoofDormerTypeOutput roofDormerTypeOutput : roofExtensionsList) { if (roofDormerTypeOutput == null) { continue; } SimpleMatrix roofMatrix = rto.getTransformationMatrix() .mult(roofDormerTypeOutput.getTransformationMatrix()); for (MeshFactory mf : roofDormerTypeOutput.getMesh()) { transformMeshFactory(mf, roofMatrix); modelFactory.addMesh(mf); } } } }
ModelFactory modelBuilder = ModelFactory.modelBuilder(); int mi = modelBuilder.addMaterial(m); MeshFactory meshWalls = modelBuilder.addMesh("road"); model = modelBuilder.toModel(); model.setUseLight(true); model.setUseTexture(true);
MeshFactory createOrGetMeshFactory(String textureKey) { MeshFactory meshFactory = catchMesh.get(textureKey); if (meshFactory == null) { meshFactory = mf.addMesh(textureKey); Material mat = MaterialFactory.createTextureMaterial(textureKey); int iMat = mf.addMaterial(mat); meshFactory.materialID = iMat; meshFactory.hasTexture = true; catchMesh.put(textureKey, meshFactory); } return meshFactory; } }
@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; }
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)); }
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; }
@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); }
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(); }