2011-03-18 23:58:13 +00:00
|
|
|
# ##### 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 #####
|
|
|
|
|
|
|
|
# <pep8 compliant>
|
|
|
|
|
|
|
|
# simple script to enable all addons, and disable
|
|
|
|
|
2015-01-21 01:56:30 +00:00
|
|
|
"""
|
|
|
|
./blender.bin --background -noaudio --factory-startup --python tests/python/bl_load_py_modules.py
|
|
|
|
"""
|
|
|
|
|
2011-03-18 23:58:13 +00:00
|
|
|
import bpy
|
|
|
|
import addon_utils
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
|
2013-02-13 14:11:04 +00:00
|
|
|
BLACKLIST = {
|
|
|
|
"bl_i18n_utils",
|
2015-08-23 16:55:40 +00:00
|
|
|
"bl_previews_utils",
|
2013-02-13 14:11:04 +00:00
|
|
|
"cycles",
|
|
|
|
"io_export_dxf", # TODO, check on why this fails
|
2015-01-21 01:56:30 +00:00
|
|
|
'io_import_dxf', # Because of cydxfentity.so dependency
|
2017-06-19 13:28:28 +00:00
|
|
|
|
2019-09-08 13:16:07 +00:00
|
|
|
# Utility scripts not meant to be used as modules
|
|
|
|
os.path.join("power_sequencer", "scripts"),
|
2017-06-19 13:28:28 +00:00
|
|
|
# The unpacked wheel is only loaded when actually used, not directly on import:
|
2017-07-14 07:53:20 +00:00
|
|
|
os.path.join("io_blend_utils", "blender_bam-unpacked.whl"),
|
2018-07-03 04:47:49 +00:00
|
|
|
}
|
2013-02-13 14:11:04 +00:00
|
|
|
|
2019-04-18 19:11:40 +00:00
|
|
|
for mod in addon_utils.modules():
|
|
|
|
if addon_utils.module_bl_info(mod)['blender'] < (2, 80, 0):
|
|
|
|
BLACKLIST.add(mod.__name__)
|
|
|
|
|
2016-05-02 11:01:10 +00:00
|
|
|
# Some modules need to add to the `sys.path`.
|
|
|
|
MODULE_SYS_PATHS = {
|
|
|
|
# Runs in a Python subprocess, so its expected its basedir can be imported.
|
|
|
|
"io_blend_utils.blendfile_pack": ".",
|
2018-07-03 04:47:49 +00:00
|
|
|
}
|
2016-05-02 11:01:10 +00:00
|
|
|
|
2015-09-22 17:34:37 +00:00
|
|
|
if not bpy.app.build_options.freestyle:
|
|
|
|
BLACKLIST.add("render_freestyle_svg")
|
|
|
|
|
VR: Initial Virtual Reality support - Milestone 1, Scene Inspection
NOTE: While most of the milestone 1 goals are there, a few smaller features and
improvements are still to be done.
Big picture of this milestone: Initial, OpenXR-based virtual reality support
for users and foundation for advanced use cases.
Maniphest Task: https://developer.blender.org/T71347
The tasks contains more information about this milestone.
To be clear: This is not a feature rich VR implementation, it's focused on the
initial scene inspection use case. We intentionally focused on that, further
features like controller support are part of the next milestone.
- How to use?
Instructions on how to use this are here:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/How_to_Test
These will be updated and moved to a more official place (likely the manual) soon.
Currently Windows Mixed Reality and Oculus devices are usable. Valve/HTC
headsets don't support the OpenXR standard yet and hence, do not work with this
implementation.
---------------
This is the C-side implementation of the features added for initial VR
support as per milestone 1. A "VR Scene Inspection" Add-on will be
committed separately, to expose the VR functionality in the UI. It also
adds some further features for milestone 1, namely a landmarking system
(stored view locations in the VR space)
Main additions/features:
* Support for rendering viewports to an HMD, with good performance.
* Option to sync the VR view perspective with a fully interactive,
regular 3D View (VR-Mirror).
* Option to disable positional tracking. Keeps the current position (calculated
based on the VR eye center pose) when enabled while a VR session is running.
* Some regular viewport settings for the VR view
* RNA/Python-API to query and set VR session state information.
* WM-XR: Layer tying Ghost-XR to the Blender specific APIs/data
* wmSurface API: drawable, non-window container (manages Ghost-OpenGL and GPU
context)
* DNA/RNA for management of VR session settings
* `--debug-xr` and `--debug-xr-time` commandline options
* Utility batch & config file for using the Oculus runtime on Windows.
* Most VR data is runtime only. The exception is user settings which are saved
to files (`XrSessionSettings`).
* VR support can be disabled through the `WITH_XR_OPENXR` compiler flag.
For architecture and code documentation, see
https://wiki.blender.org/wiki/Source/Interface/XR.
---------------
A few thank you's:
* A huge shoutout to Ray Molenkamp for his help during the project - it would
have not been that successful without him!
* Sebastian Koenig and Simeon Conzendorf for testing and feedback!
* The reviewers, especially Brecht Van Lommel!
* Dalai Felinto for pushing and managing me to get this done ;)
* The OpenXR working group for providing an open standard. I think we're the
first bigger application to adopt OpenXR. Congratulations to them and
ourselves :)
This project started as a Google Summer of Code 2019 project - "Core Support of
Virtual Reality Headsets through OpenXR" (see
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/).
Some further information, including ideas for further improvements can be found
in the final GSoC report:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/Final_Report
Differential Revisions: D6193, D7098
Reviewed by: Brecht Van Lommel, Jeroen Bakker
2020-03-17 19:20:55 +00:00
|
|
|
if not bpy.app.build_options.xr_openxr:
|
|
|
|
BLACKLIST.add("viewport_vr_preview")
|
|
|
|
|
2015-01-21 01:56:30 +00:00
|
|
|
BLACKLIST_DIRS = (
|
|
|
|
os.path.join(bpy.utils.resource_path('USER'), "scripts"),
|
2018-07-03 04:47:49 +00:00
|
|
|
) + tuple(addon_utils.paths()[1:])
|
2015-01-21 01:56:30 +00:00
|
|
|
|
|
|
|
|
2016-05-02 11:01:10 +00:00
|
|
|
def module_names_recursive(mod_dir, *, parent=None):
|
|
|
|
"""
|
|
|
|
a version of bpy.path.module_names that includes non-packages
|
|
|
|
"""
|
|
|
|
|
|
|
|
is_package = os.path.exists(os.path.join(mod_dir, "__init__.py"))
|
|
|
|
|
|
|
|
for n in os.listdir(mod_dir):
|
|
|
|
if not n.startswith((".", "_")):
|
|
|
|
submod_full = os.path.join(mod_dir, n)
|
|
|
|
if os.path.isdir(submod_full):
|
|
|
|
if not parent:
|
|
|
|
subparent = n
|
|
|
|
else:
|
|
|
|
subparent = parent + "." + n
|
|
|
|
yield from module_names_recursive(submod_full, parent=subparent)
|
|
|
|
elif n.endswith(".py") and is_package is False:
|
|
|
|
submod = n[:-3]
|
|
|
|
if parent:
|
|
|
|
submod = parent + "." + submod
|
|
|
|
yield submod, submod_full
|
|
|
|
|
|
|
|
|
|
|
|
def module_names_all(mod_dir):
|
|
|
|
yield from bpy.path.module_names(mod_dir)
|
|
|
|
yield from module_names_recursive(mod_dir)
|
|
|
|
|
|
|
|
|
2011-03-18 23:58:13 +00:00
|
|
|
def source_list(path, filename_check=None):
|
|
|
|
from os.path import join
|
|
|
|
for dirpath, dirnames, filenames in os.walk(path):
|
2017-08-23 05:36:39 +00:00
|
|
|
# skip '.git'
|
|
|
|
dirnames[:] = [d for d in dirnames if not d.startswith(".")]
|
2011-03-18 23:58:13 +00:00
|
|
|
|
|
|
|
for filename in filenames:
|
|
|
|
filepath = join(dirpath, filename)
|
|
|
|
if filename_check is None or filename_check(filepath):
|
|
|
|
yield filepath
|
|
|
|
|
|
|
|
|
|
|
|
def load_modules():
|
2017-08-09 07:42:03 +00:00
|
|
|
VERBOSE = os.environ.get("BLENDER_VERBOSE") is not None
|
|
|
|
|
2011-03-18 23:58:13 +00:00
|
|
|
modules = []
|
|
|
|
module_paths = []
|
|
|
|
|
|
|
|
# paths blender stores scripts in.
|
|
|
|
paths = bpy.utils.script_paths()
|
|
|
|
|
2011-06-09 16:20:00 +00:00
|
|
|
print("Paths:")
|
|
|
|
for script_path in paths:
|
|
|
|
print("\t'%s'" % script_path)
|
|
|
|
|
2011-03-18 23:58:13 +00:00
|
|
|
#
|
|
|
|
# find all sys.path we added
|
|
|
|
for script_path in paths:
|
|
|
|
for mod_dir in sys.path:
|
|
|
|
if mod_dir.startswith(script_path):
|
2015-01-21 01:56:30 +00:00
|
|
|
if not mod_dir.startswith(BLACKLIST_DIRS):
|
|
|
|
if mod_dir not in module_paths:
|
|
|
|
if os.path.exists(mod_dir):
|
|
|
|
module_paths.append(mod_dir)
|
2011-03-18 23:58:13 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# collect modules from our paths.
|
2013-02-13 14:11:04 +00:00
|
|
|
module_names = {}
|
2011-03-18 23:58:13 +00:00
|
|
|
for mod_dir in module_paths:
|
|
|
|
# print("mod_dir", mod_dir)
|
|
|
|
for mod, mod_full in bpy.path.module_names(mod_dir):
|
2013-02-13 14:11:04 +00:00
|
|
|
if mod in BLACKLIST:
|
|
|
|
continue
|
2011-06-09 16:20:00 +00:00
|
|
|
if mod in module_names:
|
2013-02-13 14:11:04 +00:00
|
|
|
mod_dir_prev, mod_full_prev = module_names[mod]
|
|
|
|
raise Exception("Module found twice %r.\n (%r -> %r, %r -> %r)" %
|
|
|
|
(mod, mod_dir, mod_full, mod_dir_prev, mod_full_prev))
|
2011-06-09 16:20:00 +00:00
|
|
|
|
2011-03-18 23:58:13 +00:00
|
|
|
modules.append(__import__(mod))
|
|
|
|
|
2013-02-13 14:11:04 +00:00
|
|
|
module_names[mod] = mod_dir, mod_full
|
2011-06-09 16:20:00 +00:00
|
|
|
del module_names
|
|
|
|
|
2017-08-09 07:42:03 +00:00
|
|
|
#
|
|
|
|
# test we tested all files except for presets and templates
|
|
|
|
ignore_paths = [
|
|
|
|
os.sep + "presets" + os.sep,
|
2019-04-18 19:11:40 +00:00
|
|
|
os.sep + "templates_osl" + os.sep,
|
|
|
|
os.sep + "templates_py" + os.sep,
|
|
|
|
os.sep + "bl_app_templates_system" + os.sep,
|
2017-08-09 07:42:03 +00:00
|
|
|
] + ([(os.sep + f + os.sep) for f in BLACKLIST] +
|
2018-07-03 04:47:49 +00:00
|
|
|
[(os.sep + f + ".py") for f in BLACKLIST])
|
2017-08-09 07:42:03 +00:00
|
|
|
|
2011-03-18 23:58:13 +00:00
|
|
|
#
|
|
|
|
# now submodules
|
|
|
|
for m in modules:
|
|
|
|
filepath = m.__file__
|
|
|
|
if os.path.basename(filepath).startswith("__init__."):
|
|
|
|
mod_dir = os.path.dirname(filepath)
|
2016-05-02 11:01:10 +00:00
|
|
|
for submod, submod_full in module_names_all(mod_dir):
|
2011-03-18 23:58:13 +00:00
|
|
|
# fromlist is ignored, ugh.
|
|
|
|
mod_name_full = m.__name__ + "." + submod
|
2016-05-02 11:01:10 +00:00
|
|
|
|
|
|
|
sys_path_back = sys.path[:]
|
|
|
|
|
|
|
|
sys.path.extend([
|
|
|
|
os.path.normpath(os.path.join(mod_dir, f))
|
|
|
|
for f in MODULE_SYS_PATHS.get(mod_name_full, ())
|
2018-07-03 04:47:49 +00:00
|
|
|
])
|
2016-05-02 11:01:10 +00:00
|
|
|
|
2017-07-25 09:38:33 +00:00
|
|
|
try:
|
|
|
|
__import__(mod_name_full)
|
|
|
|
mod_imp = sys.modules[mod_name_full]
|
|
|
|
|
|
|
|
sys.path[:] = sys_path_back
|
|
|
|
|
|
|
|
# check we load what we ask for.
|
|
|
|
assert(os.path.samefile(mod_imp.__file__, submod_full))
|
|
|
|
|
|
|
|
modules.append(mod_imp)
|
2018-11-25 22:26:15 +00:00
|
|
|
except Exception:
|
2017-07-25 09:38:33 +00:00
|
|
|
import traceback
|
|
|
|
# Module might fail to import, but we don't want whole test to fail here.
|
|
|
|
# Reasoning:
|
|
|
|
# - This module might be in ignored list (for example, preset or template),
|
|
|
|
# so failing here will cause false-positive test failure.
|
|
|
|
# - If this is module which should not be ignored, it is not added to list
|
|
|
|
# of successfully loaded modules, meaning the test will catch this
|
|
|
|
# import failure.
|
|
|
|
# - We want to catch all failures of this script instead of stopping on
|
|
|
|
# a first big failure.
|
2017-08-09 07:42:03 +00:00
|
|
|
do_print = True
|
|
|
|
if not VERBOSE:
|
|
|
|
for ignore in ignore_paths:
|
|
|
|
if ignore in submod_full:
|
|
|
|
do_print = False
|
|
|
|
break
|
|
|
|
if do_print:
|
|
|
|
traceback.print_exc()
|
2011-03-18 23:58:13 +00:00
|
|
|
|
|
|
|
#
|
2013-01-19 03:04:51 +00:00
|
|
|
# check which filepaths we didn't load
|
2011-03-18 23:58:13 +00:00
|
|
|
source_files = []
|
|
|
|
for mod_dir in module_paths:
|
|
|
|
source_files.extend(source_list(mod_dir, filename_check=lambda f: f.endswith(".py")))
|
|
|
|
|
|
|
|
source_files = list(set(source_files))
|
|
|
|
source_files.sort()
|
|
|
|
|
|
|
|
#
|
|
|
|
# remove loaded files
|
|
|
|
loaded_files = list({m.__file__ for m in modules})
|
|
|
|
loaded_files.sort()
|
|
|
|
|
|
|
|
for f in loaded_files:
|
|
|
|
source_files.remove(f)
|
|
|
|
|
|
|
|
for f in source_files:
|
|
|
|
for ignore in ignore_paths:
|
|
|
|
if ignore in f:
|
2017-06-19 13:25:58 +00:00
|
|
|
break
|
|
|
|
else:
|
2011-03-18 23:58:13 +00:00
|
|
|
raise Exception("Source file %r not loaded in test" % f)
|
|
|
|
|
|
|
|
print("loaded %d modules" % len(loaded_files))
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
load_modules()
|
|
|
|
|
2018-07-03 04:47:49 +00:00
|
|
|
|
2011-03-18 23:58:13 +00:00
|
|
|
if __name__ == "__main__":
|
2020-04-27 15:43:47 +00:00
|
|
|
main()
|