Code Monkey home page Code Monkey logo

up3date's Introduction

This add-on was originally developed by Konstantinos Mastorakis (konmast3r) as part of their research orientation project for the MSc Geomatics programme of TU Delft. Its functionality was further developed for the needs of their MSc thesis An integrative workflow for 3D city model versioning

I plan to keep developing this add-on as a free-time project since I enjoy it a lot and because I see that there are many enthusiasts out there already using it in ways more serious than I expected. Although I am very excited to see that, I can't guarantee how much and how often Up3date going to be further developed.

Up3date

A Blender add-on to import, edit and export new instances of CityJSON-encoded 3D city models. All buildings' levels of detail (LoD), attributes and semantic surfaces are stored and can be accesed via Blender's graphical interface.

Requirements

  • Blender Version >=2.80

Testing Datasets

You can find sample datasets at the official CityJSON website. In case you have 3D city model datasets encoded in CityGML you can use the free Conversion Tool to convert to and from CityGML and CityJSON and vice versa.

Trying to import really big datasets such as New York will take several minutes because of the amount of information contained. With the rest sample CityJSON files everything should work noticeably faster. Depending on your machine, it could take some seconds up to few minutes minute to import the 3D city model.

Installation

  1. Download this repository as zip (through GitHub this can be done through the Clone or download > Download ZIP button).

  2. Run Blender and go to Edit > Preferences > Add-ons and press the Install... button.

  3. Select the downloaded ZIP and press Install Add-on from File....

  4. Enable the add-on from the list, by ticking the empty box next to the add-on's name.
    (Optional: If you wish to update to a newer version, un-tick and tick again the add-on to reload it!)

Usage

Before you start!

  • For better understanding of the logic behind the add-on it is strongly recommended to have a quick (or thorough :-)) look on the CityJSON documentation if you are unfamiliar with it.

  • In case you run Blender through the console, useful feedback is given in it, informing about the progress of the import and export process. Upon importing and exporting from Blender it might prove quite useful since in the case of big files it can take up to several minutes. It will also print an error message in case of a crash, which is quite useful for debugging purposes.*
    *Important: Make sure Blender's viewport is in Object Mode before importing and exporting a CityJSON file.

Importing a 3D city model

Go to File > Import > CityJSON (.json) and navigate to the directory where the CityJSON file is stored and open it.

Options

The following options are available during file selection:

  • Materials' type:
    • Surfaces will create materials according to semantic surfaces (e.g. RoofSurface, WallSurface), if present, and load their attributes.
    • City Objects will create materials per city object and according to the city object's type (e.g. Building, Road).
  • Reuse materials: Enable this if you want semantic surface materials to be reused when they share the same type. For example, all RoofSurface faces will have the same materials. This only work when Surfaces are selected as Materials' type.
    *Important: Greatly improves speed of loading, but semantic surfaces' attributes can be lost, if present!
  • Clean scene: Enable this if you want the script to clean the scene of any existing object prior to importing the CityJSON objects.

Useful tips

  • After a successful import, you should be able to see the model somewhere close to the axis origin. Rotation of the scene and zooming in and out might help you, locating the model. In case you can't see the model, select an object from the Outliner* (always in Object Mode) and click View > Frame Selected or use the home button of your keyboard right after importing and try zooming in.
    *Important: Make sure the object you are selecting is a mesh object and not an empty object. You can check that from the small pointing down triangle icon next to the object's name.

  • A different Collection is created for each LoD present in the 3D city model. In case more than 1 geometry exists for the objects -representing different LODs (levels of detail)-, every geometry is stored under the appropriate Collection, under the parent CityObject. You can display different Collections by clicking on the eye icon in the Outliner at the top right of the interface (see screenshot below). By default all the LOD_x collections should be visible right after importing the 3D city model. In case you see any artefacts that is the reason! Choosing only one visible collection should remove all artifacts.

  • In case you want to visualize a certain area, click Shift + B and draw a rectangle with your mouse to zoom into that specific area of the 3D city model. This also moves the rotation center at that point, which will come handy when you want to inspect specific areas of the model.

  • To see the attributes of each object, simply select the object on the screen and click on the Object Properties tab on the bottom right of Blender's interface. Then click Custom Properties drop down menu (see screenshot below).

  • To see the semantics of each surface, select an object in Object Mode, hit TAB to toggle Edit Mode and click Face Select (top left of the viewport between the Edit Mode and the View button). Select a face of the object and click on the Material Properties tab at the bottom right. Scroll down and click on Custom Properties(see screenshot below).

Accessing the attributes of objects Accessing the semantics of LoD2 (or higher) geometries

  • Blender translates the 3D city model at the beginning of the axis upon importing. The translation parameters and the CRS are visible under the World Properties for transforming the coordinates back to original if needed.

The translation parameters with the CRS information

Exporting a 3D city model

Up3date's exporting module was desinged and implemented in order to be able to export any scene of Blender into a CityJSON file.

**To do so and because there are certain differences between the two data models (Blender and CityJSON) some conventions were made to allow lossless exporting. **

In order to export objects from Blender's scene the following steps need to be followed:

  1. For every LoD/geometry a Mesh object* has to be added into Blender's scene. In case there are already created Collections from a previously imported CityJSON file, it is not necessary to add the LoD/geometry into it, but recommended for organization purposes.

*Important: The mesh should be named in a predefined way for Up3date to be able to parse it correctly. Example: a LoD0 geometry should be named as 0: [LoD0] ID_of_object preserving also the spaces.

For every Mesh / geometry 2 more things needs to be added as Custom Properties for the exporter to work. You need to add them yourself after selecting the Mesh object in Object Mode, clicking on the Object Properties button (second screenshot of the documentation), expanding the Custom Properties and clicking the Add button to add a new Custom Property. After addition, edit the property by hitting the Edit button next to it. You only need to change Property Name and Property Value.

  • type: the_surface_type (Surface, MultiSurface, CompositeSurface and Solid are accepted)
  • lod : the_number_of_lod

Adding a new Mesh object with its necessary custom properties

  1. An Empty object representing the CityObject has to be created named as ID_of_object (should be exactly the same name as the Mesh described above without the 0: [LoD0] prefix). To rename any object just double-click on it in the Outliner and type a new name.
    This object will be the parent for the various LoD geometries that a CityObject might have. For any CityObject's (aka building's) attribute you wish to store, a new Custom Property has to be added to the Empty Object. You have to manually add them via Blender's graphical interface exactly the same way as described in step 1.
    In case the attributes have to be nested, for example the postal code of an address, then the Custom Property key should be address.postalcode so Up3date can understand the nested attribute structure from the . and handle it accordingly (see picture below).

Adding the parent Empty object (parent of the Mesh object) with (optional) custom properties

  1. If the semantics of a (LoD 2 or above) geometry surfaces are known and you want to add them, they can be assigned (again) as Custom Properties of Materials to the respective faces. For every Mesh / Geometry object Blender allows the creation of Materials. To assign semantics that will be exported in the CityJSON file, you will need to first create (a) new material(s) inside the newly added Mesh / Geometry object (just select the object in Object Mode and go to the Materials tab). If working with a pre-imported file, you can select an already existing material. Don't worry if the materials' names look like WallSurface.001 etc. The only information exported is the value of the Custom Property type of the material (i.e. the semantic).
    In the case of creating new materials you need to add a Custom Property to each one of them which must look like the following: type: Semantic_name (WallSurface, RoofSurface, GroundSurface etc) (see also picture below).
    After successfully adding the material(s) and the Custom Property, select the geometry in Object Mode, hit the tab button to swap to Edit Mode and click the Face Select button right next to the Edit Mode option (as explained under the 5th Useful tip in the section above).
    With the appropriate face selected select the appropriate material and hit the Assign button to link that material to the face.

Adding semantic information to an LoD2 (or higher) geometry surface

  1. Finally, go to File > Export > CityJSON (.json) and export the new instance. Voila!

Further Development

If you are using Visual Studio Code, you may:

  • Install Blender Development: a plugin that allows starting and debugging Python scripts from VSC.
  • Install the fake-bpy-module to enable auto-completion: pip install fake-bpy-module-2.80.

Clone this repository and have fun!

If you experience any bugs or have recommendations etc, you can open a new issue, providing all the necessary information. I can't promise to take them all under consideration but I always appreciate them.

up3date's People

Contributors

bertt avatar konmast3r avatar laurensjn avatar liberostelios avatar sambaas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

up3date's Issues

Using LOD subversion numbers problem in CityJSON output

Using LOD subversions gives a problem in the json output.
It looks like the part of the name is not stripped out properly (The two extra characters for the decimal character seem to be ignored when removing the '[LOD2.1]' part of the name.

{
    "type": "CityJSON",
    "version": "1.0",
    "metadata": {
        "geographicalExtent": [121578.775, 486020.60199999996, -4.7540000000000004, 121966.761, 486232.568, 309.487]
    },
    "CityObjects": {
        "] Cube": {
            "geometry": [{
                    "type": "MultiSurface",
                    "boundaries": [[[0, 1, 2, 3]], [[3, 2, 4, 5]], [[5, 4, 6, 7]], [[7, 6, 1, 0]], [[3, 5, 7, 0]], [[4, 2, 1, 6]]],
                    "lod": 2
                }
            ]
        },
        "Cube": {
            "geometry": [],
            "type": "Building"
        }
    },
    "vertices": [[236940.0, 60919.0, 163194.0], [236940.0, 60919.0, 314241.0], [236940.0, 211966.0, 314241.0], [236940.0, 211966.0, 163194.0], [387986.0, 211966.0, 314241.0], [387986.0, 211966.0, 163194.0], [387986.0, 60919.0, 314241.0], [387986.0, 60919.0, 163194.0]],
    "transform": {
        "scale": [0.001, 0.001, 0.001],
        "translate": [121578.775, 486020.60199999996, -4.7540000000000004]
    }
}

"Clean scene" option breaks in Blender 3.x

I have Blender 3.1.2 and the "Up3date-main" add-on is not able to import CityJSON files from 3D BAG

I keep getting the following error:

Python: Traceback (most recent call last):
  File "C:\Users\HP ZBook 15 G2\AppData\Roaming\Blender Foundation\Blender\3.1\scripts\addons\Up3date-main\__init__.py", line 72, in execute
    return parser.execute()
  File "C:\Users\HP ZBook 15 G2\AppData\Roaming\Blender Foundation\Blender\3.1\scripts\addons\Up3date-main\core\objects.py", line 138, in execute
    remove_scene_objects()
  File "C:\Users\HP ZBook 15 G2\AppData\Roaming\Blender Foundation\Blender\3.1\scripts\addons\Up3date-main\core\utils.py", line 21, in remove_scene_objects
    bpy.ops.object.delete()
  File "C:\Program Files\Blender Foundation\Blender 3.1\3.1\scripts\modules\bpy\ops.py", line 132, in __call__
    ret = _op_call(self.idname_py(), None, kw)
RuntimeError: Operator bpy.ops.object.delete.poll() failed, context is incorrectD

location: <unknown location>:-1

(Installation Workflow) Package doesn't import in Blender 3.3.7 LTS

By default, the following the current installation instructions simply leads to a paste of the contents of this repo inside the user-storage addons folder, which is not ideal for organising addons. If you have cloned the repo elsewhere, it won't even copy all the contents, just the __init__.py script.

If one decides to clone the repository (which should be the best way to use this fantastic project), the ideal way is to do so directly in the addons folder location. For Windows users, it's C:\Users\<USERNAME>\AppData\Roaming\Blender Foundation\Blender\<MAJOR_VERSION>.<MINOR_VERSION>\scripts\addons.

Export only selection

I am wondering if Up3date can export only selected object since I notice that the plugin work slower when export a lot of objects

Duplicate vertices checker makes export really slow

Using a model with 94.000 vertices, the exporter takes 74 seconds when the exporter checks for duplicate vertices. Without checking, it takes only 1.4 second. That's 70x faster. For bigger models the checker will probably be even worse.

What probably makes it slow is that it checks (1) each coordinate individually if it's already in a list; (2) it does not use any rounding. Another method should be considered that can make it faster, maybe similar to the CJIO remove_duplicate_vertices method (see here). That method also uses some rounding that would make it faster. On the model that is exported without checking for duplicate vertices I tried the CJIO method (with 12 decimals) and it was <1s.

Each face in multisurface gets assigned new semantic surface (material)

When using the export function, a new semantic material is assigned for each surface in a multisurface. This slows down exports a lot for triangulated surfaces.

Semantic surfaces should only be create once, with afterwards an element values that is an indexed list to the geometry boundaries:

image

Cant Export .stl to CityJSON

Hello,
I exported a 3D-Mesh from CloudCompare in .stl-format and imported it into blender. After changing geometry to origin I can see my model.

When I try to export it as cityJon I get the following error:
Python: Traceback (most recent call last):
File "C:\Users\felix\AppData\Roaming\Blender Foundation\Blender\4.0\scripts\addons\Up3date-main_init_.py", line 124, in execute
return exporter.execute()
File "C:\Users\felix\AppData\Roaming\Blender Foundation\Blender\4.0\scripts\addons\Up3date-main\core\objects.py", line 362, in execute
CityObject_id,object_verts,object_faces = self.create_mesh_structure(city_object,objid,init_json)
File "C:\Users\felix\AppData\Roaming\Blender Foundation\Blender\4.0\scripts\addons\Up3date-main\core\objects.py", line 276, in create_mesh_structure
print ("You either forgot to add lod as a custom property of the geometry, ", name, ", or 'lod' is not a number")
NameError: name 'name' is not defined

I already added lod as custom property but it is not working.

How to recover the original coordinates

It seems that the plugin (master branch) centers the objects around 0,0,0. I have a coordinate in the citymodel's original coordinate system which I want to locate in the model, how can I do that?

Can't export my blender model to .CityJSON

Hi Guys,

So i am working with Blender and trying to export it to .CityJSON.

At the moment i get this issue when i try to export my model.
I'm not the best at coding, tried looking at with by doing my own research and could not find a fix.
Could anybody help me or help me identify the issue?

image

Cannot view CityJSON file

Hello,

I am trying to view my CityJSON data file in blender using Up3date plug in, I have made some validation schemas and validation on geometry but my data cannot be visualize, some error have been appear as shown below

1
2
image

Am I missing any steps? or anything i have to change on my CityJSON file?

Support

Hi,
thanks for this great plugin.
I´ve got one problem and one support question.

my problem:
We are working with FME and FME can not read the CityJSON, the plugin is exporting.
The problem seems to that the values of semantics are in an inner array and an empty texture object exists.

does not working:
`"semantics":{
"surfaces":[
{
"type":"GroundSurface"
},
{
"type":"WallSurface"
},
{
"type":"RoofSurface"
}
],
"values":[
[ 0,
2,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1 ]
]
},
"texture":{

           },`

still working:
"semantics":{ "surfaces":[ { "type":"GroundSurface" }, { "type":"WallSurface" }, { "type":"RoofSurface" } ], "values":[ 0, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ] },
so i´ve changed and everything is working fine
#init_json["CityObjects"][CityObject_id]['geometry'].append({'type':city_object['type'],'boundaries':[],'semantics':{'surfaces': [], 'values': [[]]},'texture':{},'lod':city_object['lod']}) init_json["CityObjects"][CityObject_id]['geometry'].append({'type':city_object['type'],'boundaries':[],'semantics':{'surfaces': [], 'values': []},'lod':city_object['lod']})

So is that a general issue or is that only a problem of FME?

Support question:
Are you still working on the possibility to im- and export objects with textures?

best regards
Tim

Add colour menu for semantics

Hi!

Great plugin! I was wondering if you could add a color menu so I could modify the colours in different semantics within the CityJSON file?

Thank you!

Batch Import Files

Is there a way to load multiple cityjson files at once using a script. Any method I can use?
Thank you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.