Skip to content

Commit

Permalink
Add option to triangulate faces
Browse files Browse the repository at this point in the history
  • Loading branch information
LMesaric committed Aug 5, 2020
1 parent 9ce7176 commit dcc0a79
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Implementation/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*.pyc
*.blend[1-9]
venv/
blender_tester.py
zagrebgis.zip


# Created by https://www.gitignore.io/api/python,pycharm+all,unrealengine,visualstudiocode
Expand Down
2 changes: 1 addition & 1 deletion Implementation/ZagrebGIS/zagrebgis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"name": "Zagreb GIS",
"description": "Generates a Zagreb district model based on real data.",
"author": "Luka Mesarić",
"version": (1, 0),
"version": (1, 1),
"blender": (2, 82, 0),
"location": "View3D > Sidebar > ZagrebGIS Tab",
"tracker_url": "https://github.com/LMesaric/BSc-Thesis-FER-2020/issues",
Expand Down
34 changes: 34 additions & 0 deletions Implementation/ZagrebGIS/zagrebgis/triangulator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Zagreb GIS - Generate a Zagreb district model based on real data
# Copyright (C) 2020 Luka Mesarić ([email protected])
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.


import bpy


def triangulate_all():
"""
Converts all faces in all meshes in the scene to triangles.
"""

bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.mode_set(mode='EDIT')

bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.mesh.quads_convert_to_tris()
bpy.ops.mesh.select_all(action='DESELECT')

bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.select_all(action='DESELECT')
11 changes: 10 additions & 1 deletion Implementation/ZagrebGIS/zagrebgis/zagreb_gis.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from zagrebgis.terrain_creator import create_terrain
from zagrebgis.tree_creator import create_trees_many
from zagrebgis.tree_fetcher import get_all_trees
from zagrebgis.triangulator import triangulate_all


class VIEW3D_OT_ZagrebGIS(bpy.types.Operator):
Expand All @@ -41,6 +42,7 @@ class VIEW3D_OT_ZagrebGIS(bpy.types.Operator):
long_top_right: bpy.props.FloatProperty(options={'HIDDEN'})
terrain_height_scale: bpy.props.FloatProperty(options={'HIDDEN'})
add_trees_bool: bpy.props.BoolProperty(options={'HIDDEN'})
convert_to_tris: bpy.props.BoolProperty(options={'HIDDEN'})

def execute(self, context):
if not self._check_input():
Expand Down Expand Up @@ -86,7 +88,14 @@ def execute(self, context):
print(f'GIS INFO: Trees created --- {time.time() - start_time:.2f}s')

else:
print('Skipping generation of trees')
print('GIS INFO: Skipping generation of trees')

if self.convert_to_tris:
start_time = time.time()
triangulate_all()
print(f'GIS INFO: Triangulated all meshes --- {time.time() - start_time:.2f}s')
else:
print('GIS INFO: Skipping mesh triangulation')

self.report({'INFO'}, "Everything was successfully generated")
print(f'GIS INFO: Total runtime --- {time.time() - start_time_total:.2f}s')
Expand Down
7 changes: 7 additions & 0 deletions Implementation/ZagrebGIS/zagrebgis/zagreb_gis_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ def draw(self, context):

layout.row().prop(scene, "global_add_trees_bool", text="Generate trees")

layout.row().separator()

layout.row().prop(scene, "global_convert_to_tris", text="Use only triangles")

layout.row().separator()
layout.row().separator()

Expand All @@ -65,6 +69,7 @@ def draw(self, context):
props.long_top_right = scene.global_long_top_right
props.terrain_height_scale = scene.global_terrain_height_scale
props.add_trees_bool = scene.global_add_trees_bool
props.convert_to_tris = scene.global_convert_to_tris


def register():
Expand All @@ -76,11 +81,13 @@ def register():
s.global_long_top_right = FloatProperty(default=15.9742, min=-180.0, max=180.0, step=1, precision=6)
s.global_terrain_height_scale = FloatProperty(default=1, min=0, soft_max=3, step=1, precision=3)
s.global_add_trees_bool = BoolProperty(default=True)
s.global_convert_to_tris = BoolProperty(default=True)


# noinspection PyUnresolvedReferences
def unregister():
s = bpy.types.Scene
del s.global_convert_to_tris
del s.global_add_trees_bool
del s.global_terrain_height_scale
del s.global_long_top_right
Expand Down

0 comments on commit dcc0a79

Please sign in to comment.