Browse Source

Set up the Microvision add-on

master
Fen Dweller 4 years ago
commit
6e1122ad04
9 changed files with 379 additions and 0 deletions
  1. +1
    -0
      .gitattributes
  2. +146
    -0
      .gitignore
  3. +3
    -0
      .gitmodules
  4. +8
    -0
      .vscode/settings.json
  5. +208
    -0
      __init__.py
  6. +6
    -0
      attribution.py
  7. +1
    -0
      blender_autocomplete
  8. BIN
      libs/Buildings.blend
  9. BIN
      libs/Vehicles.blend

+ 1
- 0
.gitattributes View File

@@ -0,0 +1 @@
*.blend filter=lfs diff=lfs merge=lfs -text

+ 146
- 0
.gitignore View File

@@ -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

+ 3
- 0
.gitmodules View File

@@ -0,0 +1,3 @@
[submodule "blender_autocomplete"]
path = blender_autocomplete
url = https://github.com/Korchy/blender_autocomplete

+ 8
- 0
.vscode/settings.json View File

@@ -0,0 +1,8 @@
{
"python.autoComplete.extraPaths": [
"./blender_autocomplete/2.92"
],
"python.analysis.extraPaths": [
"./blender_autocomplete/2.92"
]
}

+ 208
- 0
__init__.py View File

@@ -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)

+ 6
- 0
attribution.py View File

@@ -0,0 +1,6 @@
people = {
"chemicalcrux": {
"name": "chemicalcrux",
"url": "https://furaffinity.net/user/chemicalcrux/"
}
}

+ 1
- 0
blender_autocomplete

@@ -0,0 +1 @@
Subproject commit 0f10376548806cf1337c91e0e0e26973ebbe558b

BIN
libs/Buildings.blend (Stored with Git LFS) View File

oid sha256:2dff5707f76f37760551bff6b3bbc9518cb748906ca9f0e57045853877fce6b8
size 3135400

BIN
libs/Vehicles.blend (Stored with Git LFS) View File

oid sha256:d8e81ad0e7afb54a9fffe8c857b7e135a1f087cb820ea27806e2c4866b5020af
size 807160

Loading…
Cancel
Save