From 6e1122ad046af1c072731cfbcc902619c9e0c97a Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Sat, 19 Jun 2021 09:53:24 -0400 Subject: [PATCH] Set up the Microvision add-on --- .gitattributes | 1 + .gitignore | 146 +++++++++++++++++++++++++++++ .gitmodules | 3 + .vscode/settings.json | 8 ++ __init__.py | 208 ++++++++++++++++++++++++++++++++++++++++++ attribution.py | 6 ++ blender_autocomplete | 1 + libs/Buildings.blend | 3 + libs/Vehicles.blend | 3 + 9 files changed, 379 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 .vscode/settings.json create mode 100644 __init__.py create mode 100644 attribution.py create mode 160000 blender_autocomplete create mode 100644 libs/Buildings.blend create mode 100644 libs/Vehicles.blend diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..80a1944 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.blend filter=lfs diff=lfs merge=lfs -text diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9ef476a --- /dev/null +++ b/.gitignore @@ -0,0 +1,146 @@ +*.blend1 + +# Created by https://www.toptal.com/developers/gitignore/api/python +# Edit at https://www.toptal.com/developers/gitignore?templates=python + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# End of https://www.toptal.com/developers/gitignore/api/python \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..f1c2a9a --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "blender_autocomplete"] + path = blender_autocomplete + url = https://github.com/Korchy/blender_autocomplete diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..194fd0e --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,8 @@ +{ + "python.autoComplete.extraPaths": [ + "./blender_autocomplete/2.92" + ], + "python.analysis.extraPaths": [ + "./blender_autocomplete/2.92" + ] +} \ No newline at end of file diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..8cb3631 --- /dev/null +++ b/__init__.py @@ -0,0 +1,208 @@ +import bpy +from bpy.props import CollectionProperty, EnumProperty, PointerProperty, StringProperty +from bpy.types import PropertyGroup +from . attribution import people + +bl_info = { + "name": "Microvision", + "description": "Size comparison, now in 3D!", + "version": (0, 1, 0), + "blender": (2, 80, 0), + "location": "View3D > Toolbar > Microvision", + "author": "chemicalcrux", + "category": "Development" +} + +class MicrovisionPerson(PropertyGroup): + id: StringProperty(name="Identifier") + +class MicrovisionSource(PropertyGroup): + url: StringProperty(name="URL") + +class MicrovisionAttribution(PropertyGroup): + authors: CollectionProperty(name="Authors", type=MicrovisionPerson) + owners: CollectionProperty(name="Owners", type=MicrovisionPerson) + sources: CollectionProperty(name="Owners", type=MicrovisionSource) + +class MicrovisionData(PropertyGroup): + attribution: PointerProperty(type=MicrovisionAttribution) + +class MicrovisionProperties(PropertyGroup): + def groups(self, context:bpy.types.Context): + results = [] + + if "Microvision Assets" in bpy.data.collections: + assets = bpy.data.collections["Microvision Assets"] + + for index, child in enumerate(assets.children): + results.append( + (child.name, child.name, "", "", index) + ) + + return results + + def kinds(self, context:bpy.types.Context): + results = [] + + if context.scene.micro.group: + assets = bpy.data.collections[context.scene.micro.group] + + for index, child in enumerate(assets.children): + results.append( + (child.name, child.name, "", "", index) + ) + + return results + + def objects(self, context:bpy.types.Context): + results = [] + + + if context.scene.micro.kind: + assets = bpy.data.collections[context.scene.micro.kind] + for index, child in enumerate(assets.children): + results.append( + (child.name, child.name, "", "", index) + ) + + return results + + group: EnumProperty( + name="Group", + items=groups, + description="What general kind of thing to browse", + default=None + ) + + kind: EnumProperty( + name="Kind", + items=kinds, + description="What specific kind of thing to browse", + default=None + ) + + object: EnumProperty( + name="Object", + items=objects, + description="The object to spawn", + default=None + ) + + +class LoadAssets(bpy.types.Operator): + bl_idname = "microvision.load_assets" + bl_label = "Load Assets" + + def execute(self, context: bpy.types.Context): + link_data(context) + + return {'FINISHED'} + +class Spawn(bpy.types.Operator): + bl_idname = "microvision.spawn" + bl_label = "Spawn" + + def execute(self, context: bpy.types.Context): + empty = bpy.data.objects.new(context.scene.micro.object, None) + + empty.instance_type = 'COLLECTION' + empty.instance_collection = bpy.data.collections[context.scene.micro.object] + empty.show_instancer_for_viewport = False + empty.show_instancer_for_render = False + + + context.scene.collection.objects.link(empty) + + + return {'FINISHED'} + +class MicrovisionAttributionPanel(bpy.types.Panel): + bl_idname = "OBJECT_PT_microvision_attribution_panel" + bl_label = "Attribution" + bl_space_type = "VIEW_3D" + bl_region_type = "UI" + bl_category = "Microvision" + bl_context = "objectmode" + + @classmethod + def poll(self, context): + if context.active_object is not None: + if context.active_object.instance_collection is not None: + return True + else: + return False + + def draw(self, context: bpy.types.Context): + layout = self.layout + scene = context.scene + + layout.label(text="Authors") + + for author in context.active_object.instance_collection.microvision.attribution.authors: + id = author.id + layout.operator('wm.url_open', text=people[id]["name"]).url=people[id]["url"] + +class MicrovisionPanel(bpy.types.Panel): + bl_idname = "OBJECT_PT_microvision_panel" + bl_label = "Microvision" + bl_space_type = "VIEW_3D" + bl_region_type = "UI" + bl_category = "Microvision" + bl_context = "objectmode" + + def draw(self, context: bpy.types.Context): + layout = self.layout + scene = context.scene + + layout.label(text="BIG TIME") + + layout.operator("microvision.load_assets") + + layout.prop(context.scene.micro, "group") + layout.prop(context.scene.micro, "kind") + layout.prop(context.scene.micro, "object") + + layout.operator("microvision.spawn") + +classes = [ + LoadAssets, + Spawn, + MicrovisionPerson, + MicrovisionSource, + MicrovisionPanel, + MicrovisionAttributionPanel, + MicrovisionAttribution, + MicrovisionData, + MicrovisionProperties, +] + +def link_data(context: bpy.types.Context): + top = bpy.data.collections.new(name="Microvision Assets") + context.view_layer.layer_collection.collection.children.link(top) + context.view_layer.layer_collection.children["Microvision Assets"].hide_viewport = True + for lib in ["Buildings", "Vehicles"]: + path = f"C:/Users/hausss/AppData/Roaming/Blender Foundation/Blender/2.93/scripts/addons/microvision/libs/{lib}.blend" + + category = bpy.data.collections.new(name=lib) + top.children.link(category) + with bpy.data.libraries.load(path, link=True) as (data_from, data_to): + data_to.collections = ["Assets"] + + print(len(data_to.collections[0].children)) + + for coll in data_to.collections[0].children: + print(coll) + if coll is not None: + category.children.link(coll) + +def register(): + print("Hi") + for cls in classes: + bpy.utils.register_class(cls) + bpy.types.Scene.micro = PointerProperty(type=MicrovisionProperties) + bpy.types.Collection.microvision = PointerProperty(type=MicrovisionData) + +def unregister(): + print("Bye") + for cls in classes: + bpy.utils.unregister_class(cls) \ No newline at end of file diff --git a/attribution.py b/attribution.py new file mode 100644 index 0000000..09a10a7 --- /dev/null +++ b/attribution.py @@ -0,0 +1,6 @@ +people = { + "chemicalcrux": { + "name": "chemicalcrux", + "url": "https://furaffinity.net/user/chemicalcrux/" + } +} \ No newline at end of file diff --git a/blender_autocomplete b/blender_autocomplete new file mode 160000 index 0000000..0f10376 --- /dev/null +++ b/blender_autocomplete @@ -0,0 +1 @@ +Subproject commit 0f10376548806cf1337c91e0e0e26973ebbe558b diff --git a/libs/Buildings.blend b/libs/Buildings.blend new file mode 100644 index 0000000..d6dc1d9 --- /dev/null +++ b/libs/Buildings.blend @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2dff5707f76f37760551bff6b3bbc9518cb748906ca9f0e57045853877fce6b8 +size 3135400 diff --git a/libs/Vehicles.blend b/libs/Vehicles.blend new file mode 100644 index 0000000..e3fed90 --- /dev/null +++ b/libs/Vehicles.blend @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d8e81ad0e7afb54a9fffe8c857b7e135a1f087cb820ea27806e2c4866b5020af +size 807160