[Bf-extensions-cvs] [86f3b04e] master: sun_position originally from Michael Martin fixed for 2.78+ see https://developer.blender.org/T52117

Stephen Leger noreply at git.blender.org
Wed Jul 19 15:19:20 CEST 2017


Commit: 86f3b04e8379a6a8c8cbefec4898542381891250
Author: Stephen Leger
Date:   Wed Jul 19 14:53:32 2017 +0200
Branches: master
https://developer.blender.org/rBAC86f3b04e8379a6a8c8cbefec4898542381891250

sun_position originally from Michael Martin fixed for 2.78+ see https://developer.blender.org/T52117

===================================================================

A	sun_position/World.jpg
A	sun_position/__init__.py
A	sun_position/hdr.py
A	sun_position/map.py
A	sun_position/north.py
A	sun_position/operators.py
A	sun_position/properties.py
A	sun_position/sun_calc.py
A	sun_position/ui_sun.py

===================================================================

diff --git a/sun_position/World.jpg b/sun_position/World.jpg
new file mode 100644
index 00000000..84b37e3a
Binary files /dev/null and b/sun_position/World.jpg differ
diff --git a/sun_position/__init__.py b/sun_position/__init__.py
new file mode 100644
index 00000000..58e04587
--- /dev/null
+++ b/sun_position/__init__.py
@@ -0,0 +1,102 @@
+### BEGIN GPL LICENSE BLOCK #####
+#
+#  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 2
+#  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, write to the Free Software Foundation,
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+# --------------------------------------------------------------------------
+# The sun positioning algorithms are based on the National Oceanic
+# and Atmospheric Administration's (NOAA) Solar Position Calculator
+# which rely on calculations of Jean Meeus' book "Astronomical Algorithms."
+# Use of NOAA data and products are in the public domain and may be used
+# freely by the public as outlined in their policies at
+#               www.nws.noaa.gov/disclaimer.php
+# --------------------------------------------------------------------------
+# The world map images have been composited from two NASA images.
+# NASA's image use policy can be found at:
+# http://www.nasa.gov/audience/formedia/features/MP_Photo_Guidelines.html
+# --------------------------------------------------------------------------
+
+# <pep8 compliant>
+
+bl_info = {
+    "name": "Sun Position",
+    "author": "Michael Martin",
+    "version": (3, 0, 1),
+    "blender": (2, 6, 5),
+    "api": 53207,
+    "location": "World > Sun Position",
+    "description": "Show sun position with objects and/or sky texture",
+    "warning": "",
+    "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"
+    "Scripts/3D_interaction/Sun_Position",
+    "tracker_url": "https://projects.blender.org/tracker/"
+    "index.php?func=detail&aid=29714",
+    "category": "Lighting"}
+
+import bpy
+from . properties import *
+from . ui_sun import *
+from . map import SunPos_Help
+from . hdr import SunPos_HdrHelp
+
+############################################################################
+
+
+def register():
+    bpy.utils.register_class(SunPosSettings)
+    bpy.types.Scene.SunPos_property = (
+        bpy.props.PointerProperty(type=SunPosSettings,
+                                  name="Sun Position",
+                                  description="Sun Position Settings"))
+    bpy.utils.register_class(SunPosPreferences)
+    bpy.types.Scene.SunPos_pref_property = (
+        bpy.props.PointerProperty(type=SunPosPreferences,
+                                  name="Sun Position Preferences",
+                                  description="SP Preferences"))
+
+    bpy.utils.register_class(SunPos_OT_Controller)
+    bpy.utils.register_class(SunPos_OT_Preferences)
+    bpy.utils.register_class(SunPos_OT_PreferencesDone)
+    bpy.utils.register_class(SunPos_OT_DayRange)
+    bpy.utils.register_class(SunPos_OT_SetObjectGroup)
+    bpy.utils.register_class(SunPos_OT_ClearObjectGroup)
+    bpy.utils.register_class(SunPos_OT_TimePlace)
+    bpy.utils.register_class(SunPos_OT_Map)
+    bpy.utils.register_class(SunPos_OT_Hdr)
+    bpy.utils.register_class(SunPos_Panel)
+    bpy.utils.register_class(SunPos_OT_MapChoice)
+    bpy.utils.register_class(SunPos_Help)
+    bpy.utils.register_class(SunPos_HdrHelp)
+
+
+def unregister():
+    bpy.utils.unregister_class(SunPos_HdrHelp)
+    bpy.utils.unregister_class(SunPos_Help)
+    bpy.utils.unregister_class(SunPos_OT_MapChoice)
+    bpy.utils.unregister_class(SunPos_Panel)
+    bpy.utils.unregister_class(SunPos_OT_Hdr)
+    bpy.utils.unregister_class(SunPos_OT_Map)
+    bpy.utils.unregister_class(SunPos_OT_TimePlace)
+    bpy.utils.unregister_class(SunPos_OT_ClearObjectGroup)
+    bpy.utils.unregister_class(SunPos_OT_SetObjectGroup)
+    bpy.utils.unregister_class(SunPos_OT_DayRange)
+    bpy.utils.unregister_class(SunPos_OT_PreferencesDone)
+    bpy.utils.unregister_class(SunPos_OT_Preferences)
+    bpy.utils.unregister_class(SunPos_OT_Controller)
+    del bpy.types.Scene.SunPos_pref_property
+    bpy.utils.unregister_class(SunPosPreferences)
+    del bpy.types.Scene.SunPos_property
+    bpy.utils.unregister_class(SunPosSettings)
diff --git a/sun_position/hdr.py b/sun_position/hdr.py
new file mode 100644
index 00000000..731cf551
--- /dev/null
+++ b/sun_position/hdr.py
@@ -0,0 +1,935 @@
+# -*- coding: utf-8 -*-
+
+import bpy
+import bgl
+import blf
+import sys
+import os
+import math
+
+from . sun_calc import degToRad, radToDeg, format_hms
+from . properties import Display, Sun
+
+# ---------------------------------------------------------------------------
+
+
+class HdrObject:
+
+    class Origin:
+        x = 0
+        y = 0
+
+    def __init__(self, t, w, h):
+        self.type = t
+        self.width = w
+        self.height = h
+        self.heightFactor = .50
+        self.opacity = 1.0
+        self.focused = False
+        self.view3d_area = None
+        self.origin = self.Origin()
+
+    def set_dimensions(self, width):
+        self.width = width
+        self.height = int(width * self.heightFactor)
+
+    def check_focus(self, context, event):
+        self.focused = self.is_focused(context, event)
+        return self.focused
+
+    def is_focused(self, context, event):
+        if context.area != self.view3d_area:
+            return False
+
+        x = event.mouse_region_x
+        y = event.mouse_region_y
+
+        for reg in self.view3d_area.regions:
+            if reg.type == 'WINDOW':
+                if x < 0 or x > reg.width:
+                    return False
+                else:
+                    break
+
+        if x < self.origin.x or x > (self.origin.x + self.width) or \
+                y < self.origin.y or y > (self.origin.y + self.height) or \
+                y < 0 or y > reg.height:
+            return False
+        return True
+
+    def near_border(self, context, event):
+        if context.area != self.view3d_area:
+            return False
+
+        x = event.mouse_region_x
+        y = event.mouse_region_y
+
+        for reg in self.view3d_area.regions:
+            if reg.type == 'WINDOW':
+                if x < 20 or x > (reg.width - 20) or \
+                        y < 20 or y > (reg.height - 20):
+                    return True
+                else:
+                    break
+        return False
+
+
+# ---------------------------------------------------------------------------
+
+
+class HdrClass:
+
+    class mouse:
+        pass
+
+    class grab:
+
+        class spot:
+            pass
+
+        class offset:
+            pass
+
+    class zoom:
+        pass
+
+    class image:
+        pass
+
+    class last:
+        pass
+
+    def __init__(self):
+        self.handler1 = None
+        self.handler2 = None
+        self.view3d_area = None
+        self.draw_region = None
+        self.glImage = None
+        self.init_zoom_preference = True
+        self.reset()
+        self.last.filename = None
+        self.last.image = None
+        self.last.pixels = None
+        self.last.projection = None
+
+    def init(self):
+        self.object = [HdrObject('MAP', 0, 0), HdrObject('TEXT', 100, 160)]
+        self.object[0].set_dimensions(200)
+        self.object[1].origin.x = 10
+        self.object[1].origin.y = 80
+
+    def zoom_preferences(self, invert_zoom_wheel, invert_mouse_zoom):
+        self.init_zoom_preference = False
+        if invert_zoom_wheel:
+            self.zoom.wheel_up = 'OUT'
+            self.zoom.wheel_down = 'IN'
+        else:
+            self.zoom.wheel_up = 'IN'
+            self.zoom.wheel_down = 'OUT'
+        if invert_mouse_zoom:
+            self.zoom.mouse_up = 'IN'
+            self.zoom.mouse_down = 'OUT'
+        else:
+            self.zoom.mouse_up = 'OUT'
+            self.zoom.mouse_down = 'IN'
+
+    def reset(self):
+        self.init()
+        self.action = None
+        self.isActive = False
+        self.start = False
+        self.stop = False
+        self.lockCrosshair = True
+        self.elevation = 0.0
+        self.azimuth = 0.0
+        self.ctrlPress = False
+        self.altPress = False
+        self.mouse.x = 0
+        self.mouse.y = 0
+        self.grab.spot.x = 0
+        self.grab.spot.y = 0
+        self.grab.offset.x = 0
+        self.grab.offset.y = 0
+        self.zoom.width = 0
+        self.zoom.x = 0
+        self.zoom.y = 0
+        self.image.name = None
+        self.image.bindcode = 0
+        self.image.loaded = False
+        self.image.free_it = False
+
+    def clear_callbacks(self):
+        if self.handler2 is not None:
+            bpy.types.SpaceView3D.draw_handler_remove(self.handler2, 'WINDOW')
+            self.handler2 = None
+        if self.handler1 is not None:
+            bpy.types.SpaceView3D.draw_handler_remove(self.handler1, 'WINDOW')
+            self.handler1 = None
+
+    def set_view3d_area(self, area):
+        for obj in self.object:
+            obj.view3d_area = area
+
+    def activate(self, context):
+        if context.area.type == 'PROPERTIES':
+            self.reset()
+
+            def fw(self, context):
+                self.draw_region = context.region
+                areas = bpy.context.screen.areas
+                for area in areas:
+                    if area.type == 'VIEW_3D':
+                        self.view3d_area = context.area
+                        for reg in area.regions:
+                            if reg.type == 'WINDOW':
+                                self.draw_region = reg
+                                Display.refresh()
+

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list