From c51a492fe6459112bb280c7cbc1eacca36c6344f Mon Sep 17 00:00:00 2001 From: Jersonrn Date: Wed, 17 Jul 2024 15:10:49 -0500 Subject: [PATCH 1/2] Added camera settings --- makehuman/core/mhmain.py | 6 +- makehuman/lib/camera.py | 2 +- makehuman/plugins/5_settings_camera.py | 94 ++++++++++++++++++++++++++ 3 files changed, 99 insertions(+), 3 deletions(-) create mode 100644 makehuman/plugins/5_settings_camera.py diff --git a/makehuman/core/mhmain.py b/makehuman/core/mhmain.py index e36f8780..41d0e8c2 100644 --- a/makehuman/core/mhmain.py +++ b/makehuman/core/mhmain.py @@ -317,8 +317,8 @@ def onModified(event): self.updateFilenameCaption() #self.modelCamera = mh.Camera() - #self.modelCamera.switchToOrtho() self.modelCamera = mh.OrbitalCamera() + self.modelCamera.switchToOrtho() #self.modelCamera.debug = True @self.modelCamera.mhEvent @@ -731,7 +731,9 @@ def _updateBackgroundDimensions(self, width=G.windowWidth, height=G.windowHeight height = cam.getScale() aspect = cam.getAspect() width = height * aspect - self.backgroundGradient.mesh.resize(2.1*width, 2.1*height) + factor = 2.1 if cam._projection == 0 else 16.1 + + self.backgroundGradient.mesh.resize(factor*width, factor*height) self.backgroundGradient.setPosition([0, 0, -0.85*cam.farPlane]) diff --git a/makehuman/lib/camera.py b/makehuman/lib/camera.py index 854d08b4..cc1ad292 100644 --- a/makehuman/lib/camera.py +++ b/makehuman/lib/camera.py @@ -446,7 +446,7 @@ def __init__(self): self.scaleTranslations = True # Enable to make translations depend on zoom factor (only work when zoomed in) # Ortho mode - self._projection = 0 # TODO properly test with projection mode as well + self._projection = 1 # TODO properly test with projection mode as well self._horizontalRotation = 0.0 self._verticalInclination = 0.0 diff --git a/makehuman/plugins/5_settings_camera.py b/makehuman/plugins/5_settings_camera.py new file mode 100644 index 00000000..d16833b9 --- /dev/null +++ b/makehuman/plugins/5_settings_camera.py @@ -0,0 +1,94 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +""" +**Project Name:** MakeHuman + +**Product Home Page:** http://www.makehumancommunity.org/ + +**Github Code Home Page:** https://github.com/makehumancommunity/ + +**Authors:** Joel Palmius, Marc Flerackers + +**Copyright(c):** MakeHuman Team 2001-2020 + +**Licensing:** AGPL3 + + This file is part of MakeHuman (www.makehumancommunity.org). + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero 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 Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + + +Abstract +-------- + +TODO +""" + + +import gui3d +import mh +import gui + + +class CameraActionsTaskView(gui3d.TaskView): + def __init__(self, category) -> None: + super().__init__(self, category, 'Camera') + + self.cameraBox = self.addLeftWidget(gui.GroupBox('Camera')) + + + self.orthogonal = self.cameraBox.addWidget( + gui.CheckBox( + label = "Orthogonal/Perspective", + selected = True if gui3d.app.modelCamera.getProjection() == 0 else False + ) + ) + + self.fovAngle = self.cameraBox.addWidget( + gui.Slider( + value = gui3d.app.modelCamera.getFovAngle(), + min = 1, max = 171, + label = ["Fov Angle",": %d"] + ) + ) + + + @self.orthogonal.mhEvent + def onClicked(event): + if self.orthogonal.selected == True: + gui3d.app.modelCamera.switchToOrtho() + else: + gui3d.app.modelCamera.switchToPerspective() + + + @self.fovAngle.mhEvent + def onChange(value): + gui3d.app.modelCamera.setFovAngle(value) + + def onShow(self, event): + gui3d.TaskView.onShow(self, event) + # gui3d.app.statusPersist("Change camera settings") + + def onHide(self, event): + # gui3d.app.statusPersist("") + gui3d.TaskView.onHide(self, event) + + +def load(app): + category = app.getCategory('Settings') + taskview = category.addTask(CameraActionsTaskView(category)) + +def unload(app): + pass From d239d9c0a3dd86ddf6f6e8a1bac07aa9df1436b5 Mon Sep 17 00:00:00 2001 From: Jersonrn Date: Sun, 18 Aug 2024 15:29:24 -0500 Subject: [PATCH 2/2] Added zoom for perspective mode --- makehuman/core/mhmain.py | 2 +- makehuman/lib/camera.py | 91 +++++++++++++++++++++++++++++----------- 2 files changed, 68 insertions(+), 25 deletions(-) diff --git a/makehuman/core/mhmain.py b/makehuman/core/mhmain.py index 41d0e8c2..3f2c1399 100644 --- a/makehuman/core/mhmain.py +++ b/makehuman/core/mhmain.py @@ -731,7 +731,7 @@ def _updateBackgroundDimensions(self, width=G.windowWidth, height=G.windowHeight height = cam.getScale() aspect = cam.getAspect() width = height * aspect - factor = 2.1 if cam._projection == 0 else 16.1 + factor = 2.1 if cam._projection == 0 else 79.1 self.backgroundGradient.mesh.resize(factor*width, factor*height) diff --git a/makehuman/lib/camera.py b/makehuman/lib/camera.py index cc1ad292..7033de13 100644 --- a/makehuman/lib/camera.py +++ b/makehuman/lib/camera.py @@ -36,6 +36,7 @@ TODO """ +from logging import setLogRecordFactory import math import numpy as np @@ -441,6 +442,9 @@ def __init__(self): self.radius = 1.0 self._fovAngle = 90.0 + self.minRadius = 10 + self.maxRadius = 20 + self.fixedRadius = False self.noAutoScale = False self.scaleTranslations = True # Enable to make translations depend on zoom factor (only work when zoomed in) @@ -567,7 +571,9 @@ def updateCamera(self): maxDistance = math.sqrt( -distances[ np.argsort(distances)[0] ] ) # Set radius as max distance from bounding box - self.radius = maxDistance + 1 + self.minRadius = maxDistance + self.maxRadius = maxDistance + 10 + self.radius = maxDistance + 1 if not self.projection else self.radius if self.debug: import log @@ -654,36 +660,73 @@ def setZoomFactor(self, zoomFactor): else: self.zoomFactor = zoomFactor + def setRadius(self, radius): + if radius < self.minRadius: + self.radius = self.minRadius + elif radius > self.maxRadius: + self.radius = self.maxRadius + else: + self.radius = radius + def addZoom(self, amount): self.setZoomFactor(self.zoomFactor - (amount/4.0)) if self.debug: import log log.debug("OrbitalCamera zoom: %s", self.zoomFactor) - if self.pickedPos is not None: - if not self.scaleTranslations and -amount < 0.0: - amount = abs(amount) / max(1.0, min(5.0, self.zoomFactor)) - for i in range(3): - if self.translation[i] < 0.0: - self.translation[i] += amount - self.translation[i] = min(self.translation[i], 0.0) - elif self.translation[i] > 0.0: - self.translation[i] -= amount - self.translation[i] = max(self.translation[i], 0.0) + if not self.projection: + if self.pickedPos is not None: + if not self.scaleTranslations and -amount < 0.0: + amount = abs(amount) / max(1.0, min(5.0, self.zoomFactor)) + for i in range(3): + if self.translation[i] < 0.0: + self.translation[i] += amount + self.translation[i] = min(self.translation[i], 0.0) + elif self.translation[i] > 0.0: + self.translation[i] -= amount + self.translation[i] = max(self.translation[i], 0.0) + else: + #amount = abs(amount/4.0) + #amount = abs(amount) / self.zoomFactor + amount = abs(amount) / max(1.0, min(5.0, self.zoomFactor)) + #amount = abs(amount) / max(1.0, 0.3 * self.zoomFactor) + for i in range(3): + if self.translation[i] < self.pickedPos[i]: + self.translation[i] += amount + self.translation[i] = min(self.translation[i], self.pickedPos[i]) + elif self.translation[i] > self.pickedPos[i]: + self.translation[i] -= amount + self.translation[i] = max(self.translation[i], self.pickedPos[i]) + if self.pickedPos == self.translation: + self.pickedPos = None + + else: + x, y, z = 0, 1, 2 + + dir = np.array([ + self.pickedPos[x] - self.translation[x], + self.pickedPos[y] - self.translation[y], + self.pickedPos[z] - self.translation[z], + ]) if self.pickedPos else 0.2 + + # rot, incl = getRotationForDirection(dir) + + if isinstance(self.translation, list): + self.translation = np.array(self.translation) + + if amount > 0: + pos = self._getTranslationForPosition(self.translation + dir) else: - #amount = abs(amount/4.0) - #amount = abs(amount) / self.zoomFactor - amount = abs(amount) / max(1.0, min(5.0, self.zoomFactor)) - #amount = abs(amount) / max(1.0, 0.3 * self.zoomFactor) - for i in range(3): - if self.translation[i] < self.pickedPos[i]: - self.translation[i] += amount - self.translation[i] = min(self.translation[i], self.pickedPos[i]) - elif self.translation[i] > self.pickedPos[i]: - self.translation[i] -= amount - self.translation[i] = max(self.translation[i], self.pickedPos[i]) - if self.pickedPos == self.translation: - self.pickedPos = None + pos = self._getTranslationForPosition(self.translation - dir) + + self.setRadius(self.radius + amount) + self.setPosition(pos) + + #Update + G.app.redraw() + G.app.processEvents() + + self.changed() def getMatrices(self, eye=None):