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
{
v3f uaxis, vaxis;
v2f offset, scale;
+ double winding;
};
// simple VDF writing interface
for( int j=0; j<polya->loop_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;
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;
}
}
for( int m=0; m<solid_len; m++ )
{
struct cxr_polygon *polym = cxr_ab_ptr(&mesh->polys,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;
}
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);
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)
// 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; i<mesh->polys.count; i++ )
{
v2f corner_uvs[4];
int dispedge_count;
int disp_count = 0;
- struct cxr_texinfo texinfo_shared;
for( int i=0; i<mesh->polys.count; i++ )
{
// 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
// --------------------
}
}
- 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.
//
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;
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
}
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++ )
{
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" );
}
}
- cxr_log( "Disp count: %d\n", disp_count );
-
// Main loop
#if 0
int pool[25];
if( error ) break;
}
+ else
+ break;
}
else
break;