From 8e1b6889db7ce10f8d594539ef74dc4390e8e891 Mon Sep 17 00:00:00 2001 From: hgn Date: Sat, 30 Apr 2022 02:41:50 +0100 Subject: [PATCH] WVT alpha --- __init__.py | 11 ++++++++++- cxr/cxr.h | 30 +++++++++++++++++++++++------- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/__init__.py b/__init__.py index c8fbad9..3ce19bd 100644 --- a/__init__.py +++ b/__init__.py @@ -258,7 +258,8 @@ class cxr_edge(Structure): class cxr_static_loop(Structure): _fields_ = [("index",c_int32), ("edge_index",c_int32), - ("uv",c_double * 2)] + ("uv",c_double * 2), + ("alpha",c_double)] class cxr_polygon(Structure): _fields_ = [("loop_start",c_int32), @@ -351,6 +352,14 @@ def mesh_cxr_format(obj): else: loop_data[loop_index].uv[0] = c_double(0.0) loop_data[loop_index].uv[1] = c_double(0.0) + + if data.vertex_colors: + alpha = data.vertex_colors.active.data[loop_index].color[0] + else: + alpha = 0.0 + + loop_data[loop_index].alpha = alpha + center = obj.matrix_world @ poly.center normal = mtx_rot @ poly.normal diff --git a/cxr/cxr.h b/cxr/cxr.h index 0585f1a..e1c1679 100644 --- a/cxr/cxr.h +++ b/cxr/cxr.h @@ -159,6 +159,7 @@ struct cxr_static_mesh i32 index, edge_index; v2f uv; + double alpha; } *loops; @@ -192,6 +193,7 @@ struct cxr_loop edge_index, index; v2f uv; + float alpha; }; struct cxr_solid @@ -514,9 +516,12 @@ CXR_API void cxr_write_test_data( cxr_static_mesh *src ) fprintf( fp, "cxr_static_loop test_loops[] = {\n" ); for( int i=0; iloop_count; i ++ ) { - fprintf( fp, " {%d, %d},\n", + fprintf( fp, " {%d, %d, {%f, %f}, %f},\n", src->loops[i].index, - src->loops[i].edge_index); + src->loops[i].edge_index, + src->loops[i].uv[0], + src->loops[i].uv[1], + src->loops[i].alpha ); } fprintf( fp, "};\n" ); @@ -2084,6 +2089,7 @@ static cxr_mesh *cxr_to_internal_format( lp->index = src->loops[i].index; lp->edge_index = src->loops[i].edge_index; v2_copy( src->loops[i].uv, lp->uv ); + lp->alpha = src->loops[i].alpha; } abverts->count = src->vertex_count; @@ -2777,6 +2783,13 @@ static int cxr_write_disp( cxr_mesh *mesh, cxr_world *world, } } + /* Collect alphas from loops. This discards hard blend information */ + for( int i=0; iabloops.count; i++ ) + { + cxr_loop *loop = &mesh->loops[i]; + vertinfo[loop->index].alpha = loop->alpha * 255.0; + } + v3f refv, refu, refn; v3_zero(refv); v3_zero(refu); v3_zero(refn); @@ -3145,6 +3158,7 @@ static int cxr_write_disp( cxr_mesh *mesh, cxr_world *world, v3f normals[25]; double distances[25]; + double alphas[25]; v3f lside0, lside1, lref, vdelta, vworld; double tx, ty; @@ -3169,6 +3183,8 @@ static int cxr_write_disp( cxr_mesh *mesh, cxr_world *world, v3_copy( vdelta, normals[index] ); v3_normalize( normals[index] ); distances[index] = v3_dot( vdelta, normals[index] ); + + alphas[index] = vertinfo[grid[index]].alpha; } } @@ -3215,6 +3231,11 @@ static int cxr_write_disp( cxr_mesh *mesh, cxr_world *world, cxr_vdf_karrdouble( output, "row", k, &distances[k*5], 5 ); cxr_vdf_edon( output ); + cxr_vdf_node( output, "alphas" ); + for( int k=0; k<5; k++ ) + cxr_vdf_karrdouble( output, "row", k, &alphas[k*5], 5 ); + cxr_vdf_edon( output ); + /* * TODO: This might be needed for the compilers. Opens fine in * hammer @@ -3233,11 +3254,6 @@ static int cxr_write_disp( cxr_mesh *mesh, cxr_world *world, "\"row%d\" \"0 0 1 0 0 1 0 0 1 0 0 1 0 0 1\"\n", k ); cxr_vdf_edon( output ); - cxr_vdf_node( output, "alphas" ); - for( int k=0; k<5; k++ ) - cxr_vdf_printf( output, "\"row%d\" \"0 0 0 0 0\"\n", k ); - cxr_vdf_edon( output ); - cxr_vdf_node( output, "triangle_tags" ); for( int k=0; k<5-1; k++ ) cxr_vdf_printf( output, -- 2.25.1