Skip to content

Commit

Permalink
update runtime, formatting code
Browse files Browse the repository at this point in the history
  • Loading branch information
Nokse22 committed Sep 18, 2024
1 parent c161dcf commit d62f89e
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 102 deletions.
2 changes: 1 addition & 1 deletion build-aux/io.github.nokse22.Exhibit.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "io.github.nokse22.Exhibit",
"runtime": "org.gnome.Platform",
"runtime-version": "46",
"runtime-version": "47",
"sdk": "org.gnome.Sdk",
"command": "exhibit",
"finish-args": [
Expand Down
16 changes: 13 additions & 3 deletions data/io.github.nokse22.Exhibit.metainfo.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,21 @@ You can use an HDRI image or a custom color as a background.</p>
</screenshots>

<releases>
<release version="1.3.2" date="2024-09-18">
<description translate="no">
<ul>
<li>Updated to GNOME 47</li>
<li>Removed octet-stream mime type</li>
</ul>
</description>
</release>
<release version="1.3.1" date="2024-09-04">
<description translate="no">
<p>Fixed Bugs</p>
<p>Added Russian Translation</p>
<p>Updated Translations</p>
<ul>
<li>Fixed Bugs</li>
<li>Added Russian Translation</li>
<li>Updated Translations</li>
</ul>
</description>
</release>
<release version="1.3.0" date="2024-07-31">
Expand Down
12 changes: 11 additions & 1 deletion src/vector_math.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,47 @@
import math


def p_dist(point1, point2):
if len(point1) != len(point2):
raise ValueError("Points must have the same dimension")

squared_diffs = [(x - y) ** 2 for x, y in zip(point1, point2)]
return math.sqrt(sum(squared_diffs))


def v_mod(vector):
return math.sqrt(sum([(x) ** 2 for x in vector]))


def v_abs(vector):
return tuple(abs(x) for x in vector)


def v_norm(vector):
norm = math.sqrt(sum(x**2 for x in vector))
return tuple(x / norm for x in vector)


def v_add(vector1, vector2):
return tuple(v1 + v2 for v1, v2 in zip(vector1, vector2))


def v_sub(vector1, vector2):
return tuple(v1 - v2 for v1, v2 in zip(vector1, vector2))


def v_mul(vector, scalar):
return tuple(v * scalar for v in vector)


def v_dot_p(vector1, vector2):
return tuple(v1 * v2 for v1, v2 in zip(vector1, vector2))


def v_cross(vector1, vector2):
if len(vector1) != 3 or len(vector2) != 3:
raise ValueError("Cross product is defined only for 3-dimensional vectors.")
raise ValueError(
"Cross product is defined only for 3-dimensional vectors.")

x = vector1[1] * vector2[2] - vector1[2] * vector2[1]
y = vector1[2] * vector2[0] - vector1[0] * vector2[2]
Expand Down
30 changes: 14 additions & 16 deletions src/widgets/f3d_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,11 @@
#
# SPDX-License-Identifier: GPL-3.0-or-later

import gi
from gi.repository import Adw
from gi.repository import Gtk, Gdk, Gio, GLib, GObject
from gi.repository import Gtk, Gdk, GLib

import f3d

import math

from ..vector_math import *
from .vector_math import p_dist, v_abs, v_norm, v_add, v_sub, v_mul, v_dot_p
from .. import logger_lib

up_dirs_vector = {
Expand All @@ -37,6 +33,7 @@
"+Z": (0.0, 0.0, 1.0)
}


@Gtk.Template(resource_path='/io/github/nokse22/Exhibit/ui/f3d_viewer.ui')
class F3DViewer(Gtk.GLArea):
__gtype_name__ = 'F3DViewer'
Expand All @@ -45,10 +42,10 @@ class F3DViewer(Gtk.GLArea):
"grid": "render.grid.enable",
"grid-absolute": "render.grid.absolute",
"translucency-support": "render.effect.translucency-support",
"tone-mapping":"render.effect.tone-mapping",
"tone-mapping": "render.effect.tone-mapping",
"ambient-occlusion": "render.effect.ambient-occlusion",
"anti-aliasing" :"render.effect.anti-aliasing",
"hdri-ambient" :"render.hdri.ambient",
"anti-aliasing": "render.effect.anti-aliasing",
"hdri-ambient": "render.hdri.ambient",
"hdri-skybox": "render.background.skybox",
"light-intensity": "render.light.intensity",
"orthographic": "scene.camera.orthographic",
Expand Down Expand Up @@ -83,7 +80,7 @@ class F3DViewer(Gtk.GLArea):
"grid-unit": "render.grid.unit",
"grid-subdivisions": "render.grid.subdivisions",
"grid-color": "render.grid.color",
"scalar" : "model.scivis.array-name"
"scalar": "model.scivis.array-name"
}

def __init__(self, *args):
Expand Down Expand Up @@ -138,7 +135,8 @@ def front_view(self, *args):
up_v = up_dirs_vector[self.settings["scene.up-direction"]]
vector = v_mul(tuple([up_v[2], up_v[0], up_v[1]]), 1000)
self.camera.position = v_add(self.camera.focal_point, vector)
self.camera.setViewUp(up_dirs_vector[self.settings["scene.up-direction"]])
self.camera.setViewUp(
up_dirs_vector[self.settings["scene.up-direction"]])
self.camera.resetToBounds()
self.get_distance()
self.queue_render()
Expand All @@ -147,7 +145,8 @@ def right_view(self, *args):
up_v = up_dirs_vector[self.settings["scene.up-direction"]]
vector = v_mul(tuple([up_v[1], up_v[2], up_v[0]]), 1000)
self.camera.position = v_add(self.camera.focal_point, vector)
self.camera.setViewUp(up_dirs_vector[self.settings["scene.up-direction"]])
self.camera.setViewUp(
up_dirs_vector[self.settings["scene.up-direction"]])
self.camera.resetToBounds()
self.get_distance()
self.queue_render()
Expand All @@ -166,7 +165,8 @@ def isometric_view(self, *args):
up_v = up_dirs_vector[self.settings["scene.up-direction"]]
vector = v_add(tuple([up_v[2], up_v[0], up_v[1]]), tuple([up_v[1], up_v[2], up_v[0]]))
self.camera.position = v_mul(v_norm(v_add(vector, up_v)), 1000)
self.camera.setViewUp(up_dirs_vector[self.settings["scene.up-direction"]])
self.camera.setViewUp(
up_dirs_vector[self.settings["scene.up-direction"]])
self.camera.resetToBounds()
self.get_distance()
self.queue_render()
Expand Down Expand Up @@ -265,7 +265,7 @@ def get_gimble_limit(self):
return self.distance / 10

def get_distance(self):
self.distance = p_dist(self.camera.position, (0,0,0))
self.distance = p_dist(self.camera.position, (0, 0, 0))

def pan(self, x, y, z):
val = self.distance / 40
Expand Down Expand Up @@ -360,5 +360,3 @@ def on_drag_update(self, gesture, x_offset, y_offset):
@Gtk.Template.Callback("on_drag_end")
def on_drag_end(self, gesture, *args):
self.drag_prev_offset = (0, 0)


Loading

0 comments on commit d62f89e

Please sign in to comment.