Commit 648ac7c6 authored by Adrien Vigné's avatar Adrien Vigné
Browse files

update blender script

parent 5e26292e
import bpy
import json
argRefObject = "IKEA_console_HEMNES"
argCollectionCube = "director_task_cubes"
argCollectionBox = "director_task"
dictCollections = {}
dictObjects = {}
collectionCube = None
collectionBox = None
delta = 0.1 # marge pour prendre en compte les objets
def overObjectRef(objectRef,object):
centerObjectRef = objectRef.location
dimObjectRef = objectRef.dimensions
xminObjectRef = centerObjectRef.x - dimObjectRef.x/2 - delta
xmaxObjectRef = centerObjectRef.x + dimObjectRef.x/2 + delta
yminObjectRef = centerObjectRef.y - dimObjectRef.y/2 - delta
ymaxObjectRef = centerObjectRef.y + dimObjectRef.y/2 + delta
zminObjectRef = centerObjectRef.z + dimObjectRef.z/2 - delta
zmaxObjectRef = centerObjectRef.z + dimObjectRef.z/2 + delta
centerObject = object.location
dimObject = object.dimensions
xminObject = centerObject.x - dimObject.x/2
xmaxObject = centerObject.x + dimObject.x/2
yminObject = centerObject.y - dimObject.y/2
ymaxObject = centerObject.y + dimObject.y/2
zminObject = centerObject.z + dimObject.z/2
zmaxObject = centerObject.z + dimObject.z/2
if(xminObjectRef<xminObject and xmaxObject<xmaxObjectRef):
# print('x ok')
if(yminObjectRef<yminObject and ymaxObject<ymaxObjectRef):
# print('y ok')
if(zminObject > zminObjectRef):
# print('z ok')
return True
return False
def extractObjectCollectionsOverRef(objectRef,collection):
extractedObjects = []
for obj in collection.all_objects:
if overObjectRef(objectRef,obj):
extractedObjects.append(obj)
return extractedObjects
def createJson(listeCube,listeBox):
dict = { 'cubes' : [],'box' : [] }
for cube in listeCube:
c = { 'name' : cube.name, 'x' : cube.location.x, 'y' : cube.location.y , 'z' : cube.location.z , 'rotation' : cube.rotation_euler.z}
dict['cubes'].append(c)
for box in listeBox:
b = { 'name' : box.name, 'x' : box.location.x, 'y' : box.location.y , 'z' : box.location.z , 'rotation' : box.rotation_euler.z}
dict['box'].append(b)
with open('json_export.json','w') as outfile :
json.dump(json.dumps(dict),outfile)
for collection in bpy.data.collections:
dictCollections[collection.name] = collection
for obj in collection.all_objects:
dictObjects[obj.name] = obj
#print(dictCollections)
#print(dictObjects)
refObject = dictObjects[argRefObject]
cubes = extractObjectCollectionsOverRef(refObject,dictCollections[argCollectionCube])
print(cubes)
box = extractObjectCollectionsOverRef(refObject,dictCollections[argCollectionBox])
print(box)
createJson(cubes,box)
#Cubes = [cube for cube in dictCollections[argCollectionCube].all_objects]
#print(Cubes)
#CubeExtract = []
#for cube in Cubes:
# if overObjectRef(refObject,cube):
# CubeExtract.append(cube)
#print(CubeExtract)
C1 = dictObjects["dt_cube_BBRG"]
C2 = dictObjects["IKEA_RUTBO"]
overObjectRef(refObject,C2)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment