mirror of https://github.com/AxioDL/metaforce.git
PATH cooking bug fix
This commit is contained in:
parent
3acb9c9e3d
commit
f2d6f643c9
|
@ -47,10 +47,9 @@ def set_height(self, val):
|
|||
# Edit panel
|
||||
def draw(layout, context):
|
||||
layout.prop_search(context.scene, 'hecl_path_obj', context.scene, 'objects')
|
||||
layout.operator('view3d.toggle_path_height_visualization', text='Toggle Height Viz', icon='MANIPUL')
|
||||
layout.operator('view3d.toggle_path_background_wireframe', text='Toggle Background Wire', icon='WIRE')
|
||||
hr = HeightRef()
|
||||
if hr.ready:
|
||||
layout.operator('view3d.toggle_path_height_visualization', text='Toggle Height Viz', icon='MANIPUL')
|
||||
if HeightRef().ready:
|
||||
layout.prop(context.window_manager, 'hecl_height_prop', text='Height')
|
||||
|
||||
# Simple AABB class
|
||||
|
@ -126,7 +125,7 @@ def cook(writebuf, mesh_obj):
|
|||
node_idx = 0
|
||||
start_node = len(node_list)
|
||||
start_link = len(link_list)
|
||||
while cur_loop != start_loop:
|
||||
while True:
|
||||
node_list.append(cur_loop)
|
||||
cur_loop = cur_loop.link_loop_prev
|
||||
for other_face in cur_loop.edge.link_faces:
|
||||
|
@ -134,6 +133,8 @@ def cook(writebuf, mesh_obj):
|
|||
continue
|
||||
link_list.append((node_idx, other_face.index, cur_loop.edge.calc_length()))
|
||||
node_idx += 1
|
||||
if cur_loop == start_loop:
|
||||
break
|
||||
region_list.append((f, range(start_node, len(node_list)), range(start_link, len(link_list))))
|
||||
|
||||
# Emit nodes
|
||||
|
@ -159,7 +160,7 @@ def cook(writebuf, mesh_obj):
|
|||
aabb = AABB()
|
||||
for v in r[0].verts:
|
||||
aabb.accumulate(v.co)
|
||||
aabb.accumulate(v.co + Vector(0.0, 0.0, height))
|
||||
aabb.accumulate(v.co + Vector((0.0, 0.0, height)))
|
||||
ba += struct.pack('>IIIIHHffffIfffffffffI', len(r[1]), r[1].start, len(r[2]), r[2].start,
|
||||
material.retro_path_idx_mask, material.retro_path_type_mask,
|
||||
height, r[0].normal[0], r[0].normal[1], r[0].normal[2],
|
||||
|
@ -170,7 +171,7 @@ def cook(writebuf, mesh_obj):
|
|||
|
||||
num_regions = len(region_list)
|
||||
total_adjacencies = num_regions * (num_regions - 1) // 2
|
||||
num_words = (total_adjacencies + 31) / 32
|
||||
num_words = (total_adjacencies + 31) // 32
|
||||
|
||||
# Find ground adjacencies
|
||||
words = [0] * num_words
|
||||
|
@ -183,11 +184,11 @@ def cook(writebuf, mesh_obj):
|
|||
i2 = j
|
||||
if i1 > i2:
|
||||
continue
|
||||
if ground_adjacencies.has_adjacency(bm.faces[i], bm.faces[j]):
|
||||
rem_regions = num_regions - i1
|
||||
rem_connections = rem_regions * (rem_regions - 1) // 2
|
||||
if ground_adjacencies.has_adjacency(bm.faces[i], bm.faces[j]):
|
||||
bit = total_adjacencies - rem_connections + i2 - (i1 + 1)
|
||||
words[bit / 32] |= 1 << (bit % 32)
|
||||
words[bit // 32] |= 1 << (bit % 32)
|
||||
for w in words:
|
||||
ba += struct.pack('>I', w)
|
||||
|
||||
|
@ -202,16 +203,16 @@ def cook(writebuf, mesh_obj):
|
|||
i2 = j
|
||||
if i1 > i2:
|
||||
continue
|
||||
if flyer_adjacencies.has_adjacency(bm.faces[i], bm.faces[j]):
|
||||
rem_regions = num_regions - i1
|
||||
rem_connections = rem_regions * (rem_regions - 1) // 2
|
||||
if flyer_adjacencies.has_adjacency(bm.faces[i], bm.faces[j]):
|
||||
bit = total_adjacencies - rem_connections + i2 - (i1 + 1)
|
||||
words[bit / 32] |= 1 << (bit % 32)
|
||||
words[bit // 32] |= 1 << (bit % 32)
|
||||
for w in words:
|
||||
ba += struct.pack('>I', w)
|
||||
|
||||
# Unused zero bits
|
||||
for i in range((((num_regions * num_regions) + 31) / 32 - num_words) * 2):
|
||||
for i in range((((num_regions * num_regions) + 31) // 32 - num_words) * 2):
|
||||
ba += struct.pack('>I', 0)
|
||||
|
||||
# Empty octree (to be generated by hecl)
|
||||
|
@ -228,6 +229,28 @@ def draw_line_3d(color, start, end):
|
|||
bgl.glVertex3f(*start)
|
||||
bgl.glVertex3f(*end)
|
||||
|
||||
# Draw RNA polygon
|
||||
def draw_poly(p, obj, obj_mtx, height, top_color, side_color):
|
||||
for ek in p.edge_keys:
|
||||
co0 = obj_mtx * obj.data.vertices[ek[0]].co
|
||||
co1 = obj_mtx * obj.data.vertices[ek[1]].co
|
||||
draw_line_3d(top_color, co0 + Vector((0.0, 0.0, height)),
|
||||
co1 + Vector((0.0, 0.0, height)))
|
||||
for vk in p.vertices:
|
||||
co = obj_mtx * obj.data.vertices[vk].co
|
||||
draw_line_3d(side_color, co, co + Vector((0.0, 0.0, height)))
|
||||
|
||||
# Draw bmesh face
|
||||
def draw_face(f, obj_mtx, height, top_color, side_color):
|
||||
for e in f.edges:
|
||||
co0 = obj_mtx * e.verts[0].co
|
||||
co1 = obj_mtx * e.verts[1].co
|
||||
draw_line_3d(top_color, co0 + Vector((0.0, 0.0, height)),
|
||||
co1 + Vector((0.0, 0.0, height)))
|
||||
for v in f.verts:
|
||||
co = obj_mtx * v.co
|
||||
draw_line_3d(side_color, co, co + Vector((0.0, 0.0, height)))
|
||||
|
||||
# Viewport hook callback
|
||||
def draw_callback_3d(self, context):
|
||||
# object locations
|
||||
|
@ -238,32 +261,52 @@ def draw_callback_3d(self, context):
|
|||
return
|
||||
obj_mtx = obj.matrix_world
|
||||
|
||||
bm = None
|
||||
height_lay = None
|
||||
height_lambda = None
|
||||
if obj == context.edit_object:
|
||||
bm = bmesh.from_edit_mesh(obj.data)
|
||||
if 'Height' in bm.faces.layers.float:
|
||||
height_lay = bm.faces.layers.float['Height']
|
||||
height_lambda = lambda i: bm.faces[i][height_lay]
|
||||
else:
|
||||
if 'Height' in obj.data.polygon_layers_float:
|
||||
height_lay = obj.data.polygon_layers_float['Height']
|
||||
height_lambda = lambda i: height_lay.data[i].value
|
||||
|
||||
# Deselected colors
|
||||
top_color = (0.0, 0.0, 1.0, 0.7)
|
||||
side_color = (1.0, 0.0, 0.0, 0.7)
|
||||
if bm is not None:
|
||||
for f in bm.faces:
|
||||
height = 1.0
|
||||
if height_lay is not None:
|
||||
selected = f.select
|
||||
if selected:
|
||||
continue
|
||||
height = f[height_lay]
|
||||
draw_face(f, obj_mtx, height, top_color, side_color)
|
||||
else:
|
||||
for p in obj.data.polygons:
|
||||
height = 1.0
|
||||
if height_lay is not None:
|
||||
height = height_lambda(p.index)
|
||||
for ek in p.edge_keys:
|
||||
co0 = obj_mtx * obj.data.vertices[ek[0]].co
|
||||
co1 = obj_mtx * obj.data.vertices[ek[1]].co
|
||||
draw_line_3d((0.0, 0.0, 1.0, 0.7), co0 + Vector((0.0, 0.0, height)),
|
||||
co1 + Vector((0.0, 0.0, height)))
|
||||
for vk in p.vertices:
|
||||
co = obj_mtx * obj.data.vertices[vk].co
|
||||
draw_line_3d((1.0, 0.0, 0.0, 0.7), co, co + Vector((0.0, 0.0, height)))
|
||||
|
||||
height = height_lay.data[p.index].value
|
||||
draw_poly(p, obj, obj_mtx, height, top_color, side_color)
|
||||
bgl.glEnd()
|
||||
|
||||
# Selected colors
|
||||
if bm is not None:
|
||||
top_color = (1.0, 0.0, 1.0, 0.7)
|
||||
side_color = (0.0, 1.0, 0.0, 0.7)
|
||||
# Avoid z-fighting on selected lines
|
||||
bgl.glDepthRange(-0.001, 0.999)
|
||||
for f in bm.faces:
|
||||
if height_lay is not None:
|
||||
selected = f.select
|
||||
if not selected:
|
||||
continue
|
||||
height = f[height_lay]
|
||||
draw_face(f, obj_mtx, height, top_color, side_color)
|
||||
bgl.glEnd()
|
||||
bgl.glDepthRange(0.0, 1.0)
|
||||
|
||||
# restore opengl defaults
|
||||
bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
|
||||
|
||||
|
@ -294,7 +337,6 @@ class PathHeightDrawOperator(bpy.types.Operator):
|
|||
class PathBackgroundWireframeOperator(bpy.types.Operator):
|
||||
bl_idname = "view3d.toggle_path_background_wireframe"
|
||||
bl_label = "Toggle PATH background wireframe"
|
||||
_handle_3d = None
|
||||
|
||||
def execute(self, context):
|
||||
if context.scene.background_set:
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 73a0ae0d0056c1ad3a0eb9cc3a50d284e320ec2e
|
||||
Subproject commit 2381e65d0d70310e1756643aa45e1ad021a51611
|
|
@ -180,13 +180,21 @@ err:
|
|||
|
||||
size_t Connection::_readBuf(void* buf, size_t len)
|
||||
{
|
||||
int ret = Read(m_readpipe[0], buf, len);
|
||||
uint8_t* cBuf = reinterpret_cast<uint8_t*>(buf);
|
||||
size_t readLen = 0;
|
||||
do
|
||||
{
|
||||
int ret = Read(m_readpipe[0], cBuf, len);
|
||||
if (ret < 0)
|
||||
goto err;
|
||||
if (len >= 4)
|
||||
if (!memcmp((char*)buf, "EXCEPTION", std::min(len, size_t(9))))
|
||||
if (!memcmp((char*) cBuf, "EXCEPTION", std::min(len, size_t(9))))
|
||||
_blenderDied();
|
||||
return ret;
|
||||
readLen += ret;
|
||||
cBuf += ret;
|
||||
len -= ret;
|
||||
} while (len);
|
||||
return readLen;
|
||||
err:
|
||||
_blenderDied();
|
||||
return 0;
|
||||
|
@ -194,10 +202,18 @@ err:
|
|||
|
||||
size_t Connection::_writeBuf(const void* buf, size_t len)
|
||||
{
|
||||
int ret = Write(m_writepipe[1], buf, len);
|
||||
const uint8_t* cBuf = reinterpret_cast<const uint8_t*>(buf);
|
||||
size_t writeLen = 0;
|
||||
do
|
||||
{
|
||||
int ret = Write(m_writepipe[1], cBuf, len);
|
||||
if (ret < 0)
|
||||
goto err;
|
||||
return ret;
|
||||
writeLen += ret;
|
||||
cBuf += ret;
|
||||
len -= ret;
|
||||
} while (len);
|
||||
return writeLen;
|
||||
err:
|
||||
_blenderDied();
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue