Skip to content

Adding magnets to custom objects

Joshua edited this page Sep 10, 2020 · 1 revision

Adding magnets to objects

Instructions

  1. Extract the render model of the object you wish to add magnets to using tagtool or some other method.
  2. import the extracted model into blender. and set the rotation to 0,0,0
  3. Add primitives with the name magnetMarker (Blender will automatically number them to prevent name collisions)
  4. Execute the export markers script in the python console (shfit+f4)
  5. Take the json dump and append it to magnets.json with the render model name stringid as the key
  6. Reload the map

Generating markers for box-like objects

scaling v will have the same effect as setting CloneDepth

obj = bpy.context.selected_objects[0]
for p in [v[:] for v in obj.bound_box]:
    v = obj.matrix_world * Vector(p)
    bpy.ops.mesh.primitive_uv_sphere_add(size=0.05, location=v)
    bpy.context.active_object.name = 'magnetMarker'

Exporting markers

import json
print(json.dumps([ [round(a, 2) for a in o.location] for o in bpy.data.objects if o.name.startswith('magnetMarker')]))

Importing markers

import json
for o in json.loads(magnetJson):
    bpy.ops.mesh.primitive_uv_sphere_add(size=0.05, location=o)
    bpy.context.active_object.name = 'magnetMarker'

Clone this wiki locally