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