45 lines
1.7 KiB
Python
45 lines
1.7 KiB
Python
|
|
import bpy, sys
|
||
|
|
import numpy as np
|
||
|
|
argv = sys.argv[sys.argv.index("--") + 1:]
|
||
|
|
bpy.ops.wm.open_mainfile(filepath=argv[0])
|
||
|
|
ob = max([o for o in bpy.data.objects if o.type=='MESH'], key=lambda o: len(o.data.vertices))
|
||
|
|
me = ob.data
|
||
|
|
act = np.load(argv[1])["active"]
|
||
|
|
lay = me.color_attributes.new(name="dbg", type='FLOAT_COLOR', domain='POINT')
|
||
|
|
n = len(me.vertices)
|
||
|
|
cols = np.zeros((n, 4), dtype=np.float32)
|
||
|
|
cols[:, 3] = 1.0
|
||
|
|
cols[act, 0] = 1.0 # red = replaced
|
||
|
|
cols[~act, 1] = 0.6 # green = untouched
|
||
|
|
lay.data.foreach_set("color", cols.reshape(-1))
|
||
|
|
mat = bpy.data.materials.new("dbg")
|
||
|
|
mat.use_nodes = True
|
||
|
|
nt = mat.node_tree
|
||
|
|
vc = nt.nodes.new("ShaderNodeVertexColor")
|
||
|
|
vc.layer_name = "dbg"
|
||
|
|
bsdf = next(x for x in nt.nodes if x.type == 'BSDF_PRINCIPLED')
|
||
|
|
nt.links.new(vc.outputs["Color"], bsdf.inputs["Base Color"])
|
||
|
|
me.materials.clear()
|
||
|
|
me.materials.append(mat)
|
||
|
|
import math
|
||
|
|
from mathutils import Vector
|
||
|
|
scn = bpy.context.scene
|
||
|
|
w = bpy.data.worlds.new("W"); w.color=(0.2,0.2,0.2); scn.world = w
|
||
|
|
sun = bpy.data.objects.new("S", bpy.data.lights.new("S",'SUN'))
|
||
|
|
sun.data.energy = 3; sun.data.use_shadow = False
|
||
|
|
sun.rotation_euler = (math.radians(60),0,math.radians(75))
|
||
|
|
bpy.context.collection.objects.link(sun)
|
||
|
|
cam = bpy.data.objects.new("C", bpy.data.cameras.new("C"))
|
||
|
|
cam.data.lens = 85
|
||
|
|
bpy.context.collection.objects.link(cam)
|
||
|
|
scn.camera = cam
|
||
|
|
scn.render.engine = 'BLENDER_EEVEE'
|
||
|
|
scn.render.resolution_x = scn.render.resolution_y = 1000
|
||
|
|
ctr = Vector((0,0,0.675))
|
||
|
|
yaw = math.radians(40)
|
||
|
|
cam.location = ctr + Vector((math.sin(yaw)*0.66, -math.cos(yaw)*0.66, 0.02))
|
||
|
|
cam.rotation_euler = (ctr - cam.location).to_track_quat('-Z','Y').to_euler()
|
||
|
|
scn.render.filepath = argv[2]
|
||
|
|
bpy.ops.render.render(write_still=True)
|
||
|
|
print("DBG_OK")
|