From 4a01d99d563ce228c13591bbed3e24f05241c586 Mon Sep 17 00:00:00 2001 From: hgn Date: Fri, 8 Apr 2022 00:50:17 +0100 Subject: [PATCH] bug fixes --- __init__.py | 12 +++++-- src/convexer.c | 90 +++++++++++++++++++++++++++++--------------------- 2 files changed, 62 insertions(+), 40 deletions(-) diff --git a/__init__.py b/__init__.py index 0e4ddd2..cb37747 100644 --- a/__init__.py +++ b/__init__.py @@ -396,8 +396,8 @@ cxr_graph_mapping = { { "ShaderNodeMixRGB": { - "Color1": material_tex_image("$basetexture"), - "Color2": material_tex_image("$decaltexture") + "Color1": material_tex_image("basetexture"), + "Color2": material_tex_image("decaltexture") }, "ShaderNodeTexImage": { @@ -412,7 +412,7 @@ cxr_graph_mapping = { { "ShaderNodeNormalMap": { - "Color": material_tex_image("$bumpmap") + "Color": material_tex_image("bumpmap") } } } @@ -957,12 +957,17 @@ class CXR_WRITE_VMF(bpy.types.Operator): def _collect(collection,transform): if collection.name.startswith('.'): return + + if collection.hide_render: + return if collection.name.startswith('mdl_'): _collect.heros += [(collection,transform)] return for obj in collection.objects: + if obj.hide_get(): continue + classname = cxr_classname( obj ) if classname != None: @@ -976,6 +981,7 @@ class CXR_WRITE_VMF(bpy.types.Operator): _collect.a_models = set() _collect.entities = [] _collect.geo = [] + _collect.heros = [] transform_main = cxr_object_context( context.scene.cxr_data.scale_factor, 0.0 ) transform_sky = cxr_object_context( context.scene.cxr_data.skybox_scale_factor, \ diff --git a/src/convexer.c b/src/convexer.c index 185917a..adcaf60 100644 --- a/src/convexer.c +++ b/src/convexer.c @@ -59,6 +59,7 @@ typedef v3f m4x3f[4]; typedef v3f boxf[2]; #define CXR_EPSILON 0.001 +#define CXR_PLANE_SIMILARITY_MAX 0.999 #define CXR_BIG_NUMBER 1e300 #define CXR_INTERIOR_ANGLE_MAX 0.998 #define CXR_API @@ -165,6 +166,7 @@ struct cxr_texinfo { v3f uaxis, vaxis; v2f offset, scale; + double winding; }; // simple VDF writing interface @@ -797,8 +799,8 @@ static struct cxr_mesh *cxr_pull_best_solid( for( int j=0; jloop_total; j++ ) { struct cxr_loop *loop = cxr_ab_ptr(&mesh->loops, polya->loop_start+j); - if( plane_polarity( planeb, vertices[loop->index] ) > 0.001 || - v3_dot(polya->normal,polyb->normal) > 0.98500 ) + if( plane_polarity( planeb, vertices[loop->index] ) > 0.000025 || + v3_dot(polya->normal,polyb->normal) > CXR_PLANE_SIMILARITY_MAX ) { edge_tagged[i] = 1; break; @@ -836,7 +838,7 @@ static struct cxr_mesh *cxr_pull_best_solid( struct cxr_polygon *polyj = cxr_ab_ptr(&mesh->polys,connected_planes[j]); struct cxr_polygon *polyk = cxr_ab_ptr(&mesh->polys,connected_planes[k]); - if( v3_dot(polyj->normal, polyk->normal) > 0.98500 ) + if( v3_dot(polyj->normal, polyk->normal) > CXR_PLANE_SIMILARITY_MAX ) goto IL_TAG_VERT; } } @@ -995,7 +997,7 @@ IL_TAG_NEXT_VERT:; for( int m=0; mpolys,solid[m]); - if( v3_dot( polym->normal, future_face->normal ) > 0.98500 ) + if( v3_dot( polym->normal,future_face->normal) > CXR_PLANE_SIMILARITY_MAX) goto IL_SKIP_PLANE_ADD; } @@ -1608,12 +1610,13 @@ static void cxr_calculate_axis( v2_zero( transform->offset ); v2_div( (v2f){128.0, 128.0}, texture_res, transform->scale ); + transform->winding = 1.0; return; } // Detect if UV is reversed double winding = v2_cross( tT, bT ) >= 0.0f? 1.0f: -1.0f; - + // UV projection reference v2f vY, vX; v2_muls((v2f){1,0}, winding, vX); @@ -1678,6 +1681,7 @@ static void cxr_calculate_axis( v3_copy( vaxis, transform->vaxis ); v2_copy( tex_offset, transform->offset ); v2_copy( uv_scale, transform->scale ); + transform->winding = winding; } CXR_API struct cxr_input_mesh *cxr_decompose(struct cxr_input_mesh *src) @@ -1884,7 +1888,7 @@ static void cxr_write_disp(struct cxr_mesh *mesh, struct cxr_input_mesh *inputme // human editable. v3f avg_normal, refv, refu, refn; - v3_zero(refv); v3_zero(refu); v4_zero(refn); + v3_zero(refv); v3_zero(refu); v3_zero(refn); for( int i=0; ipolys.count; i++ ) { @@ -1983,7 +1987,6 @@ static void cxr_write_disp(struct cxr_mesh *mesh, struct cxr_input_mesh *inputme v2f corner_uvs[4]; int dispedge_count; int disp_count = 0; - struct cxr_texinfo texinfo_shared; for( int i=0; ipolys.count; i++ ) { @@ -2014,8 +2017,8 @@ static void cxr_write_disp(struct cxr_mesh *mesh, struct cxr_input_mesh *inputme // Consume (remove) faces we use for corners basepoly->loop_total = -1; - - cxr_debug_box( cxr_ab_ptr(abverts,l0->index),0.08,(v4f){0.0,0.0,1.0,1.0}); + + //cxr_debug_box( cxr_ab_ptr(abverts,l0->index),0.08,(v4f){0.0,0.0,1.0,1.0}); // Collect edges // -------------------- @@ -2166,15 +2169,10 @@ static void cxr_write_disp(struct cxr_mesh *mesh, struct cxr_input_mesh *inputme } } - for( int j=0; j<5; j++ ) - { - cxr_log( "%d %d %d %d %d\n", grid[j*5+0],grid[j*5+1],grid[j*5+2],grid[j*5+3],grid[j*5+4]); - } - // Create brush vertices based on UV map // Create V reference based on first displacement. - // TODO: This is not the most stable selection method! + // TODO: This is not the moststable selection method! // faces can come in any order, so the first disp will of course // always vary. Additionaly the triangle can be oriented differently. // @@ -2191,11 +2189,17 @@ static void cxr_write_disp(struct cxr_mesh *mesh, struct cxr_input_mesh *inputme cxr_calculate_axis( &tx, tri_ref, corner_uvs, (v2f){512,512} ); v3_muls( tx.vaxis, -1.0, refv ); - int v_cardinal = cxr_cardinal( refv, n_cardinal ); - v3_copy( avg_normal, refn ); + int v_cardinal = cxr_cardinal( refv, -1 ); + + v3_cross( tx.vaxis, tx.uaxis, refn ); + v3_muls( refn, -tx.winding, refn ); + + int n1_cardinal = cxr_cardinal( refn, v_cardinal ); + + //v3_copy( avg_normal, refn ); int u_cardinal = 0; - if( u_cardinal == n_cardinal || u_cardinal == v_cardinal ) u_cardinal ++; - if( u_cardinal == n_cardinal || u_cardinal == v_cardinal ) u_cardinal ++; + if( u_cardinal == n1_cardinal || u_cardinal == v_cardinal ) u_cardinal ++; + if( u_cardinal == n1_cardinal || u_cardinal == v_cardinal ) u_cardinal ++; v3_zero(refu); refu[u_cardinal] = tx.uaxis[u_cardinal] > 0.0? 1.0: -1.0; @@ -2206,13 +2210,16 @@ static void cxr_write_disp(struct cxr_mesh *mesh, struct cxr_input_mesh *inputme v3_muladds( face_center, refn, 1.5, pn ); v3_muladds( face_center, refv, 1.5, pv ); v3_muladds( face_center, refu, 1.5, pu ); - - cxr_debug_line( p0, pn, (v4f){0.0,0.0,1.0,1.0}); - cxr_debug_line( p0, pv, (v4f){0.0,1.0,0.0,1.0}); - cxr_debug_line( p0, pu, (v4f){1.0,0.0,0.0,1.0}); - cxr_debug_line( tri_ref[0], tri_ref[1], (v4f){1.0,1.0,1.0,1.0} ); - cxr_debug_line( tri_ref[1], tri_ref[2], (v4f){1.0,1.0,1.0,1.0} ); - cxr_debug_line( tri_ref[2], tri_ref[0], (v4f){1.0,1.0,1.0,1.0} ); + + if( cxr_settings.debug ) + { + cxr_debug_line( p0, pn, (v4f){0.0,0.0,1.0,1.0}); + cxr_debug_line( p0, pv, (v4f){0.0,1.0,0.0,1.0}); + cxr_debug_line( p0, pu, (v4f){1.0,0.0,0.0,1.0}); + cxr_debug_line( tri_ref[0], tri_ref[1], (v4f){1.0,1.0,1.0,1.0} ); + cxr_debug_line( tri_ref[1], tri_ref[2], (v4f){1.0,1.0,1.0,1.0} ); + cxr_debug_line( tri_ref[2], tri_ref[0], (v4f){1.0,1.0,1.0,1.0} ); + } } // Create world cordinates @@ -2232,14 +2239,25 @@ static void cxr_write_disp(struct cxr_mesh *mesh, struct cxr_input_mesh *inputme } double *colour = colours_random[cxr_range(disp_count,8)]; - cxr_debug_arrow( world_corners[0], world_corners[1], avg_normal, 0.1, colour ); - cxr_debug_arrow( world_corners[1], world_corners[2], avg_normal, 0.1, colour ); - cxr_debug_arrow( world_corners[2], world_corners[3], avg_normal, 0.1, colour ); - cxr_debug_arrow( world_corners[3], world_corners[0], avg_normal, 0.1, colour ); for( int j=0; j<4; j++ ) v3_muladds( world_corners[j], refn, -1.0, world_corners[j+4] ); + if( cxr_settings.debug ) + { + cxr_debug_arrow( world_corners[0], world_corners[1], avg_normal, 0.1, colour ); + cxr_debug_arrow( world_corners[1], world_corners[2], avg_normal, 0.1, colour ); + cxr_debug_arrow( world_corners[2], world_corners[3], avg_normal, 0.1, colour ); + cxr_debug_arrow( world_corners[3], world_corners[0], avg_normal, 0.1, colour ); + } + + /* + cxr_debug_arrow( world_corners[0+4], world_corners[1+4], avg_normal, 0.1, colour ); + cxr_debug_arrow( world_corners[1+4], world_corners[2+4], avg_normal, 0.1, colour ); + cxr_debug_arrow( world_corners[2+4], world_corners[3+4], avg_normal, 0.1, colour ); + cxr_debug_arrow( world_corners[3+4], world_corners[0+4], avg_normal, 0.1, colour ); + */ + // Apply world transform for( int j=0; j<8; j++ ) { @@ -2247,11 +2265,9 @@ static void cxr_write_disp(struct cxr_mesh *mesh, struct cxr_input_mesh *inputme world_corners[j][2] += cxr_context.offset_z; } - if( disp_count == 0 ) - { - cxr_calculate_axis( &texinfo_shared, world_corners, world_uv, - (v2f){ matptr->res[0], matptr->res[1] } ); - } + struct cxr_texinfo texinfo_shared; + cxr_calculate_axis( &texinfo_shared, world_corners, world_uv, + (v2f){ matptr->res[0], matptr->res[1] } ); // Write brush cxr_vdf_node( output, "solid" ); @@ -2382,8 +2398,6 @@ static void cxr_write_disp(struct cxr_mesh *mesh, struct cxr_input_mesh *inputme } } - cxr_log( "Disp count: %d\n", disp_count ); - // Main loop #if 0 int pool[25]; @@ -2598,6 +2612,8 @@ CXR_API i32 cxr_convert_mesh_to_vmf(struct cxr_input_mesh *src, struct cxr_vdf * if( error ) break; } + else + break; } else break; -- 2.25.1