Skip to content

Commit

Permalink
Remove assimp, use python gltf libs instead
Browse files Browse the repository at this point in the history
  • Loading branch information
vjf committed Oct 9, 2024
1 parent ed9c70c commit 2f83a25
Show file tree
Hide file tree
Showing 11 changed files with 1,078 additions and 435 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/build-models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,6 @@ jobs:
- name: Make boreholes
run: |
eval $(pdm venv activate for-backend-build)
# Temporarily, a patched version of assimp lives in the 'test' dir
# It was installed and built via 'pdm install'
ASSIMP_VER=5.4.3
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD/assimp-$ASSIMP_VER/bin
echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH"
pushd web_build
./make_boreholes.py -b batch.txt -d query_data.db boreholes
tar cvfz boreholes.tar.gz ./boreholes
Expand Down
6 changes: 0 additions & 6 deletions .github/workflows/build_backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ jobs:
- name: Make boreholes
run: |
eval $(pdm venv activate for-backend-build)
# NB: assimp was installed and built via 'pdm install'
ASSIMP_VER=5.4.3
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD/assimp-$ASSIMP_VER/bin
echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH"
pushd web_build
./make_boreholes.py -b batch.txt -d query_data.db boreholes
tar cvfz boreholes.tar.gz ./boreholes
Expand All @@ -63,5 +59,3 @@ jobs:
name: api.tar.gz
path: web_build/api.tar.gz
if-no-files-found: error


16 changes: 0 additions & 16 deletions build_assimp.sh

This file was deleted.

1,148 changes: 786 additions & 362 deletions pdm.lock

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
# PEP 621 project metadata
# See https://www.python.org/dev/peps/pep-0621/
dependencies = [
"numpy",
"numpy>=1.14",
"OWSLib",
"Pillow",
"pyassimp @ file:///${PROJECT_ROOT}/assimp-5.4.3/port/PyAssimp",
"pycollada",
"pyproj",
"SQLAlchemy",
Expand All @@ -17,14 +16,13 @@ dependencies = [
"uvicorn",
"wheel",
"pytest>=8.3.2",
"pygltflib>=1.16.2",
]
requires-python = ">=3.10"
requires-python = ">=3.9"

[build-system]
requires = ["pdm-backend"]
build-backend = "pdm.backend"

[tool.pdm]

[tool.pdm.scripts]
pre_install = "sh -c './build_assimp.sh'"
8 changes: 4 additions & 4 deletions scripts/lib/exports/bh_make.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from lib.coords import convert_coords
from nvcl_kit.reader import NVCLReader
from lib.exports.assimp_kit import AssimpKit
from lib.exports.gltf_kit import GltfKit
from nvcl_kit.generators import gen_scalar_by_depth
from nvcl_kit.constants import Scalar
from nvcl_kit.param_builder import param_builder
Expand Down Expand Up @@ -54,8 +54,8 @@ def get_blob_boreholes(borehole_dict, model_param_dict):

# If there's data, then create the borehole
if bh_data_dict != {}:
assimp_obj = AssimpKit(LOG_LVL)
blob_obj = assimp_obj.write_borehole(base_xyz, borehole_dict['name'],
gltf_kit = GlftKit(LOG_LVL)
blob_obj = gltf_kit.write_borehole(base_xyz, borehole_dict['name'],
bh_data_dict, height_res, '')
LOGGER.debug(f"Returning: blob_obj = {blob_obj}")
return blob_obj
Expand Down Expand Up @@ -86,7 +86,7 @@ def get_nvcl_data(reader, param_obj, output_crs, height_res, x, y, z, nvcl_id):
# Min1,2,3 = 1st, 2nd, 3rd most common mineral
# Grp1,2,3 = 1st, 2nd, 3rd most common group of minerals
# uTSAV = visible light, uTSAS = shortwave IR, uTSAT = thermal IR
for nvcl_id, log_id, sca_list in gen_scalar_by_depth(reader, nvcl_id_list=[nvcl_id], scalar_class=Scalar.Grp1_uTSAS, log_type='1'):
for nvcl_id, log_id, sca_list in gen_scalar_by_depth(reader, nvcl_id_list=[nvcl_id], scalar_class=Scalar.Grp1_uTSAS, log_type='1', resolution=height_res):
for depth in sca_list:
ret_dict[depth] = sca_list[depth]
return ret_dict, base_xyz
46 changes: 24 additions & 22 deletions scripts/lib/exports/geometry_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
'''
import math
from types import SimpleNamespace
import numpy as np
from lib.exports.bh_utils import make_borehole_label

def colour_borehole_gen(pos, borehole_name, colour_info_dict, ht_resol):
Expand All @@ -25,41 +26,42 @@ def colour_borehole_gen(pos, borehole_name, colour_info_dict, ht_resol):
'className': <measurement class> } \
mesh_name - used to label meshes during mesh generation (bytes object)
'''
bh_width = 10 # Width of stick
bh_width = 10.0 # Width of stick

# Convert bv to an equilateral triangle of floats
angl_rad = math.radians(30.0)
cos_flt = math.cos(angl_rad)
sin_flt = math.sin(angl_rad)
for colour_idx, (depth, colour_info) in enumerate(colour_info_dict.items()):
height = pos[2]+ht_resol-depth
pt_a_high = [pos[0], pos[1]+bh_width*cos_flt, height]
pt_b_high = [pos[0]+bh_width*cos_flt, pos[1]-bh_width*sin_flt, height]
pt_c_high = [pos[0]-bh_width*cos_flt, pos[1]-bh_width*sin_flt, height]
pt_a_low = [pos[0], pos[1]+bh_width*cos_flt, height-ht_resol]
pt_b_low = [pos[0]+bh_width*cos_flt, pos[1]-bh_width*sin_flt, height-ht_resol]
pt_c_low = [pos[0]-bh_width*cos_flt, pos[1]-bh_width*sin_flt, height-ht_resol]

vert_list = pt_a_high + pt_b_high + pt_c_high + pt_a_low + pt_c_low + pt_b_low

indices = [0, 2, 1,
3, 5, 4,
1, 2, 5,
2, 4, 5,
0, 4, 2,
0, 3, 4,
0, 1, 3,
1, 5, 3]
height = pos[2] + ht_resol - depth
pt_a_high = [pos[0], pos[1] + bh_width*cos_flt, height]
pt_b_high = [pos[0] + bh_width*cos_flt, pos[1] - bh_width*sin_flt, height]
pt_c_high = [pos[0] - bh_width*cos_flt, pos[1] - bh_width*sin_flt, height]
pt_a_low = [pos[0], pos[1] + bh_width*cos_flt, height - ht_resol]
pt_b_low = [pos[0] + bh_width*cos_flt, pos[1] - bh_width*sin_flt, height - ht_resol]
pt_c_low = [pos[0] - bh_width*cos_flt, pos[1] - bh_width*sin_flt, height - ht_resol]

vert_list = [pt_a_high, pt_b_high, pt_c_high, pt_a_low, pt_c_low, pt_b_low]

indices = [[0, 2, 1],
[3, 5, 4],
[1, 2, 5],
[2, 4, 5],
[0, 4, 2],
[0, 3, 4],
[0, 1, 3],
[1, 5, 3]]

mesh_name = make_borehole_label(borehole_name, depth)

# If there is missing colour and mineral information, then add blank one
if not isinstance(colour_info, SimpleNamespace):
if not isinstance(colour_info, list) or len(colour_info) < 1:
rgba_colour = (1.0, 1.0, 1.0, 1.0)
class_dict = { 'classText': 'unknown', 'className': 'unknown'}
else:
rgba_colour = colour_info.colour
class_dict = { 'classText': colour_info.classText, 'className': colour_info.className }
# NB: Only takes the colour of the most common mineral at that depth
rgba_colour = colour_info[0].colour
class_dict = { 'classText': colour_info[0].classText, 'className': colour_info[0].className }

yield vert_list, indices, colour_idx, depth, rgba_colour, class_dict, mesh_name

Expand Down
Loading

0 comments on commit 2f83a25

Please sign in to comment.