Reduce ghosts (#212)
Full ghost collision handling for sphere, capsule, and hull versus a single mesh or heightfield. This requires mesh to be built with edge identification. Optimized mesh builder. Removed B3_MAX_MESH_CONTACT_TRIANGLES. You will still hit performance problems for dense meshes. Fixes #184
This commit is contained in:
parent
3362633204
commit
38f2ae1e19
61 changed files with 17756 additions and 1492 deletions
|
|
@ -12,7 +12,7 @@ BraceWrapping:
|
|||
AfterUnion: true
|
||||
BeforeWhile: true
|
||||
|
||||
ColumnLimit: 100
|
||||
ColumnLimit: 120
|
||||
PointerAlignment: Left
|
||||
UseTab: Always
|
||||
BreakConstructorInitializers: BeforeComma
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
root = true
|
||||
|
||||
[*.{c,h,cpp,inl}]
|
||||
guidelines = 100
|
||||
guidelines = 120
|
||||
guidelines_style = 1px dotted gray
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
set(BOX3D_BENCHMARK_FILES
|
||||
main.c
|
||||
mesh_benchmark.c
|
||||
mesh_benchmark.h
|
||||
)
|
||||
|
||||
add_executable(benchmark ${BOX3D_BENCHMARK_FILES})
|
||||
|
|
@ -18,4 +20,36 @@ endif()
|
|||
|
||||
target_link_libraries(benchmark PRIVATE box3d shared)
|
||||
|
||||
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX "" FILES ${BOX3D_BENCHMARK_FILES})
|
||||
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX "" FILES ${BOX3D_BENCHMARK_FILES})
|
||||
# Mesh drop soak. Uses internal threads, so it needs the static library.
|
||||
if (NOT BUILD_SHARED_LIBS)
|
||||
add_executable(mesh_soak mesh_soak.c)
|
||||
|
||||
set_target_properties(mesh_soak PROPERTIES
|
||||
C_STANDARD 17
|
||||
C_STANDARD_REQUIRED YES
|
||||
C_EXTENSIONS NO
|
||||
)
|
||||
|
||||
if (BOX3D_COMPILE_WARNING_AS_ERROR)
|
||||
set_target_properties(mesh_soak PROPERTIES COMPILE_WARNING_AS_ERROR ON)
|
||||
endif()
|
||||
|
||||
target_include_directories(mesh_soak PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../src)
|
||||
target_link_libraries(mesh_soak PRIVATE box3d shared)
|
||||
endif()
|
||||
|
||||
# Headless Ghost Collisions sample. Counts ghost manifolds per scene and body.
|
||||
add_executable(ghost_scan ghost_scan.c)
|
||||
|
||||
set_target_properties(ghost_scan PROPERTIES
|
||||
C_STANDARD 17
|
||||
C_STANDARD_REQUIRED YES
|
||||
C_EXTENSIONS NO
|
||||
)
|
||||
|
||||
if (BOX3D_COMPILE_WARNING_AS_ERROR)
|
||||
set_target_properties(ghost_scan PROPERTIES COMPILE_WARNING_AS_ERROR ON)
|
||||
endif()
|
||||
|
||||
target_link_libraries(ghost_scan PRIVATE box3d shared)
|
||||
|
|
|
|||
105
benchmark/ghost_baseline.csv
Normal file
105
benchmark/ghost_baseline.csv
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
scene,preset,mirror,body,ghosts,runs
|
||||
flat,0,0,box,0,2
|
||||
flat,0,0,capsule,0,2
|
||||
flat,0,0,upright,0,2
|
||||
flat,0,0,sphere,0,2
|
||||
flat,0,0,cylinder,0,2
|
||||
flat,0,1,box,0,2
|
||||
flat,0,1,capsule,0,2
|
||||
flat,0,1,upright,0,2
|
||||
flat,0,1,sphere,0,2
|
||||
flat,0,1,cylinder,0,2
|
||||
ramp,0,0,box,0,3
|
||||
ramp,0,0,capsule,0,3
|
||||
ramp,0,0,upright,0,3
|
||||
ramp,0,0,sphere,0,3
|
||||
ramp,0,0,cylinder,0,3
|
||||
ramp,0,1,box,0,3
|
||||
ramp,0,1,capsule,0,3
|
||||
ramp,0,1,upright,0,3
|
||||
ramp,0,1,sphere,0,3
|
||||
ramp,0,1,cylinder,0,3
|
||||
cliff,0,0,box,0,2
|
||||
cliff,0,0,capsule,0,2
|
||||
cliff,0,0,upright,0,2
|
||||
cliff,0,0,sphere,0,2
|
||||
cliff,0,0,cylinder,0,2
|
||||
cliff,0,1,box,0,2
|
||||
cliff,0,1,capsule,0,2
|
||||
cliff,0,1,upright,0,2
|
||||
cliff,0,1,sphere,0,2
|
||||
cliff,0,1,cylinder,0,2
|
||||
crest,0,0,box,0,2
|
||||
crest,0,0,capsule,0,2
|
||||
crest,0,0,upright,0,2
|
||||
crest,0,0,sphere,0,2
|
||||
crest,0,0,cylinder,0,2
|
||||
crest,0,1,box,0,2
|
||||
crest,0,1,capsule,0,2
|
||||
crest,0,1,upright,0,2
|
||||
crest,0,1,sphere,0,2
|
||||
crest,0,1,cylinder,0,2
|
||||
bumps,0,0,box,0,1
|
||||
bumps,0,0,capsule,0,1
|
||||
bumps,0,0,upright,0,1
|
||||
bumps,0,0,sphere,0,1
|
||||
bumps,0,0,cylinder,0,1
|
||||
bumps,0,1,box,0,1
|
||||
bumps,0,1,capsule,0,1
|
||||
bumps,0,1,upright,0,1
|
||||
bumps,0,1,sphere,0,1
|
||||
bumps,0,1,cylinder,0,1
|
||||
peel,0,0,box,0,2
|
||||
peel,0,0,capsule,0,2
|
||||
peel,0,0,upright,0,2
|
||||
peel,0,0,sphere,0,2
|
||||
peel,0,0,cylinder,0,2
|
||||
peel,0,1,box,0,2
|
||||
peel,0,1,capsule,0,2
|
||||
peel,0,1,upright,0,2
|
||||
peel,0,1,sphere,0,2
|
||||
peel,0,1,cylinder,0,2
|
||||
peel,1,0,box,0,2
|
||||
peel,1,0,capsule,0,2
|
||||
peel,1,0,upright,0,2
|
||||
peel,1,0,sphere,0,2
|
||||
peel,1,0,cylinder,0,2
|
||||
peel,1,1,box,0,2
|
||||
peel,1,1,capsule,0,2
|
||||
peel,1,1,upright,0,2
|
||||
peel,1,1,sphere,0,2
|
||||
peel,1,1,cylinder,0,2
|
||||
peel,2,0,box,0,2
|
||||
peel,2,0,capsule,0,2
|
||||
peel,2,0,upright,0,2
|
||||
peel,2,0,sphere,0,2
|
||||
peel,2,0,cylinder,0,2
|
||||
peel,2,1,box,0,2
|
||||
peel,2,1,capsule,0,2
|
||||
peel,2,1,upright,0,2
|
||||
peel,2,1,sphere,0,2
|
||||
peel,2,1,cylinder,0,2
|
||||
peel,3,0,box,0,2
|
||||
peel,3,0,capsule,0,2
|
||||
peel,3,0,upright,0,2
|
||||
peel,3,0,sphere,0,2
|
||||
peel,3,0,cylinder,0,2
|
||||
peel,3,1,box,0,2
|
||||
peel,3,1,capsule,0,2
|
||||
peel,3,1,upright,0,2
|
||||
peel,3,1,sphere,0,2
|
||||
peel,3,1,cylinder,0,2
|
||||
chamfer,0,0,box,0,2
|
||||
chamfer,0,0,cylinder,0,2
|
||||
chamfer,0,1,box,0,2
|
||||
chamfer,0,1,cylinder,0,2
|
||||
rail,0,0,box,0,2
|
||||
rail,0,0,capsule,0,2
|
||||
rail,0,0,upright,0,5
|
||||
rail,0,0,sphere,0,4
|
||||
rail,0,0,cylinder,0,3
|
||||
rail,0,1,box,0,2
|
||||
rail,0,1,capsule,0,2
|
||||
rail,0,1,upright,0,5
|
||||
rail,0,1,sphere,0,4
|
||||
rail,0,1,cylinder,0,3
|
||||
|
105
benchmark/ghost_baseline_hf.csv
Normal file
105
benchmark/ghost_baseline_hf.csv
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
scene,preset,mirror,body,ghosts,runs
|
||||
flat,0,0,box,0,2
|
||||
flat,0,0,capsule,0,2
|
||||
flat,0,0,upright,0,2
|
||||
flat,0,0,sphere,0,2
|
||||
flat,0,0,cylinder,0,2
|
||||
flat,0,1,box,0,2
|
||||
flat,0,1,capsule,0,2
|
||||
flat,0,1,upright,0,2
|
||||
flat,0,1,sphere,0,2
|
||||
flat,0,1,cylinder,0,2
|
||||
ramp,0,0,box,0,3
|
||||
ramp,0,0,capsule,0,3
|
||||
ramp,0,0,upright,0,3
|
||||
ramp,0,0,sphere,0,3
|
||||
ramp,0,0,cylinder,0,3
|
||||
ramp,0,1,box,0,3
|
||||
ramp,0,1,capsule,0,3
|
||||
ramp,0,1,upright,0,3
|
||||
ramp,0,1,sphere,0,3
|
||||
ramp,0,1,cylinder,0,3
|
||||
cliff,0,0,box,0,2
|
||||
cliff,0,0,capsule,0,2
|
||||
cliff,0,0,upright,0,2
|
||||
cliff,0,0,sphere,0,2
|
||||
cliff,0,0,cylinder,0,2
|
||||
cliff,0,1,box,0,2
|
||||
cliff,0,1,capsule,0,2
|
||||
cliff,0,1,upright,0,2
|
||||
cliff,0,1,sphere,0,2
|
||||
cliff,0,1,cylinder,0,2
|
||||
crest,0,0,box,0,2
|
||||
crest,0,0,capsule,0,2
|
||||
crest,0,0,upright,0,2
|
||||
crest,0,0,sphere,0,2
|
||||
crest,0,0,cylinder,0,2
|
||||
crest,0,1,box,0,2
|
||||
crest,0,1,capsule,0,2
|
||||
crest,0,1,upright,0,2
|
||||
crest,0,1,sphere,0,2
|
||||
crest,0,1,cylinder,0,2
|
||||
bumps,0,0,box,0,1
|
||||
bumps,0,0,capsule,0,1
|
||||
bumps,0,0,upright,0,1
|
||||
bumps,0,0,sphere,0,1
|
||||
bumps,0,0,cylinder,0,1
|
||||
bumps,0,1,box,0,1
|
||||
bumps,0,1,capsule,0,1
|
||||
bumps,0,1,upright,0,1
|
||||
bumps,0,1,sphere,0,1
|
||||
bumps,0,1,cylinder,0,1
|
||||
peel,0,0,box,0,2
|
||||
peel,0,0,capsule,0,2
|
||||
peel,0,0,upright,0,2
|
||||
peel,0,0,sphere,0,2
|
||||
peel,0,0,cylinder,0,2
|
||||
peel,0,1,box,0,2
|
||||
peel,0,1,capsule,0,2
|
||||
peel,0,1,upright,0,2
|
||||
peel,0,1,sphere,0,2
|
||||
peel,0,1,cylinder,0,2
|
||||
peel,1,0,box,0,2
|
||||
peel,1,0,capsule,0,2
|
||||
peel,1,0,upright,0,2
|
||||
peel,1,0,sphere,0,2
|
||||
peel,1,0,cylinder,0,2
|
||||
peel,1,1,box,0,2
|
||||
peel,1,1,capsule,0,2
|
||||
peel,1,1,upright,0,2
|
||||
peel,1,1,sphere,0,2
|
||||
peel,1,1,cylinder,0,2
|
||||
peel,2,0,box,0,2
|
||||
peel,2,0,capsule,0,2
|
||||
peel,2,0,upright,0,2
|
||||
peel,2,0,sphere,0,2
|
||||
peel,2,0,cylinder,0,2
|
||||
peel,2,1,box,0,2
|
||||
peel,2,1,capsule,0,2
|
||||
peel,2,1,upright,0,2
|
||||
peel,2,1,sphere,0,2
|
||||
peel,2,1,cylinder,0,2
|
||||
peel,3,0,box,0,2
|
||||
peel,3,0,capsule,0,2
|
||||
peel,3,0,upright,0,2
|
||||
peel,3,0,sphere,0,2
|
||||
peel,3,0,cylinder,0,2
|
||||
peel,3,1,box,0,2
|
||||
peel,3,1,capsule,0,2
|
||||
peel,3,1,upright,0,2
|
||||
peel,3,1,sphere,0,2
|
||||
peel,3,1,cylinder,0,2
|
||||
chamfer,0,0,box,0,2
|
||||
chamfer,0,0,cylinder,0,2
|
||||
chamfer,0,1,box,0,2
|
||||
chamfer,0,1,cylinder,0,2
|
||||
rail,0,0,box,0,5
|
||||
rail,0,0,capsule,0,4
|
||||
rail,0,0,upright,0,5
|
||||
rail,0,0,sphere,0,5
|
||||
rail,0,0,cylinder,0,4
|
||||
rail,0,1,box,0,5
|
||||
rail,0,1,capsule,0,4
|
||||
rail,0,1,upright,0,5
|
||||
rail,0,1,sphere,0,5
|
||||
rail,0,1,cylinder,0,4
|
||||
|
521
benchmark/ghost_scan.c
Normal file
521
benchmark/ghost_scan.c
Normal file
|
|
@ -0,0 +1,521 @@
|
|||
// SPDX-FileCopyrightText: 2026 Erin Catto
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
// Headless scan of the Mesh / Ghost Collisions sample. Runs every scene, body, mirror and PEEL
|
||||
// preset for a fixed number of steps and counts the ghost manifolds that pushed on the body. A
|
||||
// written result file can be compared against a later build, which fails on any count that grew. It
|
||||
// also fails on a config that completed fewer runs, because a body stopped on an edge or dropped
|
||||
// through the ground crosses fewer edges and so logs fewer ghosts.
|
||||
|
||||
#if defined( _MSC_VER ) && !defined( _CRT_SECURE_NO_WARNINGS )
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#include "ghost_collisions.h"
|
||||
|
||||
#include "box3d/box3d.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
// Command line and result file keys
|
||||
static const char* s_sceneKeys[e_ghostSceneCount] = { "flat", "ramp", "cliff", "crest", "bumps", "peel", "chamfer", "rail" };
|
||||
static const char* s_bodyKeys[e_ghostBodyCount] = { "box", "capsule", "upright", "sphere", "cylinder" };
|
||||
|
||||
#define MAX_CONFIGS 256
|
||||
|
||||
static bool s_recycling = true;
|
||||
|
||||
typedef struct Config
|
||||
{
|
||||
GhostScene scene;
|
||||
int preset;
|
||||
bool mirror;
|
||||
GhostBody body;
|
||||
int ghostCount;
|
||||
int runCount;
|
||||
|
||||
// From the compare file, -1 when absent
|
||||
int baseGhostCount;
|
||||
int baseRunCount;
|
||||
} Config;
|
||||
|
||||
static const char* MatchValue( const char* arg, const char* shortName, const char* longName )
|
||||
{
|
||||
size_t shortLength = strlen( shortName );
|
||||
if ( strncmp( arg, shortName, shortLength ) == 0 )
|
||||
{
|
||||
return arg + shortLength;
|
||||
}
|
||||
|
||||
size_t longLength = strlen( longName );
|
||||
if ( strncmp( arg, longName, longLength ) == 0 )
|
||||
{
|
||||
return arg + longLength;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Returns -1 for all, -2 for unknown
|
||||
static int ParseKey( const char* value, const char** keys, int count )
|
||||
{
|
||||
if ( strcmp( value, "all" ) == 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
for ( int i = 0; i < count; ++i )
|
||||
{
|
||||
if ( strcmp( value, keys[i] ) == 0 )
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
char* end;
|
||||
long index = strtol( value, &end, 10 );
|
||||
if ( *end == '\0' && 0 <= index && index < count )
|
||||
{
|
||||
return (int)index;
|
||||
}
|
||||
|
||||
return -2;
|
||||
}
|
||||
|
||||
static void RunConfig( Config* config, GhostSettings settings, int stepCount, bool verbose )
|
||||
{
|
||||
settings.scene = config->scene;
|
||||
settings.peelPreset = config->preset;
|
||||
settings.mirror = config->mirror;
|
||||
settings.body = config->body;
|
||||
|
||||
// The s&box character is a fixed rotation hull without speculative contact. Speculative contact or
|
||||
// rotation hide the ghost.
|
||||
if ( config->scene == e_ghostChamfer )
|
||||
{
|
||||
settings.fixedRotation = true;
|
||||
settings.speculative = false;
|
||||
}
|
||||
|
||||
b3WorldDef worldDef = b3DefaultWorldDef();
|
||||
b3WorldId worldId = b3CreateWorld( &worldDef );
|
||||
if ( s_recycling == false )
|
||||
{
|
||||
b3World_SetContactRecycleDistance( worldId, 0.0f );
|
||||
}
|
||||
|
||||
GhostCollisionsData data = CreateGhostCollisions( worldId, settings );
|
||||
|
||||
for ( int step = 0; step < stepCount; ++step )
|
||||
{
|
||||
b3World_Step( worldId, 1.0f / 60.0f, 4 );
|
||||
|
||||
GhostReport reports[16];
|
||||
int ghostCount = UpdateGhostCollisions( worldId, &data, reports, 16 );
|
||||
if ( verbose )
|
||||
{
|
||||
ghostCount = b3MinInt( ghostCount, 16 );
|
||||
for ( int i = 0; i < ghostCount; ++i )
|
||||
{
|
||||
GhostReport* r = reports + i;
|
||||
printf( " ghost step %d run %d n (%.3f %.3f %.3f) p (%.2f %.2f %.2f) sep %.4f impulse %.3f\n", step + 1, data.runCount,
|
||||
r->normal.x, r->normal.y, r->normal.z, (float)r->point.x, (float)r->point.y, (float)r->point.z,
|
||||
r->separation, r->impulse );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
config->ghostCount = data.ghostCount;
|
||||
config->runCount = data.runCount;
|
||||
|
||||
b3DestroyWorld( worldId );
|
||||
DestroyGhostCollisions( &data );
|
||||
}
|
||||
|
||||
static void FormatRow( char* buffer, size_t size, const Config* config )
|
||||
{
|
||||
if ( config->scene == e_ghostInternal )
|
||||
{
|
||||
snprintf( buffer, size, "%s %d%s", s_sceneKeys[config->scene], config->preset, config->mirror ? " mirror" : "" );
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf( buffer, size, "%s%s", s_sceneKeys[config->scene], config->mirror ? " mirror" : "" );
|
||||
}
|
||||
}
|
||||
|
||||
static bool SameConfig( const Config* a, const Config* b )
|
||||
{
|
||||
return a->scene == b->scene && a->preset == b->preset && a->mirror == b->mirror && a->body == b->body;
|
||||
}
|
||||
|
||||
// Filters are -1 for all
|
||||
static int BuildConfigs( Config* configs, int sceneFilter, int presetFilter, int mirrorFilter, int bodyFilter )
|
||||
{
|
||||
int configCount = 0;
|
||||
for ( int scene = 0; scene < e_ghostSceneCount; ++scene )
|
||||
{
|
||||
if ( sceneFilter >= 0 && scene != sceneFilter )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int presetCount = scene == e_ghostInternal ? GHOST_PEEL_PRESET_COUNT : 1;
|
||||
for ( int preset = 0; preset < presetCount; ++preset )
|
||||
{
|
||||
if ( scene == e_ghostInternal && presetFilter >= 0 && preset != presetFilter )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
for ( int mirror = 0; mirror < 2; ++mirror )
|
||||
{
|
||||
if ( mirrorFilter >= 0 && mirror != mirrorFilter )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
for ( int body = 0; body < e_ghostBodyCount; ++body )
|
||||
{
|
||||
if ( bodyFilter >= 0 && body != bodyFilter )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Only a flat bottom can rest on the chamfer edges
|
||||
if ( scene == e_ghostChamfer && body != e_ghostBox && body != e_ghostCylinder )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
B3_ASSERT( configCount < MAX_CONFIGS );
|
||||
configs[configCount++] = (Config){
|
||||
.scene = (GhostScene)scene,
|
||||
.preset = preset,
|
||||
.mirror = mirror != 0,
|
||||
.body = (GhostBody)body,
|
||||
.baseGhostCount = -1,
|
||||
.baseRunCount = -1,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return configCount;
|
||||
}
|
||||
|
||||
static bool ReadBaseline( const char* path, Config* configs, int configCount )
|
||||
{
|
||||
FILE* file = fopen( path, "r" );
|
||||
if ( file == NULL )
|
||||
{
|
||||
printf( "cannot read %s\n", path );
|
||||
return false;
|
||||
}
|
||||
|
||||
char line[256];
|
||||
while ( fgets( line, sizeof( line ), file ) != NULL )
|
||||
{
|
||||
char sceneKey[32], bodyKey[32];
|
||||
int preset, mirror, ghosts, runs;
|
||||
if ( sscanf( line, "%31[^,],%d,%d,%31[^,],%d,%d", sceneKey, &preset, &mirror, bodyKey, &ghosts, &runs ) != 6 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int scene = ParseKey( sceneKey, s_sceneKeys, e_ghostSceneCount );
|
||||
int body = ParseKey( bodyKey, s_bodyKeys, e_ghostBodyCount );
|
||||
for ( int i = 0; i < configCount; ++i )
|
||||
{
|
||||
Config* c = configs + i;
|
||||
if ( (int)c->scene == scene && c->preset == preset && c->mirror == ( mirror != 0 ) && (int)c->body == body )
|
||||
{
|
||||
c->baseGhostCount = ghosts;
|
||||
c->baseRunCount = runs;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fclose( file );
|
||||
return true;
|
||||
}
|
||||
|
||||
// Replaces only the rows of this run and keeps the rest of an existing file, in canonical order
|
||||
static bool WriteResults( const char* path, const Config* configs, int configCount )
|
||||
{
|
||||
Config allConfigs[MAX_CONFIGS];
|
||||
int allCount = BuildConfigs( allConfigs, -1, -1, -1, -1 );
|
||||
|
||||
FILE* existing = fopen( path, "r" );
|
||||
if ( existing != NULL )
|
||||
{
|
||||
fclose( existing );
|
||||
if ( ReadBaseline( path, allConfigs, allCount ) == false )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
FILE* file = fopen( path, "w" );
|
||||
if ( file == NULL )
|
||||
{
|
||||
printf( "cannot write %s\n", path );
|
||||
return false;
|
||||
}
|
||||
|
||||
fprintf( file, "scene,preset,mirror,body,ghosts,runs\n" );
|
||||
for ( int i = 0; i < allCount; ++i )
|
||||
{
|
||||
const Config* c = allConfigs + i;
|
||||
int ghostCount = c->baseGhostCount;
|
||||
int runCount = c->baseRunCount;
|
||||
for ( int j = 0; j < configCount; ++j )
|
||||
{
|
||||
if ( SameConfig( c, configs + j ) )
|
||||
{
|
||||
ghostCount = configs[j].ghostCount;
|
||||
runCount = configs[j].runCount;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ghostCount < 0 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
fprintf( file, "%s,%d,%d,%s,%d,%d\n", s_sceneKeys[c->scene], c->preset, c->mirror ? 1 : 0, s_bodyKeys[c->body], ghostCount,
|
||||
runCount );
|
||||
}
|
||||
|
||||
fclose( file );
|
||||
return true;
|
||||
}
|
||||
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
int sceneFilter = -1;
|
||||
int bodyFilter = -1;
|
||||
int mirrorFilter = -1;
|
||||
int presetFilter = -1;
|
||||
int stepCount = 900;
|
||||
bool verbose = false;
|
||||
const char* writePath = NULL;
|
||||
const char* comparePath = NULL;
|
||||
GhostSettings settings = GetDefaultGhostSettings();
|
||||
|
||||
for ( int i = 1; i < argc; ++i )
|
||||
{
|
||||
const char* arg = argv[i];
|
||||
const char* value;
|
||||
|
||||
if ( ( value = MatchValue( arg, "-s=", "--scene=" ) ) != NULL )
|
||||
{
|
||||
sceneFilter = ParseKey( value, s_sceneKeys, e_ghostSceneCount );
|
||||
}
|
||||
else if ( ( value = MatchValue( arg, "-b=", "--body=" ) ) != NULL )
|
||||
{
|
||||
bodyFilter = ParseKey( value, s_bodyKeys, e_ghostBodyCount );
|
||||
}
|
||||
else if ( ( value = MatchValue( arg, "-m=", "--mirror=" ) ) != NULL )
|
||||
{
|
||||
mirrorFilter = strcmp( value, "all" ) == 0 ? -1 : atoi( value ) != 0;
|
||||
}
|
||||
else if ( ( value = MatchValue( arg, "-p=", "--preset=" ) ) != NULL )
|
||||
{
|
||||
presetFilter = strcmp( value, "all" ) == 0 ? -1 : b3ClampInt( atoi( value ), 0, GHOST_PEEL_PRESET_COUNT - 1 );
|
||||
}
|
||||
else if ( ( value = MatchValue( arg, "-n=", "--steps=" ) ) != NULL )
|
||||
{
|
||||
stepCount = atoi( value );
|
||||
}
|
||||
else if ( ( value = MatchValue( arg, "-w=", "--write=" ) ) != NULL )
|
||||
{
|
||||
writePath = value;
|
||||
}
|
||||
else if ( ( value = MatchValue( arg, "-c=", "--compare=" ) ) != NULL )
|
||||
{
|
||||
comparePath = value;
|
||||
}
|
||||
else if ( ( value = MatchValue( arg, "--speed=", "--speed=" ) ) != NULL )
|
||||
{
|
||||
settings.speed = (float)atof( value );
|
||||
}
|
||||
else if ( ( value = MatchValue( arg, "--yaw=", "--yaw=" ) ) != NULL )
|
||||
{
|
||||
settings.yaw = (float)atof( value );
|
||||
}
|
||||
else if ( ( value = MatchValue( arg, "--friction=", "--friction=" ) ) != NULL )
|
||||
{
|
||||
settings.friction = (float)atof( value );
|
||||
}
|
||||
else if ( ( value = MatchValue( arg, "--cell=", "--cell=" ) ) != NULL )
|
||||
{
|
||||
settings.cellSize = (float)atof( value );
|
||||
}
|
||||
else if ( strcmp( arg, "--fixed-rotation" ) == 0 )
|
||||
{
|
||||
settings.fixedRotation = true;
|
||||
}
|
||||
else if ( strcmp( arg, "--no-speculative" ) == 0 )
|
||||
{
|
||||
settings.speculative = false;
|
||||
}
|
||||
else if ( strcmp( arg, "--no-recycling" ) == 0 )
|
||||
{
|
||||
s_recycling = false;
|
||||
}
|
||||
else if ( strcmp( arg, "--height-field" ) == 0 )
|
||||
{
|
||||
settings.heightField = true;
|
||||
}
|
||||
else if ( strcmp( arg, "-v" ) == 0 || strcmp( arg, "--verbose" ) == 0 )
|
||||
{
|
||||
verbose = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
sceneFilter = -2;
|
||||
}
|
||||
|
||||
if ( sceneFilter == -2 || bodyFilter == -2 )
|
||||
{
|
||||
printf( "Usage: ghost_scan [options]\n"
|
||||
"Runs the Ghost Collisions sample headless and counts ghost manifolds per scene and body.\n"
|
||||
" -s, --scene=<key|all> flat, ramp, cliff, crest, bumps, peel, chamfer, rail (default all)\n"
|
||||
" chamfer runs only the box and cylinder, fixed rotation without speculative\n"
|
||||
" -b, --body=<key|all> box, capsule, upright, sphere, cylinder (default all)\n"
|
||||
" -m, --mirror=<0|1|all> mirrored mesh (default all)\n"
|
||||
" -p, --preset=<0-3|all> PEEL preset (default all)\n"
|
||||
" -n, --steps=<int> steps per config (default 900)\n"
|
||||
" -w, --write=<file> write results as csv, replacing only the rows of this run\n"
|
||||
" -c, --compare=<file> compare with a written csv, fail if any count grew, any config\n"
|
||||
" completed fewer runs, or has no row\n"
|
||||
" --speed=, --yaw=, --friction=, --cell=, --fixed-rotation, --no-speculative\n"
|
||||
" --height-field height field ground, one static body per height field\n"
|
||||
" --no-recycling disable contact recycling\n"
|
||||
" -v, --verbose print every ghost\n"
|
||||
"Exit code is 1 when a compared count grew, completed fewer runs or has no row, 0 otherwise.\n" );
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
Config configs[MAX_CONFIGS];
|
||||
int configCount = BuildConfigs( configs, sceneFilter, presetFilter, mirrorFilter, bodyFilter );
|
||||
|
||||
if ( comparePath != NULL && ReadBaseline( comparePath, configs, configCount ) == false )
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
printf( "ghost scan: %d configs, %d steps, speed %.1f, yaw %.0f, friction %.2f, cell %.2f%s\n", configCount, stepCount,
|
||||
settings.speed, settings.yaw, settings.friction, settings.cellSize, settings.heightField ? ", height field" : "" );
|
||||
fflush( stdout );
|
||||
|
||||
uint64_t ticks = b3GetTicks();
|
||||
for ( int i = 0; i < configCount; ++i )
|
||||
{
|
||||
if ( verbose )
|
||||
{
|
||||
char row[64];
|
||||
FormatRow( row, sizeof( row ), configs + i );
|
||||
printf( "%s %s\n", row, s_bodyKeys[configs[i].body] );
|
||||
}
|
||||
|
||||
RunConfig( configs + i, settings, stepCount, verbose );
|
||||
}
|
||||
float seconds = 0.001f * b3GetMilliseconds( ticks );
|
||||
|
||||
// One row per ground, one column per body. A compared cell that changed prints as old>new.
|
||||
printf( "\n%-18s", "" );
|
||||
for ( int body = 0; body < e_ghostBodyCount; ++body )
|
||||
{
|
||||
if ( bodyFilter < 0 || body == bodyFilter )
|
||||
{
|
||||
printf( "%10s", s_bodyKeys[body] );
|
||||
}
|
||||
}
|
||||
printf( "\n" );
|
||||
|
||||
int totalGhosts = 0;
|
||||
int grewCount = 0;
|
||||
int shrankCount = 0;
|
||||
int missingCount = 0;
|
||||
int fewerRunsCount = 0;
|
||||
int column = 0;
|
||||
for ( int i = 0; i < configCount; ++i )
|
||||
{
|
||||
const Config* c = configs + i;
|
||||
bool newRow = i == 0 || c->scene != configs[i - 1].scene || c->preset != configs[i - 1].preset ||
|
||||
c->mirror != configs[i - 1].mirror;
|
||||
if ( newRow )
|
||||
{
|
||||
char row[64];
|
||||
FormatRow( row, sizeof( row ), c );
|
||||
printf( "%s%-18s", i == 0 ? "" : "\n", row );
|
||||
column = 0;
|
||||
}
|
||||
|
||||
// A scene that skips a body leaves its column empty
|
||||
int bodyColumn = bodyFilter >= 0 ? 0 : (int)c->body;
|
||||
while ( column < bodyColumn )
|
||||
{
|
||||
printf( "%10s", "-" );
|
||||
column += 1;
|
||||
}
|
||||
column += 1;
|
||||
|
||||
char cell[32];
|
||||
if ( comparePath != NULL && c->baseGhostCount < 0 )
|
||||
{
|
||||
snprintf( cell, sizeof( cell ), "?>%d", c->ghostCount );
|
||||
}
|
||||
else if ( c->baseGhostCount >= 0 && c->baseGhostCount != c->ghostCount )
|
||||
{
|
||||
snprintf( cell, sizeof( cell ), "%d>%d", c->baseGhostCount, c->ghostCount );
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf( cell, sizeof( cell ), "%d", c->ghostCount );
|
||||
}
|
||||
printf( "%10s", cell );
|
||||
|
||||
totalGhosts += c->ghostCount;
|
||||
grewCount += c->baseGhostCount >= 0 && c->ghostCount > c->baseGhostCount;
|
||||
shrankCount += c->baseGhostCount >= 0 && c->ghostCount < c->baseGhostCount;
|
||||
missingCount += c->baseGhostCount < 0;
|
||||
fewerRunsCount += c->baseRunCount >= 0 && c->runCount < c->baseRunCount;
|
||||
}
|
||||
|
||||
printf( "\n\ntotal ghosts %d, time %.1f s\n", totalGhosts, seconds );
|
||||
|
||||
for ( int i = 0; i < configCount && fewerRunsCount > 0; ++i )
|
||||
{
|
||||
const Config* c = configs + i;
|
||||
if ( c->baseRunCount >= 0 && c->runCount < c->baseRunCount )
|
||||
{
|
||||
char row[64];
|
||||
FormatRow( row, sizeof( row ), c );
|
||||
printf( "fewer runs: %s %s %d>%d\n", row, s_bodyKeys[c->body], c->baseRunCount, c->runCount );
|
||||
}
|
||||
}
|
||||
|
||||
if ( writePath != NULL && WriteResults( writePath, configs, configCount ) == false )
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
if ( comparePath != NULL )
|
||||
{
|
||||
bool pass = grewCount == 0 && missingCount == 0 && fewerRunsCount == 0;
|
||||
printf( "compared with %s: %d grew, %d shrank, %d missing, %d with fewer runs\n", comparePath, grewCount, shrankCount,
|
||||
missingCount, fewerRunsCount );
|
||||
printf( pass ? "PASS\n" : "FAIL\n" );
|
||||
return pass ? 0 : 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@
|
|||
#endif
|
||||
|
||||
#include "benchmarks.h"
|
||||
#include "mesh_benchmark.h"
|
||||
#include "utils.h"
|
||||
|
||||
#ifdef BOX3D_INTERNAL_BENCHMARKS
|
||||
|
|
@ -215,6 +216,9 @@ static void PrintBenchmarks( const Benchmark* benchmarks, int count )
|
|||
// Compare GJK and SAT on hull pairs in the speculative regime. Static Box3D only.
|
||||
// start /affinity 0x5555 .\build\bin\Release\benchmark.exe --sat -r=5
|
||||
|
||||
// Time mesh creation.
|
||||
// start /affinity 0x5555 .\build\bin\Release\benchmark.exe --mesh -r=5
|
||||
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
#ifdef TRACY_ENABLE
|
||||
|
|
@ -286,6 +290,8 @@ int main( int argc, char** argv )
|
|||
bool enableContinuous = true;
|
||||
bool recordStepTimes = false;
|
||||
bool runSat = false;
|
||||
bool runMesh = false;
|
||||
const char* meshCase = NULL;
|
||||
int simdWidth = 0;
|
||||
|
||||
assert( maxThreadCount <= B3_MAX_WORKERS );
|
||||
|
|
@ -343,6 +349,15 @@ int main( int argc, char** argv )
|
|||
exit( 1 );
|
||||
#endif
|
||||
}
|
||||
else if ( ( value = MatchValue( arg, "-mesh=", "--mesh=" ) ) != NULL )
|
||||
{
|
||||
runMesh = true;
|
||||
meshCase = value;
|
||||
}
|
||||
else if ( strcmp( arg, "-mesh" ) == 0 || strcmp( arg, "--mesh" ) == 0 )
|
||||
{
|
||||
runMesh = true;
|
||||
}
|
||||
else if ( ( value = MatchValue( arg, "-simd=", "--simd-width=" ) ) != NULL )
|
||||
{
|
||||
simdWidth = atoi( value );
|
||||
|
|
@ -372,6 +387,7 @@ int main( int argc, char** argv )
|
|||
"-nc, --no-continuous: disable continuous collision\n"
|
||||
"-s, --record-steps: record step times\n"
|
||||
"-sat, --sat: compare GJK and SAT on hull pairs, then exit\n"
|
||||
"-mesh, --mesh[=<case>]: time b3CreateMesh on several meshes, or one case, then exit\n"
|
||||
"-simd, --simd-width=<4|8>: force the SIMD width (static Box3D only)\n"
|
||||
"-l, --list: list the registered benchmarks\n"
|
||||
"-h, --help: print this help\n" );
|
||||
|
|
@ -402,6 +418,13 @@ int main( int argc, char** argv )
|
|||
}
|
||||
#endif
|
||||
|
||||
if ( runMesh )
|
||||
{
|
||||
RunMeshBenchmarks( runCount, meshCase );
|
||||
free( profiles );
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf( "Starting benchmarks\n" );
|
||||
printf( "======================================\n" );
|
||||
#ifdef BOX3D_INTERNAL_BENCHMARKS
|
||||
|
|
|
|||
233
benchmark/mesh_benchmark.c
Normal file
233
benchmark/mesh_benchmark.c
Normal file
|
|
@ -0,0 +1,233 @@
|
|||
// SPDX-FileCopyrightText: 2025 Erin Catto
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "mesh_benchmark.h"
|
||||
|
||||
#include "box3d/box3d.h"
|
||||
#include "box3d/collision.h"
|
||||
#include "box3d/math_functions.h"
|
||||
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef enum MeshShape
|
||||
{
|
||||
meshShape_wave,
|
||||
meshShape_torus,
|
||||
meshShape_soup,
|
||||
} MeshShape;
|
||||
|
||||
typedef struct MeshCase
|
||||
{
|
||||
const char* name;
|
||||
MeshShape shape;
|
||||
int countA;
|
||||
int countB;
|
||||
bool useMedianSplit;
|
||||
bool identifyEdges;
|
||||
bool weldVertices;
|
||||
} MeshCase;
|
||||
|
||||
typedef struct MeshSource
|
||||
{
|
||||
b3Vec3* vertices;
|
||||
int32_t* indices;
|
||||
int vertexCount;
|
||||
int triangleCount;
|
||||
} MeshSource;
|
||||
|
||||
static float WaveHeight( int i, int j )
|
||||
{
|
||||
return 0.5f * sinf( 0.31f * (float)i ) * cosf( 0.23f * (float)j ) + 0.25f * sinf( 0.07f * (float)( i + 2 * j ) );
|
||||
}
|
||||
|
||||
// Shared-vertex grid, or a triangle soup with three vertices per triangle when unshared is set
|
||||
static MeshSource MakeWave( int xCount, int zCount, bool unshared )
|
||||
{
|
||||
float cellWidth = 0.5f;
|
||||
MeshSource source = { 0 };
|
||||
source.triangleCount = 2 * xCount * zCount;
|
||||
source.indices = malloc( 3 * source.triangleCount * sizeof( int32_t ) );
|
||||
|
||||
if ( unshared == false )
|
||||
{
|
||||
source.vertexCount = ( xCount + 1 ) * ( zCount + 1 );
|
||||
source.vertices = malloc( source.vertexCount * sizeof( b3Vec3 ) );
|
||||
for ( int i = 0; i <= xCount; ++i )
|
||||
{
|
||||
for ( int j = 0; j <= zCount; ++j )
|
||||
{
|
||||
source.vertices[i * ( zCount + 1 ) + j] = (b3Vec3){ cellWidth * i, WaveHeight( i, j ), cellWidth * j };
|
||||
}
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
for ( int i = 0; i < xCount; ++i )
|
||||
{
|
||||
for ( int j = 0; j < zCount; ++j )
|
||||
{
|
||||
int a = i * ( zCount + 1 ) + j;
|
||||
int b = a + 1;
|
||||
int c = a + ( zCount + 1 ) + 1;
|
||||
int d = a + ( zCount + 1 );
|
||||
source.indices[index++] = a;
|
||||
source.indices[index++] = b;
|
||||
source.indices[index++] = c;
|
||||
source.indices[index++] = a;
|
||||
source.indices[index++] = c;
|
||||
source.indices[index++] = d;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
source.vertexCount = 3 * source.triangleCount;
|
||||
source.vertices = malloc( source.vertexCount * sizeof( b3Vec3 ) );
|
||||
int index = 0;
|
||||
for ( int i = 0; i < xCount; ++i )
|
||||
{
|
||||
for ( int j = 0; j < zCount; ++j )
|
||||
{
|
||||
b3Vec3 a = { cellWidth * i, WaveHeight( i, j ), cellWidth * j };
|
||||
b3Vec3 b = { cellWidth * i, WaveHeight( i, j + 1 ), cellWidth * ( j + 1 ) };
|
||||
b3Vec3 c = { cellWidth * ( i + 1 ), WaveHeight( i + 1, j + 1 ), cellWidth * ( j + 1 ) };
|
||||
b3Vec3 d = { cellWidth * ( i + 1 ), WaveHeight( i + 1, j ), cellWidth * j };
|
||||
b3Vec3 tris[6] = { a, b, c, a, c, d };
|
||||
for ( int k = 0; k < 6; ++k )
|
||||
{
|
||||
source.vertices[index] = tris[k];
|
||||
source.indices[index] = index;
|
||||
index += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return source;
|
||||
}
|
||||
|
||||
static MeshSource MakeTorus( int radialCount, int tubularCount )
|
||||
{
|
||||
float radius = 8.0f;
|
||||
float thickness = 2.0f;
|
||||
MeshSource source = { 0 };
|
||||
source.vertexCount = radialCount * tubularCount;
|
||||
source.triangleCount = 2 * radialCount * tubularCount;
|
||||
source.vertices = malloc( source.vertexCount * sizeof( b3Vec3 ) );
|
||||
source.indices = malloc( 3 * source.triangleCount * sizeof( int32_t ) );
|
||||
|
||||
for ( int i = 0; i < radialCount; ++i )
|
||||
{
|
||||
float u = 2.0f * B3_PI * i / radialCount;
|
||||
for ( int j = 0; j < tubularCount; ++j )
|
||||
{
|
||||
float v = 2.0f * B3_PI * j / tubularCount;
|
||||
float r = radius + thickness * cosf( v );
|
||||
source.vertices[i * tubularCount + j] = (b3Vec3){ r * cosf( u ), thickness * sinf( v ), r * sinf( u ) };
|
||||
}
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
for ( int i = 0; i < radialCount; ++i )
|
||||
{
|
||||
int i2 = ( i + 1 ) % radialCount;
|
||||
for ( int j = 0; j < tubularCount; ++j )
|
||||
{
|
||||
int j2 = ( j + 1 ) % tubularCount;
|
||||
int a = i * tubularCount + j;
|
||||
int b = i2 * tubularCount + j;
|
||||
int c = i2 * tubularCount + j2;
|
||||
int d = i * tubularCount + j2;
|
||||
source.indices[index++] = a;
|
||||
source.indices[index++] = c;
|
||||
source.indices[index++] = b;
|
||||
source.indices[index++] = a;
|
||||
source.indices[index++] = d;
|
||||
source.indices[index++] = c;
|
||||
}
|
||||
}
|
||||
|
||||
return source;
|
||||
}
|
||||
|
||||
void RunMeshBenchmarks( int runCount, const char* caseName )
|
||||
{
|
||||
MeshCase cases[] = {
|
||||
{ "wave_64", meshShape_wave, 64, 64, true, true, false },
|
||||
{ "wave_128", meshShape_wave, 128, 128, true, true, false },
|
||||
{ "wave_256", meshShape_wave, 256, 256, true, true, false },
|
||||
{ "wave_128_no_edges", meshShape_wave, 128, 128, true, false, false },
|
||||
{ "wave_128_sah", meshShape_wave, 128, 128, false, true, false },
|
||||
{ "torus_128x64", meshShape_torus, 128, 64, false, true, false },
|
||||
{ "soup_128_weld", meshShape_soup, 128, 128, true, true, true },
|
||||
};
|
||||
int caseCount = sizeof( cases ) / sizeof( cases[0] );
|
||||
|
||||
#ifdef NDEBUG
|
||||
int targetTriangles = 1 << 20;
|
||||
#else
|
||||
int targetTriangles = 1 << 14;
|
||||
#endif
|
||||
|
||||
printf( "benchmark: mesh creation, runs = %d\n", runCount );
|
||||
printf( "%-20s %10s %8s %12s %12s\n", "case", "triangles", "builds", "ms / build", "ns / tri" );
|
||||
|
||||
for ( int caseIndex = 0; caseIndex < caseCount; ++caseIndex )
|
||||
{
|
||||
const MeshCase* mc = cases + caseIndex;
|
||||
if ( caseName != NULL && strcmp( caseName, mc->name ) != 0 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
MeshSource source;
|
||||
if ( mc->shape == meshShape_torus )
|
||||
{
|
||||
source = MakeTorus( mc->countA, mc->countB );
|
||||
}
|
||||
else
|
||||
{
|
||||
source = MakeWave( mc->countA, mc->countB, mc->shape == meshShape_soup );
|
||||
}
|
||||
|
||||
b3MeshDef def = { 0 };
|
||||
def.vertices = source.vertices;
|
||||
def.vertexCount = source.vertexCount;
|
||||
def.indices = source.indices;
|
||||
def.triangleCount = source.triangleCount;
|
||||
def.useMedianSplit = mc->useMedianSplit;
|
||||
def.identifyEdges = mc->identifyEdges;
|
||||
def.weldVertices = mc->weldVertices;
|
||||
def.weldTolerance = mc->weldVertices ? 0.001f : 0.0f;
|
||||
|
||||
int buildCount = targetTriangles / source.triangleCount;
|
||||
if ( buildCount < 1 )
|
||||
{
|
||||
buildCount = 1;
|
||||
}
|
||||
|
||||
float bestMs = FLT_MAX;
|
||||
for ( int runIndex = 0; runIndex < runCount; ++runIndex )
|
||||
{
|
||||
uint64_t ticks = b3GetTicks();
|
||||
for ( int buildIndex = 0; buildIndex < buildCount; ++buildIndex )
|
||||
{
|
||||
b3MeshData* mesh = b3CreateMesh( &def, NULL, 0 );
|
||||
b3DestroyMesh( mesh );
|
||||
}
|
||||
float ms = b3GetMilliseconds( ticks ) / buildCount;
|
||||
bestMs = b3MinFloat( bestMs, ms );
|
||||
}
|
||||
|
||||
float nsPerTriangle = 1.0e6f * bestMs / source.triangleCount;
|
||||
printf( "%-20s %10d %8d %12.3f %12.1f\n", mc->name, source.triangleCount, buildCount, bestMs, nsPerTriangle );
|
||||
|
||||
free( source.vertices );
|
||||
free( source.indices );
|
||||
}
|
||||
|
||||
printf( "\n" );
|
||||
}
|
||||
6
benchmark/mesh_benchmark.h
Normal file
6
benchmark/mesh_benchmark.h
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
// SPDX-FileCopyrightText: 2025 Erin Catto
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#pragma once
|
||||
|
||||
void RunMeshBenchmarks( int runCount, const char* caseName );
|
||||
672
benchmark/mesh_soak.c
Normal file
672
benchmark/mesh_soak.c
Normal file
|
|
@ -0,0 +1,672 @@
|
|||
// SPDX-FileCopyrightText: 2026 Erin Catto
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
// Headless soak of the Continuous / Mesh Drop sample. Each generation drops 1024 small bodies on a
|
||||
// wave mesh and steps until every body sleeps. A generation fails if a body falls through the mesh
|
||||
// or the pile is still awake at the step limit. Tunnels are rare, so the soak also counts bodies that
|
||||
// sink into the wave past a few depth levels and can compare those counts against a baseline.
|
||||
// Generations run in parallel, one single threaded world per thread. The printed seed reproduces a
|
||||
// generation in the sample.
|
||||
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
|
||||
#include "core.h"
|
||||
#include "mesh_drop.h"
|
||||
|
||||
#include "box3d/box3d.h"
|
||||
#include "box3d/collision.h"
|
||||
#include "box3d/math_functions.h"
|
||||
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define MAX_REPORTED_FAILURES 32
|
||||
#define MAX_THREADS 64
|
||||
|
||||
typedef enum FailureKind
|
||||
{
|
||||
e_tunnel,
|
||||
e_awake,
|
||||
} FailureKind;
|
||||
|
||||
typedef struct Failure
|
||||
{
|
||||
FailureKind kind;
|
||||
MeshDropShape shape;
|
||||
int generation;
|
||||
uint32_t seed;
|
||||
int step;
|
||||
int index;
|
||||
b3Pos position;
|
||||
} Failure;
|
||||
|
||||
typedef struct ShapeStats
|
||||
{
|
||||
int generationCount;
|
||||
int tunnelCount;
|
||||
int awakeCount;
|
||||
int depthCounts[MESH_DROP_DEPTH_LEVEL_COUNT];
|
||||
|
||||
float maxDepth;
|
||||
uint32_t maxSeed;
|
||||
int maxGeneration;
|
||||
int maxIndex;
|
||||
int maxStep;
|
||||
} ShapeStats;
|
||||
|
||||
typedef struct Soak
|
||||
{
|
||||
b3Mutex* mutex;
|
||||
b3MeshData* groundMesh;
|
||||
b3HullData* cylinder;
|
||||
MeshDropSettings settings;
|
||||
uint32_t baseSeed;
|
||||
int generationCount;
|
||||
int nextGeneration;
|
||||
|
||||
// -1 rotates through the shapes
|
||||
int shapeFilter;
|
||||
|
||||
bool fixedSeed;
|
||||
bool recycling;
|
||||
|
||||
int completedCount;
|
||||
int failureCount;
|
||||
long long totalSteps;
|
||||
int maxSteps;
|
||||
ShapeStats stats[e_meshDropShapeCount];
|
||||
Failure failures[MAX_REPORTED_FAILURES];
|
||||
} Soak;
|
||||
|
||||
static void RecordFailure( Soak* soak, const Failure* failure )
|
||||
{
|
||||
b3LockMutex( soak->mutex );
|
||||
if ( soak->failureCount < MAX_REPORTED_FAILURES )
|
||||
{
|
||||
soak->failures[soak->failureCount] = *failure;
|
||||
}
|
||||
soak->failureCount += 1;
|
||||
b3UnlockMutex( soak->mutex );
|
||||
|
||||
const char* kind = failure->kind == e_tunnel ? "TUNNEL" : "AWAKE";
|
||||
printf( "%s: generation %d, %s, seed %u, step %d, body (%d, %d) at (%.2f, %.2f, %.2f)\n", kind, failure->generation,
|
||||
g_meshDropShapeNames[failure->shape], failure->seed, failure->step, failure->index / MESH_DROP_GRID_COUNT,
|
||||
failure->index % MESH_DROP_GRID_COUNT, (float)failure->position.x, (float)failure->position.y,
|
||||
(float)failure->position.z );
|
||||
}
|
||||
|
||||
// Mirrors MeshDrop::Generate and the auto generate step loop. Returns the step count.
|
||||
static int RunGeneration( Soak* soak, int generation, uint32_t seed, MeshDropShape shape, b3BodyId* bodies,
|
||||
MeshDropDepth* depth, int* failureKind )
|
||||
{
|
||||
b3WorldDef worldDef = b3DefaultWorldDef();
|
||||
worldDef.workerCount = 1;
|
||||
|
||||
// The world registry is global and not thread safe
|
||||
b3LockMutex( soak->mutex );
|
||||
b3WorldId worldId = b3CreateWorld( &worldDef );
|
||||
b3UnlockMutex( soak->mutex );
|
||||
|
||||
if ( soak->recycling == false )
|
||||
{
|
||||
b3World_SetContactRecycleDistance( worldId, 0.0f );
|
||||
}
|
||||
|
||||
CreateMeshDropGround( worldId, soak->groundMesh );
|
||||
|
||||
MeshDropSettings settings = soak->settings;
|
||||
settings.shape = shape;
|
||||
CreateMeshDropBodies( worldId, settings, seed, soak->cylinder, bodies );
|
||||
ResetMeshDropDepth( depth, settings, soak->cylinder );
|
||||
|
||||
float timeStep = 1.0f / 60.0f;
|
||||
int subStepCount = 4;
|
||||
int maxSteps = GetMeshDropStepLimit( shape );
|
||||
float tunnelHeight = GetMeshDropTunnelHeight();
|
||||
int step = 0;
|
||||
bool failed = false;
|
||||
|
||||
while ( failed == false )
|
||||
{
|
||||
b3World_Step( worldId, timeStep, subStepCount );
|
||||
UpdateMeshDropDepth( worldId, depth );
|
||||
step += 1;
|
||||
|
||||
for ( int i = 0; i < MESH_DROP_BODY_COUNT; ++i )
|
||||
{
|
||||
b3Pos center = b3Body_GetWorldCenter( bodies[i] );
|
||||
if ( center.y < tunnelHeight )
|
||||
{
|
||||
Failure failure = { e_tunnel, shape, generation, seed, step, i, center };
|
||||
RecordFailure( soak, &failure );
|
||||
*failureKind = e_tunnel;
|
||||
failed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( b3World_GetBodyEvents( worldId ).moveCount == 0 )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if ( failed == false && step > maxSteps )
|
||||
{
|
||||
int awakeIndex = 0;
|
||||
for ( int i = 0; i < MESH_DROP_BODY_COUNT; ++i )
|
||||
{
|
||||
if ( b3Body_IsAwake( bodies[i] ) )
|
||||
{
|
||||
awakeIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
b3Pos center = b3Body_GetWorldCenter( bodies[awakeIndex] );
|
||||
Failure failure = { e_awake, shape, generation, seed, step, awakeIndex, center };
|
||||
RecordFailure( soak, &failure );
|
||||
*failureKind = e_awake;
|
||||
failed = true;
|
||||
}
|
||||
}
|
||||
|
||||
b3LockMutex( soak->mutex );
|
||||
b3DestroyWorld( worldId );
|
||||
b3UnlockMutex( soak->mutex );
|
||||
|
||||
return step;
|
||||
}
|
||||
|
||||
static void SoakWorker( void* context )
|
||||
{
|
||||
Soak* soak = context;
|
||||
b3BodyId* bodies = malloc( MESH_DROP_BODY_COUNT * sizeof( b3BodyId ) );
|
||||
MeshDropDepth* depth = malloc( sizeof( MeshDropDepth ) );
|
||||
|
||||
while ( true )
|
||||
{
|
||||
b3LockMutex( soak->mutex );
|
||||
int generation = soak->nextGeneration;
|
||||
soak->nextGeneration += 1;
|
||||
b3UnlockMutex( soak->mutex );
|
||||
|
||||
if ( generation >= soak->generationCount )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
uint32_t seed = soak->fixedSeed ? soak->baseSeed : GetMeshDropSeed( soak->baseSeed, generation );
|
||||
MeshDropShape shape =
|
||||
soak->shapeFilter >= 0 ? (MeshDropShape)soak->shapeFilter : (MeshDropShape)( generation % e_meshDropShapeCount );
|
||||
|
||||
int failureKind = -1;
|
||||
int steps = RunGeneration( soak, generation, seed, shape, bodies, depth, &failureKind );
|
||||
|
||||
int depthCounts[MESH_DROP_DEPTH_LEVEL_COUNT];
|
||||
GetMeshDropDepthCounts( depth, depthCounts );
|
||||
|
||||
b3LockMutex( soak->mutex );
|
||||
soak->completedCount += 1;
|
||||
soak->totalSteps += steps;
|
||||
soak->maxSteps = b3MaxInt( soak->maxSteps, steps );
|
||||
|
||||
ShapeStats* stats = soak->stats + shape;
|
||||
stats->generationCount += 1;
|
||||
stats->tunnelCount += failureKind == e_tunnel ? 1 : 0;
|
||||
stats->awakeCount += failureKind == e_awake ? 1 : 0;
|
||||
for ( int i = 0; i < MESH_DROP_DEPTH_LEVEL_COUNT; ++i )
|
||||
{
|
||||
stats->depthCounts[i] += depthCounts[i];
|
||||
}
|
||||
|
||||
// Ties go to the earlier generation so the report does not depend on thread timing
|
||||
if ( depth->maxDepth > stats->maxDepth ||
|
||||
( depth->maxDepth == stats->maxDepth && generation < stats->maxGeneration ) )
|
||||
{
|
||||
stats->maxDepth = depth->maxDepth;
|
||||
stats->maxSeed = seed;
|
||||
stats->maxGeneration = generation;
|
||||
stats->maxIndex = depth->maxIndex;
|
||||
stats->maxStep = depth->maxStep;
|
||||
}
|
||||
|
||||
int completed = soak->completedCount;
|
||||
b3UnlockMutex( soak->mutex );
|
||||
|
||||
if ( completed % b3MaxInt( 100, soak->generationCount / 10 ) == 0 )
|
||||
{
|
||||
printf( "%d generations, %d bodies\n", completed, completed * MESH_DROP_BODY_COUNT );
|
||||
fflush( stdout );
|
||||
}
|
||||
}
|
||||
|
||||
free( depth );
|
||||
free( bodies );
|
||||
}
|
||||
|
||||
static const char* GetFilterName( int shapeFilter )
|
||||
{
|
||||
return shapeFilter >= 0 ? g_meshDropShapeNames[shapeFilter] : "all";
|
||||
}
|
||||
|
||||
// A baseline row starts with the run that made it, so one file can hold several runs
|
||||
static void GetBaselineKey( const Soak* soak, char* key, int size )
|
||||
{
|
||||
snprintf( key, size, "%s,%u,%d,", GetFilterName( soak->shapeFilter ), soak->baseSeed, soak->generationCount );
|
||||
}
|
||||
|
||||
// Replaces the rows of this run and keeps the rest
|
||||
static void WriteBaseline( const Soak* soak, const char* path )
|
||||
{
|
||||
char key[64];
|
||||
GetBaselineKey( soak, key, sizeof( key ) );
|
||||
size_t keyLength = strlen( key );
|
||||
|
||||
// Read the whole file so neither a row count nor a row length can drop a row
|
||||
char* text = NULL;
|
||||
FILE* file = fopen( path, "rb" );
|
||||
if ( file != NULL )
|
||||
{
|
||||
fseek( file, 0, SEEK_END );
|
||||
long textLength = ftell( file );
|
||||
fseek( file, 0, SEEK_SET );
|
||||
text = malloc( textLength + 1 );
|
||||
textLength = (long)fread( text, 1, textLength, file );
|
||||
text[textLength] = '\0';
|
||||
fclose( file );
|
||||
}
|
||||
|
||||
file = fopen( path, "w" );
|
||||
if ( file == NULL )
|
||||
{
|
||||
printf( "cannot write %s\n", path );
|
||||
free( text );
|
||||
return;
|
||||
}
|
||||
|
||||
fprintf( file, "filter,base,generations,shape,tunnels,awake" );
|
||||
for ( int i = 0; i < MESH_DROP_DEPTH_LEVEL_COUNT; ++i )
|
||||
{
|
||||
fprintf( file, ",depth%g", g_meshDropDepthLevels[i] );
|
||||
}
|
||||
fprintf( file, "\n" );
|
||||
|
||||
if ( text != NULL )
|
||||
{
|
||||
bool header = true;
|
||||
char* line = text;
|
||||
while ( *line != '\0' )
|
||||
{
|
||||
char* next = strchr( line, '\n' );
|
||||
size_t lineLength = next != NULL ? (size_t)( next - line ) : strlen( line );
|
||||
if ( lineLength > 0 && line[lineLength - 1] == '\r' )
|
||||
{
|
||||
lineLength -= 1;
|
||||
}
|
||||
|
||||
if ( header == false && lineLength > 0 && strncmp( line, key, keyLength ) != 0 )
|
||||
{
|
||||
fprintf( file, "%.*s\n", (int)lineLength, line );
|
||||
}
|
||||
|
||||
header = false;
|
||||
line = next != NULL ? next + 1 : line + strlen( line );
|
||||
}
|
||||
|
||||
free( text );
|
||||
}
|
||||
|
||||
for ( int shape = 0; shape < e_meshDropShapeCount; ++shape )
|
||||
{
|
||||
const ShapeStats* stats = soak->stats + shape;
|
||||
if ( stats->generationCount == 0 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
fprintf( file, "%s,%u,%d,%s,%d,%d", GetFilterName( soak->shapeFilter ), soak->baseSeed, soak->generationCount,
|
||||
g_meshDropShapeNames[shape], stats->tunnelCount, stats->awakeCount );
|
||||
for ( int i = 0; i < MESH_DROP_DEPTH_LEVEL_COUNT; ++i )
|
||||
{
|
||||
fprintf( file, ",%d", stats->depthCounts[i] );
|
||||
}
|
||||
fprintf( file, "\n" );
|
||||
}
|
||||
|
||||
fclose( file );
|
||||
printf( "wrote %s\n", path );
|
||||
}
|
||||
|
||||
// Returns 0 when no count grew past its noise band, 1 when one did, 2 when the baseline has no rows for this run
|
||||
static int CompareBaseline( const Soak* soak, const char* path )
|
||||
{
|
||||
FILE* file = fopen( path, "r" );
|
||||
if ( file == NULL )
|
||||
{
|
||||
printf( "cannot read %s\n", path );
|
||||
return 2;
|
||||
}
|
||||
|
||||
char line[512];
|
||||
if ( fgets( line, sizeof( line ), file ) == NULL )
|
||||
{
|
||||
fclose( file );
|
||||
printf( "empty baseline %s\n", path );
|
||||
return 2;
|
||||
}
|
||||
|
||||
int result = 0;
|
||||
int changedCount = 0;
|
||||
int matchedCount = 0;
|
||||
|
||||
while ( fgets( line, sizeof( line ), file ) != NULL )
|
||||
{
|
||||
char filter[32];
|
||||
char shapeName[32];
|
||||
unsigned int base;
|
||||
int generations;
|
||||
int counts[2 + MESH_DROP_DEPTH_LEVEL_COUNT];
|
||||
|
||||
_Static_assert( MESH_DROP_DEPTH_LEVEL_COUNT == 4, "update the baseline row format" );
|
||||
int fieldCount = sscanf( line, "%31[^,],%u,%d,%31[^,],%d,%d,%d,%d,%d,%d", filter, &base, &generations, shapeName,
|
||||
counts + 0, counts + 1, counts + 2, counts + 3, counts + 4, counts + 5 );
|
||||
if ( fieldCount != 10 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( strcmp( filter, GetFilterName( soak->shapeFilter ) ) != 0 || base != soak->baseSeed ||
|
||||
generations != soak->generationCount )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int shape = -1;
|
||||
for ( int i = 0; i < e_meshDropShapeCount; ++i )
|
||||
{
|
||||
if ( strcmp( shapeName, g_meshDropShapeNames[i] ) == 0 )
|
||||
{
|
||||
shape = i;
|
||||
}
|
||||
}
|
||||
|
||||
if ( shape < 0 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
matchedCount += 1;
|
||||
|
||||
const ShapeStats* stats = soak->stats + shape;
|
||||
int current[2 + MESH_DROP_DEPTH_LEVEL_COUNT] = { stats->tunnelCount, stats->awakeCount };
|
||||
for ( int i = 0; i < MESH_DROP_DEPTH_LEVEL_COUNT; ++i )
|
||||
{
|
||||
current[2 + i] = stats->depthCounts[i];
|
||||
}
|
||||
|
||||
for ( int i = 0; i < 2 + MESH_DROP_DEPTH_LEVEL_COUNT; ++i )
|
||||
{
|
||||
if ( current[i] == counts[i] )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Any collision change reshuffles the chaotic pile, so a count moves by about its square root
|
||||
// even when nothing got worse. Flag growth past three of those. A count that was zero flags on any
|
||||
// growth, since a good build never sinks that deep.
|
||||
float band = 3.0f * sqrtf( (float)counts[i] );
|
||||
bool regressed = i < 2 ? current[i] > counts[i] : current[i] > counts[i] + band;
|
||||
|
||||
char column[32];
|
||||
if ( i < 2 )
|
||||
{
|
||||
snprintf( column, sizeof( column ), i == 0 ? "tunnels" : "awake" );
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf( column, sizeof( column ), "> %g slop", g_meshDropDepthLevels[i - 2] );
|
||||
}
|
||||
|
||||
printf( " %-9s %-11s %d>%d%s\n", shapeName, column, counts[i], current[i], regressed ? " GREW" : "" );
|
||||
changedCount += 1;
|
||||
result = regressed ? 1 : result;
|
||||
}
|
||||
}
|
||||
|
||||
fclose( file );
|
||||
|
||||
if ( matchedCount == 0 )
|
||||
{
|
||||
printf( "%s has no rows for -s=%s -b=%u -g=%d\n", path, GetFilterName( soak->shapeFilter ), soak->baseSeed,
|
||||
soak->generationCount );
|
||||
return 2;
|
||||
}
|
||||
|
||||
printf( "compared with %s: %d changed, %s\n", path, changedCount, result == 0 ? "none grew past noise" : "GREW" );
|
||||
return result;
|
||||
}
|
||||
|
||||
static const char* MatchValue( const char* arg, const char* shortName, const char* longName )
|
||||
{
|
||||
size_t shortLength = strlen( shortName );
|
||||
if ( strncmp( arg, shortName, shortLength ) == 0 )
|
||||
{
|
||||
return arg + shortLength;
|
||||
}
|
||||
|
||||
size_t longLength = strlen( longName );
|
||||
if ( strncmp( arg, longName, longLength ) == 0 )
|
||||
{
|
||||
return arg + longLength;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
int generationCount = 1000;
|
||||
int threadCount = 8;
|
||||
int shapeFilter = e_meshDropBox;
|
||||
uint32_t seed = (uint32_t)b3GetTicks();
|
||||
bool fixedSeed = false;
|
||||
bool recycling = true;
|
||||
const char* writePath = NULL;
|
||||
const char* comparePath = NULL;
|
||||
MeshDropSettings settings = GetDefaultMeshDropSettings();
|
||||
|
||||
for ( int i = 1; i < argc; ++i )
|
||||
{
|
||||
const char* arg = argv[i];
|
||||
const char* value;
|
||||
|
||||
if ( ( value = MatchValue( arg, "-g=", "--generations=" ) ) != NULL )
|
||||
{
|
||||
generationCount = atoi( value );
|
||||
}
|
||||
else if ( ( value = MatchValue( arg, "-t=", "--threads=" ) ) != NULL )
|
||||
{
|
||||
threadCount = b3ClampInt( atoi( value ), 1, MAX_THREADS );
|
||||
}
|
||||
else if ( ( value = MatchValue( arg, "-s=", "--shape=" ) ) != NULL )
|
||||
{
|
||||
shapeFilter = -2;
|
||||
for ( int k = 0; k < e_meshDropShapeCount; ++k )
|
||||
{
|
||||
if ( strcmp( value, g_meshDropShapeNames[k] ) == 0 )
|
||||
{
|
||||
shapeFilter = k;
|
||||
}
|
||||
}
|
||||
|
||||
if ( strcmp( value, "all" ) == 0 )
|
||||
{
|
||||
shapeFilter = -1;
|
||||
}
|
||||
|
||||
if ( shapeFilter == -2 )
|
||||
{
|
||||
printf( "unknown shape: %s\n", value );
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
else if ( ( value = MatchValue( arg, "-seed=", "--seed=" ) ) != NULL )
|
||||
{
|
||||
seed = (uint32_t)strtoul( value, NULL, 10 );
|
||||
fixedSeed = true;
|
||||
}
|
||||
else if ( ( value = MatchValue( arg, "-b=", "--base-seed=" ) ) != NULL )
|
||||
{
|
||||
seed = (uint32_t)strtoul( value, NULL, 10 );
|
||||
}
|
||||
else if ( ( value = MatchValue( arg, "-a=", "--amplitude=" ) ) != NULL )
|
||||
{
|
||||
settings.amplitude = (float)atof( value );
|
||||
}
|
||||
else if ( ( value = MatchValue( arg, "-w=", "--write=" ) ) != NULL )
|
||||
{
|
||||
writePath = value;
|
||||
}
|
||||
else if ( ( value = MatchValue( arg, "-c=", "--compare=" ) ) != NULL )
|
||||
{
|
||||
comparePath = value;
|
||||
}
|
||||
else if ( strcmp( arg, "--no-recycling" ) == 0 )
|
||||
{
|
||||
recycling = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf( "Usage: mesh_soak [options]\n"
|
||||
"Drops %d bodies per generation on the Mesh Drop wave mesh until they sleep.\n"
|
||||
"Fails on a body below y = -2 (tunnel) or a pile awake past the step limit.\n"
|
||||
"Counts bodies that sink into the wave deeper than each depth level.\n"
|
||||
" -g, --generations=<int> generation count (default 1000)\n"
|
||||
" -t, --threads=<int> worker threads, one world each (default 8)\n"
|
||||
" -s, --shape=<name> box, capsule, cylinder, sphere or all (default box)\n"
|
||||
" -b, --base-seed=<uint> base seed, each generation hashes its own seed from it (default random)\n"
|
||||
" --seed=<uint> run every generation with this exact seed (replay)\n"
|
||||
" -a, --amplitude=<float> wave amplitude (default 0.5)\n"
|
||||
" -w, --write=<csv> write the counts as a baseline, replacing only the rows of this run\n"
|
||||
" -c, --compare=<csv> compare the counts with the baseline rows from the same -s, -b and -g\n"
|
||||
" --no-recycling disable contact recycling\n"
|
||||
"Exit code is 0 when every generation passes and no count grew past noise, 1 otherwise,\n"
|
||||
"2 for bad arguments or a baseline from a different run.\n",
|
||||
MESH_DROP_BODY_COUNT );
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
if ( fixedSeed && ( writePath != NULL || comparePath != NULL ) )
|
||||
{
|
||||
printf( "a baseline needs a base seed, not --seed\n" );
|
||||
return 2;
|
||||
}
|
||||
|
||||
Soak soak = { 0 };
|
||||
soak.mutex = b3CreateMutex();
|
||||
soak.settings = settings;
|
||||
soak.recycling = recycling;
|
||||
soak.groundMesh = CreateMeshDropMesh( settings.amplitude );
|
||||
soak.cylinder = CreateMeshDropCylinder();
|
||||
soak.baseSeed = seed;
|
||||
soak.fixedSeed = fixedSeed;
|
||||
soak.generationCount = generationCount;
|
||||
soak.shapeFilter = shapeFilter;
|
||||
|
||||
for ( int i = 0; i < e_meshDropShapeCount; ++i )
|
||||
{
|
||||
soak.stats[i].maxDepth = -FLT_MAX;
|
||||
soak.stats[i].maxGeneration = INT32_MAX;
|
||||
}
|
||||
|
||||
printf( "mesh soak: %d generations, %d threads, shape %s, %s seed %u\n", generationCount, threadCount,
|
||||
GetFilterName( shapeFilter ), fixedSeed ? "fixed" : "base", seed );
|
||||
fflush( stdout );
|
||||
|
||||
uint64_t ticks = b3GetTicks();
|
||||
|
||||
b3Thread* threads[MAX_THREADS];
|
||||
for ( int i = 0; i < threadCount; ++i )
|
||||
{
|
||||
threads[i] = b3CreateThread( SoakWorker, &soak, "soak" );
|
||||
}
|
||||
|
||||
for ( int i = 0; i < threadCount; ++i )
|
||||
{
|
||||
b3JoinThread( threads[i] );
|
||||
}
|
||||
|
||||
float seconds = 0.001f * b3GetMilliseconds( ticks );
|
||||
double averageSteps = soak.completedCount > 0 ? (double)soak.totalSteps / soak.completedCount : 0.0;
|
||||
float slop = B3_LINEAR_SLOP;
|
||||
|
||||
printf( "\n%-9s %8s %8s %6s", "shape", "bodies", "tunnels", "awake" );
|
||||
for ( int i = 0; i < MESH_DROP_DEPTH_LEVEL_COUNT; ++i )
|
||||
{
|
||||
char label[32];
|
||||
snprintf( label, sizeof( label ), "> %g slop", g_meshDropDepthLevels[i] );
|
||||
printf( " %10s", label );
|
||||
}
|
||||
printf( " deepest\n" );
|
||||
|
||||
for ( int shape = 0; shape < e_meshDropShapeCount; ++shape )
|
||||
{
|
||||
const ShapeStats* stats = soak.stats + shape;
|
||||
if ( stats->generationCount == 0 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
printf( "%-9s %8d %8d %6d", g_meshDropShapeNames[shape], stats->generationCount * MESH_DROP_BODY_COUNT,
|
||||
stats->tunnelCount, stats->awakeCount );
|
||||
for ( int i = 0; i < MESH_DROP_DEPTH_LEVEL_COUNT; ++i )
|
||||
{
|
||||
printf( " %10d", stats->depthCounts[i] );
|
||||
}
|
||||
|
||||
if ( stats->maxIndex >= 0 )
|
||||
{
|
||||
printf( " %.1f slop, seed %u body (%d, %d) step %d\n", stats->maxDepth / slop, stats->maxSeed,
|
||||
stats->maxIndex / MESH_DROP_GRID_COUNT, stats->maxIndex % MESH_DROP_GRID_COUNT, stats->maxStep );
|
||||
}
|
||||
else
|
||||
{
|
||||
printf( "\n" );
|
||||
}
|
||||
}
|
||||
|
||||
printf( "\nsteps to sleep: average %.0f, max %d, time %.1f s\n", averageSteps, soak.maxSteps, seconds );
|
||||
|
||||
int reported = b3MinInt( soak.failureCount, MAX_REPORTED_FAILURES );
|
||||
for ( int i = 0; i < reported; ++i )
|
||||
{
|
||||
Failure* f = soak.failures + i;
|
||||
printf( " %s %s seed %u body (%d, %d)\n", f->kind == e_tunnel ? "tunnel" : "awake", g_meshDropShapeNames[f->shape],
|
||||
f->seed, f->index / MESH_DROP_GRID_COUNT, f->index % MESH_DROP_GRID_COUNT );
|
||||
}
|
||||
|
||||
int exitCode = soak.failureCount == 0 ? 0 : 1;
|
||||
|
||||
if ( writePath != NULL )
|
||||
{
|
||||
WriteBaseline( &soak, writePath );
|
||||
}
|
||||
|
||||
if ( comparePath != NULL )
|
||||
{
|
||||
int compareResult = CompareBaseline( &soak, comparePath );
|
||||
exitCode = b3MaxInt( exitCode, compareResult );
|
||||
}
|
||||
|
||||
printf( exitCode == 0 ? "PASS\n" : "FAIL\n" );
|
||||
|
||||
b3DestroyHull( soak.cylinder );
|
||||
b3DestroyMesh( soak.groundMesh );
|
||||
b3DestroyMutex( soak.mutex );
|
||||
|
||||
return exitCode;
|
||||
}
|
||||
9
benchmark/soak_baseline.csv
Normal file
9
benchmark/soak_baseline.csv
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
filter,base,generations,shape,tunnels,awake,depth4,depth8,depth16,depth32
|
||||
all,12345,1000,box,0,0,1538,220,3,0
|
||||
all,12345,1000,capsule,0,0,14507,3488,28,0
|
||||
all,12345,1000,cylinder,0,0,11210,2353,37,0
|
||||
all,12345,1000,sphere,0,0,56,0,0,0
|
||||
all,12345,16000,box,0,0,23676,3191,44,0
|
||||
all,12345,16000,capsule,0,0,231496,54552,515,0
|
||||
all,12345,16000,cylinder,0,0,178981,37441,480,0
|
||||
all,12345,16000,sphere,0,0,987,0,0,0
|
||||
|
64
docs/images/build.sh
Normal file
64
docs/images/build.sh
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
#!/bin/bash
|
||||
# Usage: ./build.sh [--force] [name.asy ...]
|
||||
# https://asymptote.sourceforge.io/doc/colors.png
|
||||
|
||||
asy="/c/Program Files/Asymptote/asy.exe"
|
||||
if [ ! -x "$asy" ]; then
|
||||
echo "missing $asy"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd "$(dirname "$0")" || exit 1
|
||||
|
||||
force=0
|
||||
sources=()
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--force) force=1 ;;
|
||||
*) sources+=("$arg") ;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ ${#sources[@]} -eq 0 ]; then
|
||||
sources=(*.asy)
|
||||
fi
|
||||
|
||||
# asy can exit 0 after a failed TeX run, so judge success by a fresh svg
|
||||
marker=$(mktemp)
|
||||
trap 'rm -f "$marker"' EXIT
|
||||
|
||||
status=0
|
||||
failed=0
|
||||
for src in "${sources[@]}"; do
|
||||
name=$(basename "$src" .asy)
|
||||
svg="$name.svg"
|
||||
|
||||
# Never clobber a hand drawn svg of the same name, delete it first to replace it
|
||||
if [ -f "$svg" ] && ! head -c 300 "$svg" | grep -q dvisvgm; then
|
||||
echo "skip $src: $svg was not made by asy"
|
||||
status=1
|
||||
continue
|
||||
fi
|
||||
|
||||
if [ $force -eq 0 ] && [ "$svg" -nt "$src" ]; then
|
||||
echo "fresh $svg"
|
||||
continue
|
||||
fi
|
||||
|
||||
touch "$marker"
|
||||
"$asy" -noV -o "$name" "$src"
|
||||
if [ "$svg" -nt "$marker" ]; then
|
||||
echo "built $svg"
|
||||
else
|
||||
echo "failed $src"
|
||||
status=1
|
||||
failed=1
|
||||
fi
|
||||
done
|
||||
|
||||
# Leftovers from asy's TeX pipe. Keep the log after a failure, it has the TeX error.
|
||||
rm -f texput.aux
|
||||
if [ $failed -eq 0 ]; then
|
||||
rm -f texput.log
|
||||
fi
|
||||
exit $status
|
||||
267
docs/images/saddle_region.asy
Normal file
267
docs/images/saddle_region.asy
Normal file
|
|
@ -0,0 +1,267 @@
|
|||
settings.outformat = "svg";
|
||||
settings.render = 0;
|
||||
settings.prc = false;
|
||||
|
||||
import three;
|
||||
|
||||
real px = 0.75bp;
|
||||
|
||||
pen ink = rgb("231f20");
|
||||
pen meshPen = ink + 0.6px;
|
||||
pen regionFill = rgb("f2d4d0");
|
||||
pen regionPen = rgb("a8322a") + 1.0px;
|
||||
pen ridgeColor = rgb("c26a17");
|
||||
pen gullyColor = rgb("1f5c99");
|
||||
pen sliceFill = gray(0.93) + opacity(0.75);
|
||||
pen guidePen = gray(0.55) + 0.5px + linetype(new real[] {4, 3});
|
||||
pen hullPen = ink + 0.7px + linetype(new real[] {5, 3});
|
||||
|
||||
real arrowSize = 5px;
|
||||
triple lightDirection = unit((1, 4, 2));
|
||||
|
||||
// The Saddle Vertex sample hub, spokes alternate 8 degree ridges and 32 degree gullies
|
||||
int spokeCount = 6;
|
||||
real fanRadius = 1.5;
|
||||
real[] drops = {8, 32, 8, 32, 8, 32};
|
||||
|
||||
// The slice plane sits this far above the hub. Planes through the hub cut it in lines.
|
||||
real sliceHeight = 1.6;
|
||||
real sliceRadius = sliceHeight * Tan(40);
|
||||
|
||||
triple[] spokes;
|
||||
for (int i = 0; i < spokeCount; ++i)
|
||||
{
|
||||
real angle = 60 * i;
|
||||
spokes.push(fanRadius * (Cos(angle), -Tan(drops[i]), Sin(angle)));
|
||||
}
|
||||
|
||||
bool IsRidge(int i)
|
||||
{
|
||||
return i % 2 == 0;
|
||||
}
|
||||
|
||||
pen SpokePen(int i)
|
||||
{
|
||||
return IsRidge(i) ? ridgeColor : gullyColor;
|
||||
}
|
||||
|
||||
// Gnomonic coordinates: a normal n maps to (n.x, n.z) / n.y on the slice, so every plane through
|
||||
// the hub maps to a line and n . e <= 0 maps to a half plane
|
||||
pair Gnomonic(triple n)
|
||||
{
|
||||
return (n.x / n.y, n.z / n.y);
|
||||
}
|
||||
|
||||
// Half plane of spoke i on the unit slice: dot(p, u) <= offset
|
||||
pair SpokeDirection(int i)
|
||||
{
|
||||
return (Cos(60 * i), Sin(60 * i));
|
||||
}
|
||||
|
||||
real SpokeOffset(int i)
|
||||
{
|
||||
return Tan(drops[i]);
|
||||
}
|
||||
|
||||
// Sutherland Hodgman clip of a convex polygon against dot(p, u) <= offset
|
||||
pair[] ClipPolygon(pair[] poly, pair u, real offset)
|
||||
{
|
||||
pair[] result;
|
||||
int n = poly.length;
|
||||
for (int k = 0; k < n; ++k)
|
||||
{
|
||||
pair a = poly[k];
|
||||
pair b = poly[(k + 1) % n];
|
||||
real da = dot(a, u) - offset;
|
||||
real db = dot(b, u) - offset;
|
||||
if (da <= 0)
|
||||
result.push(a);
|
||||
if (da * db < 0)
|
||||
result.push(a + da / (da - db) * (b - a));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
pair[] region = { (-10, -10), (10, -10), (10, 10), (-10, 10) };
|
||||
for (int i = 0; i < spokeCount; ++i)
|
||||
region = ClipPolygon(region, SpokeDirection(i), SpokeOffset(i));
|
||||
|
||||
// Each face normal is perpendicular to its two spokes, so it lies on both of their lines
|
||||
pair[] faceNormals;
|
||||
for (int i = 0; i < spokeCount; ++i)
|
||||
{
|
||||
triple n = cross(spokes[(i + 1) % spokeCount], spokes[i]);
|
||||
if (n.y < 0)
|
||||
n = -n;
|
||||
faceNormals.push(Gnomonic(n));
|
||||
}
|
||||
|
||||
// A face normal leans past the gully it borders, so sort by angle before drawing the hull
|
||||
pair[] hullPoints = sort(faceNormals, new bool(pair a, pair b) { return degrees(a, false) < degrees(b, false); });
|
||||
|
||||
// End points of the line of spoke i, clipped to a disk of the given radius on the unit slice
|
||||
pair[] SpokeLine(int i, real radius)
|
||||
{
|
||||
pair u = SpokeDirection(i);
|
||||
pair t = (-u.y, u.x);
|
||||
real c = SpokeOffset(i);
|
||||
real half = sqrt(radius * radius - c * c);
|
||||
return new pair[] { c * u - half * t, c * u + half * t };
|
||||
}
|
||||
|
||||
pen Shade(path3 face)
|
||||
{
|
||||
triple n = unit(cross(point(face, 1) - point(face, 0), point(face, 2) - point(face, 0)));
|
||||
real k = 0.74 + 0.26 * abs(dot(n, lightDirection));
|
||||
return rgb(k * 0.843, k * 0.890, k * 0.957);
|
||||
}
|
||||
|
||||
triple Lift(pair p)
|
||||
{
|
||||
return sliceHeight * (p.x, 1, p.y);
|
||||
}
|
||||
|
||||
frame[] panels;
|
||||
string[] titles;
|
||||
|
||||
// 3D view: the fan, the slice above it and the cone of the region
|
||||
{
|
||||
currentprojection = orthographic((3.4, 3.0, 2.6), up = Y);
|
||||
picture pic;
|
||||
size(pic, 250px, 250px);
|
||||
triple hub = (0, 0, 0);
|
||||
|
||||
for (int i = 0; i < spokeCount; ++i)
|
||||
{
|
||||
path3 t = hub -- spokes[i] -- spokes[(i + 1) % spokeCount] -- cycle;
|
||||
draw(pic, surface(t), Shade(t), nolight);
|
||||
draw(pic, t, meshPen);
|
||||
}
|
||||
|
||||
triple offset[] = {(0.1, 0, 0.1), (0.3, 0, 0.3), (0, 0, 0), (-0.1, 0, 0), (0, 0, -0.3), (0, 0, 0)};
|
||||
for (int i = 0; i < spokeCount; ++i)
|
||||
{
|
||||
draw(pic, hub -- spokes[i], SpokePen(i) + 1.4px);
|
||||
label(pic, "$e_" + string(i) + "$", spokes[i] + offset[i], unit(Gnomonic((spokes[i].x, 1, 4 * spokes[i].z))), SpokePen(i));
|
||||
}
|
||||
|
||||
// The boundary plane of one ridge spoke, it holds the hub and its line on the slice
|
||||
pair[] line0 = SpokeLine(0, Tan(40));
|
||||
path3 wall = hub -- Lift(line0[0]) -- Lift(line0[1]) -- cycle;
|
||||
draw(pic, surface(wall), ridgeColor + opacity(0.18), nolight);
|
||||
draw(pic, hub -- Lift(line0[0]), ridgeColor + 0.5px + linetype(new real[] {4, 3}));
|
||||
draw(pic, hub -- Lift(line0[1]), ridgeColor + 0.5px + linetype(new real[] {4, 3}));
|
||||
|
||||
path3 slice = shift((0, sliceHeight, 0)) * rotate(90, X) * scale3(sliceRadius) * unitcircle3;
|
||||
draw(pic, surface(slice), sliceFill, nolight);
|
||||
draw(pic, slice, gray(0.6) + 0.5px);
|
||||
|
||||
for (int i = 0; i < spokeCount; ++i)
|
||||
{
|
||||
pair[] ends = SpokeLine(i, Tan(40));
|
||||
draw(pic, Lift(ends[0]) -- Lift(ends[1]), SpokePen(i) + 0.8px);
|
||||
}
|
||||
|
||||
path3 top = Lift(region[0]);
|
||||
for (int k = 1; k < region.length; ++k)
|
||||
top = top -- Lift(region[k]);
|
||||
top = top -- cycle;
|
||||
draw(pic, surface(top), regionFill, nolight);
|
||||
draw(pic, top, regionPen);
|
||||
|
||||
for (pair p : region)
|
||||
draw(pic, hub -- Lift(p), regionPen);
|
||||
|
||||
dot(pic, hub, ink + 3px);
|
||||
label(pic, "slice", Lift((0, -Tan(40))) + (0, 0.1, 0), N, gray(0.35));
|
||||
|
||||
panels.push(pic.fit());
|
||||
titles.push("Saddle Vertex Voronoi");
|
||||
}
|
||||
|
||||
// Top view of the slice, in units of tan(tilt)
|
||||
{
|
||||
picture pic;
|
||||
unitsize(pic, 190px);
|
||||
real radius = Tan(40);
|
||||
|
||||
// Looking down on the slice: x to the right, z down the page
|
||||
pair View(pair p)
|
||||
{
|
||||
return (p.x, -p.y);
|
||||
}
|
||||
|
||||
path hull = View(hullPoints[0]);
|
||||
for (int i = 1; i < spokeCount; ++i)
|
||||
hull = hull -- View(hullPoints[i]);
|
||||
hull = hull -- cycle;
|
||||
fill(pic, hull, gray(0.92));
|
||||
|
||||
// Excluded side of each line, a band inside the disk
|
||||
real band = 0.035;
|
||||
for (int i = 0; i < spokeCount; ++i)
|
||||
{
|
||||
pair u = SpokeDirection(i);
|
||||
pair[] ends = SpokeLine(i, radius - band);
|
||||
path strip = View(ends[0]) -- View(ends[1]) -- View(ends[1] + band * u) -- View(ends[0] + band * u) -- cycle;
|
||||
fill(pic, strip, SpokePen(i) + opacity(0.25));
|
||||
}
|
||||
|
||||
for (int i = 0; i < spokeCount; ++i)
|
||||
{
|
||||
pair[] ends = SpokeLine(i, radius);
|
||||
draw(pic, View(ends[0]) -- View(ends[1]), SpokePen(i) + 1.0px);
|
||||
pair u = SpokeDirection(i);
|
||||
label(pic, "$e_" + string(i) + "$", View((SpokeOffset(i) + (IsRidge(i) ? 0.11 : 0.075)) * u), SpokePen(i));
|
||||
}
|
||||
|
||||
draw(pic, hull, hullPen);
|
||||
|
||||
path area = View(region[0]);
|
||||
for (int k = 1; k < region.length; ++k)
|
||||
area = area -- View(region[k]);
|
||||
area = area -- cycle;
|
||||
filldraw(pic, area, regionFill, regionPen);
|
||||
|
||||
// Tilt from up, drawn over the fills so they read through the region
|
||||
for (real tilt : new real[] {10, 20, 30, 40})
|
||||
{
|
||||
draw(pic, scale(Tan(tilt)) * unitcircle, tilt == 40 ? gray(0.6) + 0.5px : guidePen);
|
||||
label(pic, string(tilt) + "$^\circ$", Tan(tilt) * dir(90), N, gray(0.45) + fontsize(7pt));
|
||||
}
|
||||
|
||||
for (pair n : faceNormals)
|
||||
dot(pic, View(n), ink + 3.5px);
|
||||
label(pic, "face normals", View(faceNormals[1]), NE, ink + fontsize(8pt));
|
||||
|
||||
dot(pic, (0, 0), ink + 2.5px);
|
||||
label(pic, "up", (0, 0), SW, ink + fontsize(8pt));
|
||||
|
||||
frame f = pic.fit();
|
||||
panels.push(f);
|
||||
titles.push("Top View");
|
||||
}
|
||||
|
||||
real gap = 36px;
|
||||
real x = 0;
|
||||
real bottom = 0;
|
||||
for (int i = 0; i < panels.length; ++i)
|
||||
{
|
||||
frame f = panels[i];
|
||||
pair lo = min(f);
|
||||
pair hi = max(f);
|
||||
add(shift(x - lo.x, -lo.y) * f);
|
||||
label(titles[i], (x + 0.5 * (hi.x - lo.x), -8px), S, ink);
|
||||
x += hi.x - lo.x + gap;
|
||||
}
|
||||
|
||||
// Legend
|
||||
pair legend = (0, -40px);
|
||||
draw((legend.x, legend.y) -- (legend.x + 18px, legend.y), ridgeColor + 1.4px);
|
||||
label("ridge spoke, 8$^\circ$ drop", (legend.x + 22px, legend.y), E, ink + fontsize(8pt));
|
||||
draw((legend.x + 150px, legend.y) -- (legend.x + 168px, legend.y), gullyColor + 1.4px);
|
||||
label("gully spoke, 32$^\circ$ drop", (legend.x + 172px, legend.y), E, ink + fontsize(8pt));
|
||||
filldraw(shift(legend.x + 300px, legend.y - 5px) * scale(10px) * unitsquare, regionFill, regionPen);
|
||||
label("vertex region", (legend.x + 314px, legend.y), E, ink + fontsize(8pt));
|
||||
draw((legend.x + 410px, legend.y) -- (legend.x + 428px, legend.y), hullPen);
|
||||
label("cone of face normals", (legend.x + 432px, legend.y), E, ink + fontsize(8pt));
|
||||
442
docs/images/saddle_region.svg
Normal file
442
docs/images/saddle_region.svg
Normal file
|
|
@ -0,0 +1,442 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<!-- This file was generated by dvisvgm 3.6 -->
|
||||
<svg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='421.026268pt' height='282.69703pt' viewBox='56.934449 301.85182 421.026268 282.69703'>
|
||||
<defs>
|
||||
<path id='g0-14' d='M3.257783-1.494396C3.257783-2.253549 2.64807-2.851308 1.906849-2.851308S.555915-2.247572 .555915-1.494396C.555915-.735243 1.165629-.137484 1.906849-.137484S3.257783-.74122 3.257783-1.494396ZM1.906849-.448319C1.333001-.448319 .86675-.908593 .86675-1.494396S1.333001-2.540473 1.906849-2.540473S2.946949-2.080199 2.946949-1.494396S2.480697-.448319 1.906849-.448319Z'/>
|
||||
<path id='g1-101' d='M2.139975-2.773599C2.462765-2.773599 3.275716-2.797509 3.849564-3.012702C4.758157-3.359402 4.841843-4.052802 4.841843-4.267995C4.841843-4.794022 4.387547-5.272229 3.598506-5.272229C2.343213-5.272229 .537983-4.136488 .537983-2.008468C.537983-.753176 1.255293 .119552 2.343213 .119552C3.969116 .119552 4.99726-1.147696 4.99726-1.303113C4.99726-1.374844 4.925529-1.43462 4.877709-1.43462C4.841843-1.43462 4.829888-1.422665 4.722291-1.315068C3.957161-.298879 2.82142-.119552 2.367123-.119552C1.685679-.119552 1.327024-.657534 1.327024-1.542217C1.327024-1.709589 1.327024-2.008468 1.506351-2.773599H2.139975ZM1.566127-3.012702C2.080199-4.853798 3.21594-5.033126 3.598506-5.033126C4.124533-5.033126 4.483188-4.722291 4.483188-4.267995C4.483188-3.012702 2.570361-3.012702 2.068244-3.012702H1.566127Z'/>
|
||||
<path id='g2-44' d='M1.490411-.119552C1.490411 .119552 1.490411 .773101 .884682 1.338979C.860772 1.362889 .836862 1.378829 .836862 1.42665C.836862 1.498381 .908593 1.546202 .948443 1.546202C1.052055 1.546202 1.713574 .924533 1.713574-.03188C1.713574-.470237 1.554172-.884682 1.171606-.884682C.908593-.884682 .73325-.67746 .73325-.446326C.73325-.207223 .900623 0 1.179577 0C1.354919 0 1.466501-.095641 1.490411-.119552Z'/>
|
||||
<path id='g2-48' d='M3.897385-2.542466C3.897385-3.395268 3.809714-3.913325 3.5467-4.423412C3.196015-5.124782 2.550436-5.300125 2.11208-5.300125C1.107846-5.300125 .74122-4.550934 .629639-4.327771C.342715-3.745953 .326775-2.956912 .326775-2.542466C.326775-2.016438 .350685-1.211457 .73325-.573848C1.099875 .01594 1.689664 .167372 2.11208 .167372C2.494645 .167372 3.180075 .047821 3.57858-.74122C3.873474-1.315068 3.897385-2.024408 3.897385-2.542466ZM2.11208-.055791C1.841096-.055791 1.291158-.183313 1.123786-1.020174C1.036115-1.474471 1.036115-2.223661 1.036115-2.638107C1.036115-3.188045 1.036115-3.745953 1.123786-4.184309C1.291158-4.99726 1.912827-5.076961 2.11208-5.076961C2.383064-5.076961 2.933001-4.941469 3.092403-4.216189C3.188045-3.777833 3.188045-3.180075 3.188045-2.638107C3.188045-2.16787 3.188045-1.45056 3.092403-1.004234C2.925031-.167372 2.375093-.055791 2.11208-.055791Z'/>
|
||||
<path id='g2-49' d='M2.502615-5.076961C2.502615-5.292154 2.486675-5.300125 2.271482-5.300125C1.944707-4.98132 1.522291-4.790037 .765131-4.790037V-4.527024C.980324-4.527024 1.41071-4.527024 1.872976-4.742217V-.653549C1.872976-.358655 1.849066-.263014 1.091905-.263014H.812951V0C1.139726-.02391 1.825156-.02391 2.183811-.02391S3.235866-.02391 3.56264 0V-.263014H3.283686C2.526526-.263014 2.502615-.358655 2.502615-.653549V-5.076961Z'/>
|
||||
<path id='g2-50' d='M2.247572-1.625903C2.375093-1.745455 2.709838-2.008468 2.83736-2.12005C3.331507-2.574346 3.801743-3.012702 3.801743-3.737983C3.801743-4.686426 3.004732-5.300125 2.008468-5.300125C1.052055-5.300125 .422416-4.574844 .422416-3.865504C.422416-3.474969 .73325-3.419178 .844832-3.419178C1.012204-3.419178 1.259278-3.53873 1.259278-3.841594C1.259278-4.25604 .860772-4.25604 .765131-4.25604C.996264-4.837858 1.530262-5.037111 1.920797-5.037111C2.662017-5.037111 3.044583-4.407472 3.044583-3.737983C3.044583-2.909091 2.462765-2.303362 1.522291-1.338979L.518057-.302864C.422416-.215193 .422416-.199253 .422416 0H3.57061L3.801743-1.42665H3.55467C3.53076-1.267248 3.466999-.868742 3.371357-.71731C3.323537-.653549 2.717808-.653549 2.590286-.653549H1.171606L2.247572-1.625903Z'/>
|
||||
<path id='g2-51' d='M2.016438-2.662017C2.646077-2.662017 3.044583-2.199751 3.044583-1.362889C3.044583-.366625 2.478705-.071731 2.056289-.071731C1.617933-.071731 1.020174-.231133 .74122-.653549C1.028144-.653549 1.227397-.836862 1.227397-1.099875C1.227397-1.354919 1.044085-1.538232 .789041-1.538232C.573848-1.538232 .350685-1.40274 .350685-1.083935C.350685-.326775 1.163636 .167372 2.072229 .167372C3.132254 .167372 3.873474-.565878 3.873474-1.362889C3.873474-2.024408 3.347447-2.630137 2.534496-2.805479C3.164134-3.028643 3.634371-3.57061 3.634371-4.208219S2.917061-5.300125 2.088169-5.300125C1.235367-5.300125 .589788-4.837858 .589788-4.23213C.589788-3.937235 .789041-3.809714 .996264-3.809714C1.243337-3.809714 1.40274-3.985056 1.40274-4.216189C1.40274-4.511083 1.147696-4.622665 .972354-4.630635C1.307098-5.068991 1.920797-5.092902 2.064259-5.092902C2.271482-5.092902 2.87721-5.029141 2.87721-4.208219C2.87721-3.650311 2.646077-3.315567 2.534496-3.188045C2.295392-2.940971 2.11208-2.925031 1.625903-2.893151C1.474471-2.885181 1.41071-2.87721 1.41071-2.773599C1.41071-2.662017 1.482441-2.662017 1.617933-2.662017H2.016438Z'/>
|
||||
<path id='g2-52' d='M3.140224-5.156663C3.140224-5.316065 3.140224-5.379826 2.972852-5.379826C2.86924-5.379826 2.86127-5.371856 2.781569-5.260274L.239103-1.570112V-1.307098H2.486675V-.645579C2.486675-.350685 2.462765-.263014 1.849066-.263014H1.665753V0C2.343213-.02391 2.359153-.02391 2.81345-.02391S3.283686-.02391 3.961146 0V-.263014H3.777833C3.164134-.263014 3.140224-.350685 3.140224-.645579V-1.307098H3.985056V-1.570112H3.140224V-5.156663ZM2.542466-4.511083V-1.570112H.518057L2.542466-4.511083Z'/>
|
||||
<path id='g2-53' d='M1.115816-4.479203C1.219427-4.447323 1.538232-4.367621 1.872976-4.367621C2.86924-4.367621 3.474969-5.068991 3.474969-5.188543C3.474969-5.276214 3.419178-5.300125 3.379328-5.300125C3.363387-5.300125 3.347447-5.300125 3.275716-5.260274C2.964882-5.140722 2.598257-5.045081 2.16787-5.045081C1.697634-5.045081 1.307098-5.164633 1.060025-5.260274C.980324-5.300125 .964384-5.300125 .956413-5.300125C.852802-5.300125 .852802-5.212453 .852802-5.068991V-2.733748C.852802-2.590286 .852802-2.494645 .980324-2.494645C1.044085-2.494645 1.067995-2.526526 1.107846-2.590286C1.203487-2.709838 1.506351-3.116314 2.183811-3.116314C2.630137-3.116314 2.84533-2.749689 2.917061-2.598257C3.052553-2.311333 3.068493-1.944707 3.068493-1.633873C3.068493-1.338979 3.060523-.908593 2.83736-.557908C2.685928-.318804 2.367123-.071731 1.944707-.071731C1.42665-.071731 .916563-.398506 .73325-.916563C.757161-.908593 .804981-.908593 .812951-.908593C1.036115-.908593 1.211457-1.052055 1.211457-1.299128C1.211457-1.594022 .980324-1.697634 .820922-1.697634C.67746-1.697634 .422416-1.617933 .422416-1.275218C.422416-.557908 1.044085 .167372 1.960648 .167372C2.956912 .167372 3.801743-.605729 3.801743-1.594022C3.801743-2.518555 3.132254-3.339477 2.191781-3.339477C1.793275-3.339477 1.41868-3.211955 1.115816-2.940971V-4.479203Z'/>
|
||||
<path id='g2-56' d='M2.646077-2.87721C3.092403-3.092403 3.634371-3.490909 3.634371-4.112578C3.634371-4.869738 2.86127-5.300125 2.12005-5.300125C1.275218-5.300125 .589788-4.718306 .589788-3.969116C.589788-3.674222 .6934-3.403238 .892653-3.172105C1.028144-3.004732 1.060025-2.988792 1.554172-2.677958C.565878-2.239601 .350685-1.657783 .350685-1.211457C.350685-.334745 1.235367 .167372 2.10411 .167372C3.084433 .167372 3.873474-.494147 3.873474-1.338979C3.873474-1.841096 3.602491-2.175841 3.474969-2.311333C3.339477-2.438854 3.331507-2.446824 2.646077-2.87721ZM1.41071-3.626401C1.179577-3.761893 .988294-3.993026 .988294-4.27198C.988294-4.774097 1.538232-5.092902 2.10411-5.092902C2.725778-5.092902 3.235866-4.670486 3.235866-4.112578C3.235866-3.650311 2.87721-3.259776 2.406974-3.028643L1.41071-3.626401ZM1.801245-2.534496C1.833126-2.518555 2.741719-1.960648 2.87721-1.872976C3.004732-1.801245 3.419178-1.546202 3.419178-1.067995C3.419178-.454296 2.773599-.071731 2.12005-.071731C1.41071-.071731 .804981-.557908 .804981-1.211457C.804981-1.809215 1.251308-2.279452 1.801245-2.534496Z'/>
|
||||
<path id='g2-97' d='M3.347447-2.375093C3.347447-3.156164 2.590286-3.55467 1.865006-3.55467C1.203487-3.55467 .613699-3.299626 .613699-2.773599C.613699-2.534496 .781071-2.391034 .988294-2.391034C1.211457-2.391034 1.362889-2.550436 1.362889-2.765629C1.362889-2.956912 1.243337-3.092403 1.067995-3.132254C1.362889-3.331507 1.793275-3.331507 1.849066-3.331507C2.295392-3.331507 2.741719-3.020672 2.741719-2.367123V-2.12005C2.279452-2.096139 1.745455-2.072229 1.187547-1.841096C.486177-1.538232 .350685-1.075965 .350685-.812951C.350685-.127522 1.155666 .079701 1.705604 .079701C2.287422 .079701 2.646077-.247073 2.82142-.565878C2.86127-.263014 3.068493 .039851 3.419178 .039851C3.498879 .039851 4.176339 .00797 4.176339-.71731V-1.155666H3.929265V-.71731C3.929265-.390535 3.809714-.263014 3.642341-.263014C3.347447-.263014 3.347447-.629639 3.347447-.71731V-2.375093ZM2.741719-1.123786C2.741719-.350685 2.088169-.143462 1.769365-.143462C1.354919-.143462 1.004234-.422416 1.004234-.804981C1.004234-1.331009 1.498381-1.872976 2.741719-1.912827V-1.123786Z'/>
|
||||
<path id='g2-99' d='M2.933001-3.164134C2.709838-3.092403 2.677958-2.909091 2.677958-2.81345C2.677958-2.598257 2.82939-2.438854 3.052553-2.438854C3.259776-2.438854 3.427148-2.582316 3.427148-2.82142C3.427148-3.315567 2.885181-3.55467 2.13599-3.55467C1.028144-3.55467 .278954-2.669988 .278954-1.721544C.278954-.70934 1.107846 .079701 2.11208 .079701C3.235866 .079701 3.514819-.860772 3.514819-.956413S3.411208-1.052055 3.387298-1.052055C3.331507-1.052055 3.291656-1.044085 3.267746-.964384C3.211955-.797011 2.988792-.167372 2.191781-.167372C1.697634-.167372 .988294-.549938 .988294-1.729514C.988294-2.87721 1.578082-3.307597 2.1599-3.307597C2.231631-3.307597 2.654047-3.307597 2.933001-3.164134Z'/>
|
||||
<path id='g2-100' d='M2.622167-5.443587V-5.180573C3.164134-5.180573 3.227895-5.124782 3.227895-4.734247V-3.052553C2.948941-3.355417 2.574346-3.514819 2.1599-3.514819C1.163636-3.514819 .278954-2.741719 .278954-1.713574C.278954-.73325 1.075965 .079701 2.080199 .079701C2.550436 .079701 2.940971-.143462 3.203985-.422416V.079701L4.415442 0V-.263014C3.873474-.263014 3.809714-.318804 3.809714-.70934V-5.531258L2.622167-5.443587ZM3.203985-.988294C3.203985-.844832 3.203985-.812951 3.084433-.653549C2.86127-.334745 2.494645-.143462 2.12005-.143462C1.753425-.143462 1.43462-.334745 1.243337-.629639C1.028144-.940473 .988294-1.331009 .988294-1.705604C.988294-2.16787 1.060025-2.494645 1.243337-2.773599C1.43462-3.068493 1.793275-3.291656 2.199751-3.291656C2.582316-3.291656 2.964882-3.100374 3.203985-2.685928V-.988294Z'/>
|
||||
<path id='g2-101' d='M3.291656-1.817186C3.466999-1.817186 3.514819-1.817186 3.514819-2.000498C3.514819-2.709838 3.124284-3.55467 2.000498-3.55467C1.012204-3.55467 .239103-2.733748 .239103-1.745455C.239103-.71731 1.099875 .079701 2.10411 .079701C3.116314 .079701 3.514819-.773101 3.514819-.956413C3.514819-.988294 3.490909-1.067995 3.387298-1.067995C3.299626-1.067995 3.283686-1.012204 3.267746-.964384C2.980822-.191283 2.295392-.167372 2.15193-.167372C1.793275-.167372 1.42665-.334745 1.187547-.70137S.948443-1.578082 .948443-1.817186H3.291656ZM.956413-2.024408C1.028144-3.140224 1.705604-3.331507 2.000498-3.331507C2.933001-3.331507 2.964882-2.207721 2.972852-2.024408H.956413Z'/>
|
||||
<path id='g2-102' d='M1.522291-3.172105H2.478705V-3.435118H1.498381V-4.335741C1.498381-5.029141 1.888917-5.387796 2.239601-5.387796C2.367123-5.387796 2.438854-5.355915 2.470735-5.347945C2.327273-5.276214 2.287422-5.140722 2.287422-5.037111C2.287422-4.829888 2.438854-4.678456 2.646077-4.678456C2.86127-4.678456 3.004732-4.829888 3.004732-5.037111C3.004732-5.379826 2.669988-5.610959 2.247572-5.610959C1.649813-5.610959 .940473-5.180573 .940473-4.327771V-3.435118H.286924V-3.172105H.940473V-.621669C.940473-.263014 .844832-.263014 .334745-.263014V0C.645579-.02391 1.083935-.02391 1.275218-.02391C1.745455-.02391 1.761395-.02391 2.279452 0V-.263014H2.12005C1.538232-.263014 1.522291-.350685 1.522291-.637609V-3.172105Z'/>
|
||||
<path id='g2-103' d='M1.378829-.549938C1.131756-.573848 .932503-.789041 .932503-1.075965C.932503-1.267248 .980324-1.338979 1.036115-1.41071C1.370859-1.211457 1.681694-1.171606 1.872976-1.171606C2.662017-1.171606 3.243836-1.721544 3.243836-2.343213C3.243836-2.646077 3.108344-2.901121 2.917061-3.108344C3.028643-3.203985 3.291656-3.371357 3.682192-3.379328C3.650311-3.355417 3.610461-3.315567 3.610461-3.188045C3.610461-3.044583 3.714072-2.940971 3.857534-2.940971C3.969116-2.940971 4.104608-3.012702 4.104608-3.196015C4.104608-3.331507 4.000996-3.602491 3.650311-3.602491C3.514819-3.602491 3.132254-3.57061 2.765629-3.235866C2.566376-3.379328 2.255542-3.514819 1.880946-3.514819C1.091905-3.514819 .510087-2.964882 .510087-2.343213C.510087-1.968618 .71731-1.689664 .884682-1.530262C.70934-1.331009 .645579-1.075965 .645579-.884682C.645579-.557908 .804981-.310834 .980324-.175342C.565878-.063761 .239103 .247073 .239103 .613699C.239103 1.187547 1.060025 1.633873 2.11208 1.633873C3.108344 1.633873 3.985056 1.227397 3.985056 .597758C3.985056 .167372 3.730012-.167372 3.466999-.302864C2.996762-.549938 2.606227-.549938 1.825156-.549938H1.378829ZM1.880946-1.40274C1.139726-1.40274 1.139726-2.16787 1.139726-2.343213C1.139726-2.638107 1.179577-2.84533 1.299128-3.004732C1.43462-3.188045 1.657783-3.283686 1.872976-3.283686C2.614197-3.283686 2.614197-2.518555 2.614197-2.343213C2.614197-2.048319 2.574346-1.841096 2.454795-1.681694C2.279452-1.458531 2.024408-1.40274 1.880946-1.40274ZM2.255542-.03188C2.470735-.03188 3.514819-.03188 3.514819 .605729C3.514819 1.036115 2.901121 1.40274 2.11208 1.40274C1.315068 1.40274 .70934 1.036115 .70934 .605729C.70934 .438356 .836862-.03188 1.490411-.03188H2.255542Z'/>
|
||||
<path id='g2-105' d='M1.554172-4.909589C1.554172-5.140722 1.370859-5.355915 1.107846-5.355915C.876712-5.355915 .669489-5.172603 .669489-4.917559C.669489-4.638605 .900623-4.471233 1.107846-4.471233C1.3868-4.471233 1.554172-4.702366 1.554172-4.909589ZM.358655-3.427148V-3.164134C.868742-3.164134 .940473-3.116314 .940473-2.725778V-.621669C.940473-.263014 .844832-.263014 .334745-.263014V0C.645579-.02391 1.091905-.02391 1.211457-.02391C1.315068-.02391 1.793275-.02391 2.072229 0V-.263014C1.554172-.263014 1.522291-.302864 1.522291-.613699V-3.514819L.358655-3.427148Z'/>
|
||||
<path id='g2-107' d='M2.399004-2.16787L3.076463-2.709838C3.602491-3.124284 3.937235-3.164134 4.136488-3.172105V-3.435118C3.945205-3.411208 3.833624-3.411208 3.506849-3.411208C3.116314-3.411208 3.004732-3.419178 2.654047-3.435118V-3.172105C2.805479-3.164134 2.83736-3.060523 2.83736-3.012702C2.83736-2.84533 2.677958-2.709838 2.614197-2.662017L1.466501-1.737484V-5.531258L.278954-5.443587V-5.180573C.820922-5.180573 .884682-5.124782 .884682-4.734247V-.621669C.884682-.263014 .789041-.263014 .278954-.263014V0C.589788-.02391 1.020174-.02391 1.155666-.02391C1.315068-.02391 1.729514-.02391 2.040349 0V-.263014C1.530262-.263014 1.43462-.263014 1.43462-.621669V-1.39477L1.976588-1.825156C2.000498-1.825156 2.207721-1.546202 2.335243-1.39477C2.454795-1.227397 2.582316-1.067995 2.709838-.908593C2.82142-.749191 2.988792-.541968 2.988792-.422416C2.988792-.286924 2.83736-.263014 2.741719-.263014V0C3.084433-.02391 3.443088-.02391 3.57858-.02391C3.881445-.02391 4.040847-.02391 4.319801 0V-.263014C3.985056-.263014 3.841594-.294894 3.55467-.669489L2.399004-2.16787Z'/>
|
||||
<path id='g2-108' d='M1.522291-5.531258L.334745-5.443587V-5.180573C.876712-5.180573 .940473-5.124782 .940473-4.734247V-.621669C.940473-.263014 .844832-.263014 .334745-.263014V0C.645579-.02391 1.091905-.02391 1.227397-.02391C1.3868-.02391 1.817186-.02391 2.12802 0V-.263014C1.617933-.263014 1.522291-.263014 1.522291-.621669V-5.531258Z'/>
|
||||
<path id='g2-109' d='M6.224658-2.414944C6.224658-3.060523 5.945704-3.514819 5.076961-3.514819C4.343711-3.514819 3.977086-3.012702 3.849564-2.781569C3.706102-3.355417 3.251806-3.514819 2.733748-3.514819C1.960648-3.514819 1.594022-2.964882 1.490411-2.749689H1.482441V-3.514819L.326775-3.427148V-3.164134C.868742-3.164134 .932503-3.108344 .932503-2.717808V-.621669C.932503-.263014 .836862-.263014 .326775-.263014V0C.669489-.02391 1.020174-.02391 1.235367-.02391C1.466501-.02391 1.801245-.02391 2.14396 0V-.263014C1.633873-.263014 1.538232-.263014 1.538232-.621669V-2.064259C1.538232-2.901121 2.16787-3.291656 2.669988-3.291656C3.188045-3.291656 3.275716-2.885181 3.275716-2.446824V-.621669C3.275716-.263014 3.180075-.263014 2.669988-.263014V0C3.012702-.02391 3.363387-.02391 3.57858-.02391C3.809714-.02391 4.144458-.02391 4.487173 0V-.263014C3.977086-.263014 3.881445-.263014 3.881445-.621669V-2.064259C3.881445-2.901121 4.511083-3.291656 5.0132-3.291656C5.531258-3.291656 5.618929-2.885181 5.618929-2.446824V-.621669C5.618929-.263014 5.523288-.263014 5.0132-.263014V0C5.355915-.02391 5.7066-.02391 5.921793-.02391C6.152927-.02391 6.487671-.02391 6.830386 0V-.263014C6.320299-.263014 6.224658-.263014 6.224658-.621669V-2.414944Z'/>
|
||||
<path id='g2-110' d='M3.873474-2.414944C3.873474-3.084433 3.57061-3.514819 2.733748-3.514819C1.944707-3.514819 1.586052-2.940971 1.490411-2.749689H1.482441V-3.514819L.326775-3.427148V-3.164134C.868742-3.164134 .932503-3.108344 .932503-2.717808V-.621669C.932503-.263014 .836862-.263014 .326775-.263014V0C.669489-.02391 1.020174-.02391 1.235367-.02391C1.466501-.02391 1.801245-.02391 2.14396 0V-.263014C1.633873-.263014 1.538232-.263014 1.538232-.621669V-2.064259C1.538232-2.901121 2.175841-3.291656 2.662017-3.291656S3.267746-2.948941 3.267746-2.446824V-.621669C3.267746-.263014 3.172105-.263014 2.662017-.263014V0C3.004732-.02391 3.355417-.02391 3.57061-.02391C3.801743-.02391 4.136488-.02391 4.479203 0V-.263014C3.969116-.263014 3.873474-.263014 3.873474-.621669V-2.414944Z'/>
|
||||
<path id='g2-111' d='M3.985056-1.697634C3.985056-2.693898 3.164134-3.55467 2.11208-3.55467S.239103-2.693898 .239103-1.697634S1.091905 .079701 2.11208 .079701C3.140224 .079701 3.985056-.70137 3.985056-1.697634ZM2.11208-.167372C1.681694-.167372 1.346949-.374595 1.171606-.653549C.972354-.980324 .948443-1.370859 .948443-1.769365C.948443-2.072229 .948443-2.550436 1.195517-2.893151C1.40274-3.172105 1.737484-3.331507 2.11208-3.331507C2.526526-3.331507 2.86924-3.132254 3.052553-2.8533C3.267746-2.518555 3.275716-2.088169 3.275716-1.769365C3.275716-1.40274 3.259776-.964384 3.036613-.629639C2.82142-.310834 2.462765-.167372 2.11208-.167372Z'/>
|
||||
<path id='g2-112' d='M2.096139 1.283188C1.586052 1.283188 1.490411 1.283188 1.490411 .924533V-.390535C1.865006 .01594 2.271482 .079701 2.526526 .079701C3.53873 .079701 4.415442-.70137 4.415442-1.721544C4.415442-2.717808 3.610461-3.514819 2.646077-3.514819C2.335243-3.514819 1.872976-3.435118 1.466501-3.020672V-3.514819L.278954-3.427148V-3.164134C.844832-3.164134 .884682-3.116314 .884682-2.781569V.924533C.884682 1.283188 .789041 1.283188 .278954 1.283188V1.546202C.621669 1.522291 .972354 1.522291 1.187547 1.522291C1.41868 1.522291 1.753425 1.522291 2.096139 1.546202V1.283188ZM1.490411-2.654047C1.673724-2.972852 2.072229-3.267746 2.574346-3.267746C3.188045-3.267746 3.706102-2.590286 3.706102-1.721544C3.706102-.804981 3.132254-.143462 2.486675-.143462C2.207721-.143462 1.841096-.263014 1.586052-.661519C1.490411-.797011 1.490411-.804981 1.490411-.956413V-2.654047Z'/>
|
||||
<path id='g2-114' d='M1.466501-1.817186C1.466501-2.414944 1.713574-3.275716 2.478705-3.291656C2.430884-3.259776 2.351183-3.196015 2.351183-3.012702C2.351183-2.765629 2.542466-2.654047 2.701868-2.654047C2.893151-2.654047 3.060523-2.781569 3.060523-3.012702C3.060523-3.291656 2.805479-3.514819 2.454795-3.514819C1.936737-3.514819 1.586052-3.124284 1.41868-2.677958H1.41071V-3.514819L.278954-3.427148V-3.164134C.820922-3.164134 .884682-3.108344 .884682-2.717808V-.621669C.884682-.263014 .789041-.263014 .278954-.263014V0C.589788-.02391 1.028144-.02391 1.219427-.02391C1.689664-.02391 1.705604-.02391 2.223661 0V-.263014H2.064259C1.482441-.263014 1.466501-.350685 1.466501-.637609V-1.817186Z'/>
|
||||
<path id='g2-115' d='M2.83736-3.347447C2.83736-3.474969 2.83736-3.55467 2.733748-3.55467C2.693898-3.55467 2.669988-3.55467 2.542466-3.427148C2.526526-3.419178 2.454795-3.347447 2.430884-3.347447C2.422914-3.347447 2.406974-3.347447 2.359153-3.379328C2.231631-3.466999 2.000498-3.55467 1.641843-3.55467C.526027-3.55467 .278954-2.948941 .278954-2.566376C.278954-2.16787 .573848-1.936737 .597758-1.912827C.916563-1.673724 1.099875-1.641843 1.633873-1.546202C2.008468-1.474471 2.622167-1.362889 2.622167-.820922C2.622167-.510087 2.414944-.143462 1.681694-.143462C.876712-.143462 .645579-.765131 .541968-1.187547C.510087-1.291158 .502117-1.331009 .406476-1.331009C.278954-1.331009 .278954-1.267248 .278954-1.115816V-.127522C.278954 0 .278954 .079701 .382565 .079701C.430386 .079701 .438356 .071731 .581818-.079701C.621669-.119552 .70934-.223163 .749191-.263014C1.107846 .063761 1.482441 .079701 1.689664 .079701C2.701868 .079701 3.052553-.502117 3.052553-1.028144C3.052553-1.41071 2.82142-1.968618 1.872976-2.14396C1.809215-2.1599 1.362889-2.239601 1.331009-2.239601C1.083935-2.295392 .70934-2.462765 .70934-2.781569C.70934-3.020672 .884682-3.355417 1.641843-3.355417C2.534496-3.355417 2.574346-2.701868 2.590286-2.478705C2.598257-2.414944 2.654047-2.391034 2.709838-2.391034C2.83736-2.391034 2.83736-2.446824 2.83736-2.598257V-3.347447Z'/>
|
||||
<path id='g2-116' d='M1.482441-3.172105H2.669988V-3.435118H1.482441V-4.901619H1.235367C1.227397-4.176339 .900623-3.419178 .159402-3.395268V-3.172105H.876712V-.996264C.876712-.063761 1.594022 .079701 1.960648 .079701C2.494645 .079701 2.81345-.398506 2.81345-.996264V-1.44259H2.566376V-1.012204C2.566376-.462267 2.319303-.167372 2.016438-.167372C1.482441-.167372 1.482441-.852802 1.482441-.980324V-3.172105Z'/>
|
||||
<path id='g2-117' d='M2.662017-3.427148V-3.164134C3.203985-3.164134 3.267746-3.108344 3.267746-2.717808V-1.331009C3.267746-.645579 2.8533-.143462 2.255542-.143462C1.570112-.143462 1.538232-.486177 1.538232-.884682V-3.514819L.326775-3.427148V-3.164134C.932503-3.164134 .932503-3.140224 .932503-2.430884V-1.235367C.932503-.661519 .932503 .079701 2.207721 .079701C2.956912 .079701 3.243836-.494147 3.283686-.565878H3.291656V.079701L4.479203 0V-.263014C3.937235-.263014 3.873474-.318804 3.873474-.70934V-3.514819L2.662017-3.427148Z'/>
|
||||
<path id='g2-118' d='M3.53076-2.614197C3.722042-3.060523 3.993026-3.164134 4.28792-3.172105V-3.435118C4.008966-3.411208 3.993026-3.411208 3.666252-3.411208C3.594521-3.411208 3.219925-3.411208 2.972852-3.435118V-3.172105C3.251806-3.156164 3.323537-2.980822 3.323537-2.84533C3.323537-2.765629 3.307597-2.725778 3.275716-2.654047L2.414944-.645579L1.474471-2.805479C1.42665-2.909091 1.42665-2.956912 1.42665-2.972852C1.42665-3.172105 1.713574-3.172105 1.849066-3.172105V-3.435118C1.506351-3.411208 1.131756-3.411208 .980324-3.411208C.812951-3.411208 .430386-3.411208 .175342-3.435118V-3.172105C.661519-3.172105 .70137-3.124284 .820922-2.8533L2.016438-.095641C2.072229 .02391 2.12005 .079701 2.231631 .079701S2.399004 .01594 2.438854-.079701L3.53076-2.614197Z'/>
|
||||
<path id='g2-120' d='M2.454795-1.865006C2.677958-2.14396 2.909091-2.414944 3.148194-2.677958C3.411208-2.956912 3.690162-3.164134 4.192279-3.172105V-3.435118C3.881445-3.411208 3.865504-3.411208 3.506849-3.411208C3.466999-3.411208 2.996762-3.411208 2.749689-3.435118V-3.172105C2.901121-3.156164 2.933001-3.060523 2.933001-2.956912S2.893151-2.757659 2.797509-2.646077L2.295392-2.056289L1.665753-2.805479C1.570112-2.917061 1.570112-2.972852 1.570112-2.988792C1.570112-3.044583 1.617933-3.164134 1.817186-3.172105V-3.435118C1.498381-3.411208 1.052055-3.411208 .964384-3.411208C.820922-3.411208 .414446-3.411208 .175342-3.435118V-3.172105C.71731-3.172105 .72528-3.164134 1.139726-2.677958L1.960648-1.681694L1.235367-.828892C1.036115-.605729 .74122-.278954 .135492-.263014V0C.430386-.02391 .486177-.02391 .820922-.02391C.836862-.02391 1.323039-.02391 1.578082 0V-.263014C1.474471-.278954 1.3868-.334745 1.3868-.478207S1.482441-.73325 1.506351-.773101C1.705604-1.012204 1.920797-1.251308 2.12802-1.482441L2.781569-.70137C2.940971-.518057 2.940971-.502117 2.940971-.446326C2.940971-.382565 2.885181-.270984 2.693898-.263014V0C3.036613-.02391 3.395268-.02391 3.5467-.02391C3.690162-.02391 4.096638-.02391 4.335741 0V-.263014C3.841594-.263014 3.761893-.302864 3.55467-.549938L2.454795-1.865006Z'/>
|
||||
<path id='g2-121' d='M3.53076-2.630137C3.730012-3.084433 4.024907-3.164134 4.28792-3.172105V-3.435118C4.008966-3.411208 3.993026-3.411208 3.658281-3.411208C3.626401-3.411208 3.203985-3.411208 2.972852-3.435118V-3.172105C3.203985-3.156164 3.315567-3.028643 3.315567-2.84533C3.315567-2.797509 3.307597-2.741719 3.267746-2.646077L2.414944-.71731L1.490411-2.805479C1.43462-2.925031 1.43462-2.940971 1.43462-2.972852C1.43462-3.164134 1.681694-3.172105 1.857036-3.172105V-3.435118C1.498381-3.411208 1.155666-3.411208 .980324-3.411208C.812951-3.411208 .430386-3.411208 .175342-3.435118V-3.172105C.589788-3.172105 .70137-3.156164 .836862-2.8533L2.096139 0C1.737484 .844832 1.498381 1.40274 .940473 1.40274C.74122 1.40274 .613699 1.307098 .613699 1.307098C.669489 1.291158 .852802 1.203487 .852802 .972354C.852802 .749191 .68543 .629639 .510087 .629639C.350685 .629639 .167372 .73325 .167372 .980324C.167372 1.331009 .510087 1.625903 .940473 1.625903C1.649813 1.625903 2.032379 .773101 2.064259 .6934L3.53076-2.630137Z'/>
|
||||
<path id='g3-83' d='M2.486675-4.985305C1.876961-5.140722 1.338979-5.738481 1.338979-6.503611C1.338979-7.340473 2.008468-8.093649 2.940971-8.093649C4.901619-8.093649 5.164633-6.156912 5.236364-5.642839C5.260274-5.499377 5.260274-5.451557 5.379826-5.451557C5.511333-5.451557 5.511333-5.511333 5.511333-5.726526V-8.141469C5.511333-8.356663 5.511333-8.416438 5.391781-8.416438C5.355915-8.416438 5.308095-8.416438 5.224408-8.261021L4.829888-7.531756C4.25604-8.272976 3.466999-8.416438 2.940971-8.416438C1.613948-8.416438 .645579-7.352428 .645579-6.133001C.645579-5.559153 .848817-5.033126 1.291158-4.554919C1.709589-4.088667 2.12802-3.981071 2.976837-3.765878C3.395268-3.670237 4.052802-3.502864 4.220174-3.431133C4.782067-3.156164 5.152677-2.510585 5.152677-1.841096C5.152677-.944458 4.519054-.095641 3.526775-.095641C2.988792-.095641 2.247572-.227148 1.661768-.74122C.968369-1.362889 .920548-2.223661 .908593-2.618182C.896638-2.713823 .800996-2.713823 .777086-2.713823C.645579-2.713823 .645579-2.654047 .645579-2.438854V-.02391C.645579 .191283 .645579 .251059 .765131 .251059C.836862 .251059 .848817 .227148 .932503 .083686C.980324-.011955 1.231382-.454296 1.327024-.633624C1.75741-.155417 2.510585 .251059 3.53873 .251059C4.877709 .251059 5.846077-.884682 5.846077-2.199751C5.846077-2.929016 5.571108-3.466999 5.248319-3.861519C4.805978-4.399502 4.267995-4.531009 3.801743-4.65056L2.486675-4.985305Z'/>
|
||||
<path id='g3-84' d='M7.806725-8.105604H.633624L.418431-5.439601H.681445C.848817-7.328518 .956413-7.758904 2.84533-7.758904C3.060523-7.758904 3.395268-7.758904 3.490909-7.734994C3.730012-7.699128 3.741968-7.555666 3.741968-7.280697V-.920548C3.741968-.514072 3.741968-.3467 2.570361-.3467H2.139975V0C2.52254-.02391 3.753923-.02391 4.220174-.02391S5.929763-.02391 6.312329 0V-.3467H5.881943C4.710336-.3467 4.710336-.514072 4.710336-.920548V-7.280697C4.710336-7.579577 4.734247-7.687173 4.925529-7.734994C5.021171-7.758904 5.36787-7.758904 5.595019-7.758904C7.483935-7.758904 7.591532-7.328518 7.758904-5.439601H8.021918L7.806725-8.105604Z'/>
|
||||
<path id='g3-86' d='M7.304608-6.981818C7.412204-7.280697 7.615442-7.806725 8.547945-7.81868V-8.16538C7.938232-8.141469 7.914321-8.141469 7.44807-8.141469C7.12528-8.141469 6.527522-8.141469 6.228643-8.16538V-7.81868C6.838356-7.806725 7.017684-7.47198 7.017684-7.232877C7.017684-7.161146 7.017684-7.137235 6.945953-6.969863L4.710336-1.075965L2.355168-7.292653C2.295392-7.424159 2.295392-7.44807 2.295392-7.47198C2.295392-7.81868 2.893151-7.81868 3.19203-7.81868V-8.16538C2.905106-8.141469 1.996513-8.141469 1.649813-8.141469C1.315068-8.141469 .502117-8.141469 .215193-8.16538V-7.81868C.956413-7.81868 1.147696-7.81868 1.327024-7.340473L4.124533 .02391C4.184309 .191283 4.208219 .251059 4.375592 .251059S4.554919 .215193 4.638605 .011955L7.304608-6.981818Z'/>
|
||||
<path id='g3-97' d='M4.614695-3.19203C4.614695-3.837609 4.614695-4.315816 4.088667-4.782067C3.670237-5.164633 3.132254-5.332005 2.606227-5.332005C1.625903-5.332005 .872727-4.686426 .872727-3.90934C.872727-3.56264 1.099875-3.395268 1.374844-3.395268C1.661768-3.395268 1.865006-3.598506 1.865006-3.88543C1.865006-4.375592 1.43462-4.375592 1.255293-4.375592C1.530262-4.877709 2.10411-5.092902 2.582316-5.092902C3.132254-5.092902 3.837609-4.638605 3.837609-3.56264V-3.084433C1.43462-3.048568 .526027-2.044334 .526027-1.123786C.526027-.179328 1.625903 .119552 2.355168 .119552C3.144209 .119552 3.682192-.358655 3.90934-.932503C3.957161-.37061 4.327771 .059776 4.841843 .059776C5.092902 .059776 5.786301-.107597 5.786301-1.06401V-1.733499H5.523288V-1.06401C5.523288-.382565 5.236364-.286924 5.068991-.286924C4.614695-.286924 4.614695-.920548 4.614695-1.099875V-3.19203ZM3.837609-1.685679C3.837609-.514072 2.964882-.119552 2.450809-.119552C1.865006-.119552 1.374844-.549938 1.374844-1.123786C1.374844-2.701868 3.407223-2.84533 3.837609-2.86924V-1.685679Z'/>
|
||||
<path id='g3-100' d='M3.58655-8.16538V-7.81868C4.399502-7.81868 4.495143-7.734994 4.495143-7.149191V-4.507098C4.244085-4.853798 3.730012-5.272229 3.000747-5.272229C1.613948-5.272229 .418431-4.100623 .418431-2.570361C.418431-1.052055 1.554172 .119552 2.86924 .119552C3.777833 .119552 4.303861-.478207 4.471233-.705355V.119552L6.156912 0V-.3467C5.34396-.3467 5.248319-.430386 5.248319-1.016189V-8.296887L3.58655-8.16538ZM4.471233-1.398755C4.471233-1.183562 4.471233-1.147696 4.303861-.884682C4.016936-.466252 3.526775-.119552 2.929016-.119552C2.618182-.119552 1.327024-.239103 1.327024-2.558406C1.327024-3.419178 1.470486-3.897385 1.733499-4.291905C1.972603-4.662516 2.450809-5.033126 3.048568-5.033126C3.789788-5.033126 4.208219-4.495143 4.327771-4.303861C4.471233-4.100623 4.471233-4.076712 4.471233-3.861519V-1.398755Z'/>
|
||||
<path id='g3-101' d='M4.578829-2.773599C4.841843-2.773599 4.865753-2.773599 4.865753-3.000747C4.865753-4.208219 4.220174-5.332005 2.773599-5.332005C1.41071-5.332005 .358655-4.100623 .358655-2.618182C.358655-1.0401 1.578082 .119552 2.905106 .119552C4.327771 .119552 4.865753-1.171606 4.865753-1.422665C4.865753-1.494396 4.805978-1.542217 4.734247-1.542217C4.638605-1.542217 4.614695-1.482441 4.590785-1.422665C4.27995-.418431 3.478954-.143462 2.976837-.143462S1.267248-.478207 1.267248-2.546451V-2.773599H4.578829ZM1.279203-3.000747C1.374844-4.877709 2.426899-5.092902 2.761644-5.092902C4.040847-5.092902 4.112578-3.407223 4.124533-3.000747H1.279203Z'/>
|
||||
<path id='g3-105' d='M2.080199-7.364384C2.080199-7.675218 1.829141-7.950187 1.494396-7.950187C1.183562-7.950187 .920548-7.699128 .920548-7.376339C.920548-7.017684 1.207472-6.790535 1.494396-6.790535C1.865006-6.790535 2.080199-7.10137 2.080199-7.364384ZM.430386-5.140722V-4.794022C1.195517-4.794022 1.303113-4.722291 1.303113-4.136488V-.884682C1.303113-.3467 1.171606-.3467 .394521-.3467V0C.729265-.02391 1.303113-.02391 1.649813-.02391C1.78132-.02391 2.47472-.02391 2.881196 0V-.3467C2.10411-.3467 2.056289-.406476 2.056289-.872727V-5.272229L.430386-5.140722Z'/>
|
||||
<path id='g3-108' d='M2.056289-8.296887L.394521-8.16538V-7.81868C1.207472-7.81868 1.303113-7.734994 1.303113-7.149191V-.884682C1.303113-.3467 1.171606-.3467 .394521-.3467V0C.729265-.02391 1.315068-.02391 1.673724-.02391S2.630137-.02391 2.964882 0V-.3467C2.199751-.3467 2.056289-.3467 2.056289-.884682V-8.296887Z'/>
|
||||
<path id='g3-110' d='M5.32005-2.905106C5.32005-4.016936 5.32005-4.351681 5.045081-4.734247C4.698381-5.200498 4.136488-5.272229 3.730012-5.272229C2.570361-5.272229 2.116065-4.27995 2.020423-4.040847H2.008468V-5.272229L.382565-5.140722V-4.794022C1.195517-4.794022 1.291158-4.710336 1.291158-4.124533V-.884682C1.291158-.3467 1.159651-.3467 .382565-.3467V0C.6934-.02391 1.338979-.02391 1.673724-.02391C2.020423-.02391 2.666002-.02391 2.976837 0V-.3467C2.211706-.3467 2.068244-.3467 2.068244-.884682V-3.108344C2.068244-4.363636 2.893151-5.033126 3.634371-5.033126S4.542964-4.423412 4.542964-3.694147V-.884682C4.542964-.3467 4.411457-.3467 3.634371-.3467V0C3.945205-.02391 4.590785-.02391 4.925529-.02391C5.272229-.02391 5.917808-.02391 6.228643 0V-.3467C5.630884-.3467 5.332005-.3467 5.32005-.705355V-2.905106Z'/>
|
||||
<path id='g3-111' d='M5.487422-2.558406C5.487422-4.100623 4.315816-5.332005 2.929016-5.332005C1.494396-5.332005 .358655-4.064757 .358655-2.558406C.358655-1.028144 1.554172 .119552 2.917061 .119552C4.327771 .119552 5.487422-1.052055 5.487422-2.558406ZM2.929016-.143462C2.486675-.143462 1.948692-.334745 1.601993-.920548C1.279203-1.458531 1.267248-2.163885 1.267248-2.666002C1.267248-3.120299 1.267248-3.849564 1.637858-4.387547C1.972603-4.901619 2.49863-5.092902 2.917061-5.092902C3.383313-5.092902 3.88543-4.877709 4.208219-4.411457C4.578829-3.861519 4.578829-3.108344 4.578829-2.666002C4.578829-2.247572 4.578829-1.506351 4.267995-.944458C3.93325-.37061 3.383313-.143462 2.929016-.143462Z'/>
|
||||
<path id='g3-112' d='M2.929016 1.972603C2.163885 1.972603 2.020423 1.972603 2.020423 1.43462V-.645579C2.235616-.3467 2.725778 .119552 3.490909 .119552C4.865753 .119552 6.073225-1.0401 6.073225-2.582316C6.073225-4.100623 4.94944-5.272229 3.646326-5.272229C2.594271-5.272229 2.032379-4.519054 1.996513-4.471233V-5.272229L.334745-5.140722V-4.794022C1.171606-4.794022 1.243337-4.710336 1.243337-4.184309V1.43462C1.243337 1.972603 1.111831 1.972603 .334745 1.972603V2.319303C.645579 2.295392 1.291158 2.295392 1.625903 2.295392C1.972603 2.295392 2.618182 2.295392 2.929016 2.319303V1.972603ZM2.020423-3.813699C2.020423-4.040847 2.020423-4.052802 2.15193-4.244085C2.510585-4.782067 3.096389-5.009215 3.550685-5.009215C4.447323-5.009215 5.164633-3.921295 5.164633-2.582316C5.164633-1.159651 4.351681-.119552 3.431133-.119552C3.060523-.119552 2.713823-.274969 2.47472-.502117C2.199751-.777086 2.020423-1.016189 2.020423-1.350934V-3.813699Z'/>
|
||||
<path id='g3-114' d='M1.996513-2.785554C1.996513-3.945205 2.47472-5.033126 3.395268-5.033126C3.490909-5.033126 3.514819-5.033126 3.56264-5.021171C3.466999-4.97335 3.275716-4.901619 3.275716-4.578829C3.275716-4.23213 3.550685-4.100623 3.741968-4.100623C3.981071-4.100623 4.220174-4.25604 4.220174-4.578829C4.220174-4.937484 3.897385-5.272229 3.383313-5.272229C2.367123-5.272229 2.020423-4.172354 1.948692-3.945205H1.936737V-5.272229L.334745-5.140722V-4.794022C1.147696-4.794022 1.243337-4.710336 1.243337-4.124533V-.884682C1.243337-.3467 1.111831-.3467 .334745-.3467V0C.669489-.02391 1.327024-.02391 1.685679-.02391C2.008468-.02391 2.857285-.02391 3.132254 0V-.3467H2.893151C2.020423-.3467 1.996513-.478207 1.996513-.908593V-2.785554Z'/>
|
||||
<path id='g3-116' d='M2.008468-4.805978H3.694147V-5.152677H2.008468V-7.352428H1.745455C1.733499-6.228643 1.303113-5.080946 .215193-5.045081V-4.805978H1.231382V-1.482441C1.231382-.155417 2.116065 .119552 2.749689 .119552C3.502864 .119552 3.897385-.621669 3.897385-1.482441V-2.163885H3.634371V-1.506351C3.634371-.645579 3.287671-.143462 2.82142-.143462C2.008468-.143462 2.008468-1.255293 2.008468-1.458531V-4.805978Z'/>
|
||||
<path id='g3-119' d='M7.232877-4.016936C7.49589-4.770112 8.021918-4.794022 8.225156-4.805978V-5.152677C7.926276-5.128767 7.711083-5.128767 7.340473-5.128767C6.993773-5.128767 6.969863-5.128767 6.324284-5.152677V-4.805978C6.862267-4.782067 7.005729-4.459278 7.005729-4.23213C7.005729-4.220174 7.005729-4.136488 6.957908-4.016936L5.858032-.884682L4.662516-4.267995C4.60274-4.411457 4.60274-4.435367 4.60274-4.471233C4.60274-4.805978 5.045081-4.805978 5.296139-4.805978V-5.152677C4.961395-5.128767 4.471233-5.128767 4.124533-5.128767C3.741968-5.128767 3.718057-5.128767 3.048568-5.152677V-4.805978C3.502864-4.805978 3.658281-4.782067 3.789788-4.62665C3.849564-4.554919 3.993026-4.160399 4.076712-3.921295L3.060523-1.004234L1.912827-4.25604C1.853051-4.411457 1.853051-4.435367 1.853051-4.483188C1.853051-4.805978 2.319303-4.805978 2.546451-4.805978V-5.152677C2.247572-5.128767 1.649813-5.128767 1.327024-5.128767C.992279-5.128767 .968369-5.128767 .215193-5.152677V-4.805978C.824907-4.805978 .944458-4.758157 1.075965-4.375592L2.582316-.095641C2.630137 .035866 2.666002 .119552 2.797509 .119552C2.905106 .119552 2.964882 .083686 3.024658-.107597L4.220174-3.514819L5.415691-.107597C5.475467 .083686 5.535243 .119552 5.642839 .119552C5.774346 .119552 5.810212 .035866 5.858032-.095641L7.232877-4.016936Z'/>
|
||||
<path id='g3-120' d='M3.347447-2.82142C3.694147-3.275716 4.196264-3.921295 4.423412-4.172354C4.913574-4.722291 5.475467-4.805978 5.858032-4.805978V-5.152677C5.34396-5.128767 5.32005-5.128767 4.853798-5.128767C4.399502-5.128767 4.375592-5.128767 3.777833-5.152677V-4.805978C3.93325-4.782067 4.124533-4.710336 4.124533-4.435367C4.124533-4.23213 4.016936-4.100623 3.945205-4.004981L3.180075-3.036613L2.247572-4.267995C2.211706-4.315816 2.139975-4.423412 2.139975-4.507098C2.139975-4.578829 2.199751-4.794022 2.558406-4.805978V-5.152677C2.259527-5.128767 1.649813-5.128767 1.327024-5.128767C.932503-5.128767 .908593-5.128767 .179328-5.152677V-4.805978C.789041-4.805978 1.016189-4.782067 1.267248-4.459278L2.666002-2.630137C2.689913-2.606227 2.737733-2.534496 2.737733-2.49863S1.80523-1.291158 1.685679-1.135741C1.159651-.490162 .633624-.358655 .119552-.3467V0C.573848-.02391 .597758-.02391 1.111831-.02391C1.566127-.02391 1.590037-.02391 2.187796 0V-.3467C1.900872-.382565 1.853051-.561893 1.853051-.729265C1.853051-.920548 1.936737-1.016189 2.056289-1.171606C2.235616-1.422665 2.630137-1.912827 2.917061-2.283437L3.897385-1.004234C4.100623-.74122 4.100623-.71731 4.100623-.645579C4.100623-.549938 4.004981-.358655 3.682192-.3467V0C3.993026-.02391 4.578829-.02391 4.913574-.02391C5.308095-.02391 5.332005-.02391 6.049315 0V-.3467C5.415691-.3467 5.200498-.37061 4.913574-.753176L3.347447-2.82142Z'/>
|
||||
<path id='g4-14' d='M3.043587-1.24533C3.043587-1.912827 2.500623-2.455791 1.833126-2.455791S.622665-1.912827 .622665-1.24533S1.165629-.034869 1.833126-.034869S3.043587-.577833 3.043587-1.24533ZM1.833126-.313823C1.32005-.313823 .901619-.732254 .901619-1.24533S1.32005-2.176837 1.833126-2.176837S2.764633-1.758406 2.764633-1.24533S2.346202-.313823 1.833126-.313823Z'/>
|
||||
<path id='g5-48' d='M3.598506-2.224658C3.598506-2.991781 3.507846-3.542715 3.187049-4.030884C2.970859-4.351681 2.538481-4.630635 1.980573-4.630635C.36264-4.630635 .36264-2.726775 .36264-2.224658S.36264 .139477 1.980573 .139477S3.598506-1.72254 3.598506-2.224658ZM1.980573-.055791C1.659776-.055791 1.234371-.244085 1.094894-.81594C.99726-1.227397 .99726-1.799253 .99726-2.315318C.99726-2.824408 .99726-3.354421 1.101868-3.737983C1.248319-4.288917 1.694645-4.435367 1.980573-4.435367C2.357161-4.435367 2.719801-4.20523 2.84533-3.800747C2.956912-3.424159 2.963885-2.922042 2.963885-2.315318C2.963885-1.799253 2.963885-1.283188 2.873225-.843836C2.733748-.209215 2.259527-.055791 1.980573-.055791Z'/>
|
||||
<path id='g5-49' d='M2.336239-4.435367C2.336239-4.623661 2.322291-4.630635 2.127024-4.630635C1.680697-4.191283 1.046077-4.184309 .760149-4.184309V-3.93325C.927522-3.93325 1.387796-3.93325 1.771357-4.128518V-.571856C1.771357-.341719 1.771357-.251059 1.073973-.251059H.808966V0C.934496-.006974 1.792279-.027895 2.050311-.027895C2.266501-.027895 3.145205-.006974 3.29863 0V-.251059H3.033624C2.336239-.251059 2.336239-.341719 2.336239-.571856V-4.435367Z'/>
|
||||
<path id='g5-50' d='M3.521793-1.26924H3.284682C3.263761-1.115816 3.194022-.704359 3.103362-.63462C3.047572-.592777 2.510585-.592777 2.412951-.592777H1.129763C1.862017-1.241345 2.106102-1.436613 2.524533-1.764384C3.040598-2.175841 3.521793-2.608219 3.521793-3.270735C3.521793-4.11457 2.782565-4.630635 1.889913-4.630635C1.025156-4.630635 .439352-4.02391 .439352-3.382316C.439352-3.02665 .739228-2.991781 .808966-2.991781C.976339-2.991781 1.17858-3.110336 1.17858-3.361395C1.17858-3.486924 1.129763-3.731009 .767123-3.731009C.983313-4.226152 1.457534-4.379577 1.785305-4.379577C2.48269-4.379577 2.84533-3.835616 2.84533-3.270735C2.84533-2.66401 2.412951-2.182814 2.189788-1.931756L.509091-.27198C.439352-.209215 .439352-.195268 .439352 0H3.312578L3.521793-1.26924Z'/>
|
||||
<path id='g5-51' d='M1.903861-2.329265C2.447821-2.329265 2.838356-1.952677 2.838356-1.206476C2.838356-.341719 2.336239-.083686 1.931756-.083686C1.652802-.083686 1.039103-.160399 .746202-.571856C1.073973-.585803 1.150685-.81594 1.150685-.962391C1.150685-1.185554 .983313-1.345953 .767123-1.345953C.571856-1.345953 .376588-1.227397 .376588-.941469C.376588-.285928 1.101868 .139477 1.945704 .139477C2.915068 .139477 3.584558-.509091 3.584558-1.206476C3.584558-1.750436 3.138232-2.294396 2.371108-2.454795C3.103362-2.719801 3.368369-3.242839 3.368369-3.668244C3.368369-4.219178 2.733748-4.630635 1.959651-4.630635S.592777-4.254047 .592777-3.696139C.592777-3.459029 .746202-3.326526 .955417-3.326526C1.171606-3.326526 1.311083-3.486924 1.311083-3.682192C1.311083-3.884433 1.171606-4.030884 .955417-4.044832C1.199502-4.351681 1.680697-4.428394 1.93873-4.428394C2.252553-4.428394 2.691905-4.274969 2.691905-3.668244C2.691905-3.375342 2.594271-3.054545 2.412951-2.838356C2.182814-2.57335 1.987547-2.559402 1.638854-2.538481C1.464508-2.524533 1.45056-2.524533 1.415691-2.517559C1.401743-2.517559 1.345953-2.503611 1.345953-2.426899C1.345953-2.329265 1.408717-2.329265 1.527273-2.329265H1.903861Z'/>
|
||||
<path id='g5-52' d='M3.689166-1.143711V-1.39477H2.915068V-4.505106C2.915068-4.651557 2.915068-4.700374 2.761644-4.700374C2.677958-4.700374 2.650062-4.700374 2.580324-4.60274L.27198-1.39477V-1.143711H2.322291V-.571856C2.322291-.334745 2.322291-.251059 1.75741-.251059H1.569116V0C1.917808-.013948 2.364134-.027895 2.615193-.027895C2.873225-.027895 3.319552-.013948 3.668244 0V-.251059H3.47995C2.915068-.251059 2.915068-.334745 2.915068-.571856V-1.143711H3.689166ZM2.371108-3.947198V-1.39477H.530012L2.371108-3.947198Z'/>
|
||||
</defs>
|
||||
<g id='page1'>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M77.8071 165.443L121.782 206.781L49.993 240.848L77.8071 165.443Z' fill='#d7e3f4'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M77.8071 165.443L121.782 206.781L49.993 240.848L77.8071 165.443Z' fill='none' stroke='#231f20' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10.0375' stroke-width='0.451687'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M77.8071 165.443L49.993 240.848L6.01782 179.13L77.8071 165.443Z' fill='#d6e2f3'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M77.8071 165.443L49.993 240.848L6.01782 179.13L77.8071 165.443Z' fill='none' stroke='#231f20' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10.0375' stroke-width='0.451687'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M77.8071 165.443L6.01782 179.13L33.8319 169.481L77.8071 165.443Z' fill='#bec8d7'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M77.8071 165.443L6.01782 179.13L33.8319 169.481L77.8071 165.443Z' fill='none' stroke='#231f20' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10.0375' stroke-width='0.451687'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M77.8071 165.443L33.8319 169.481L105.621 135.413L77.8071 165.443Z' fill='#c6d1e1'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M77.8071 165.443L33.8319 169.481L105.621 135.413L77.8071 165.443Z' fill='none' stroke='#231f20' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10.0375' stroke-width='0.451687'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M77.8071 165.443L105.621 135.413L149.596 197.131L77.8071 165.443Z' fill='#c4cfdf'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M77.8071 165.443L105.621 135.413L149.596 197.131L77.8071 165.443Z' fill='none' stroke='#231f20' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10.0375' stroke-width='0.451687'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M77.8071 165.443L149.596 197.131L121.782 206.781L77.8071 165.443Z' fill='#bcc7d6'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M77.8071 165.443L149.596 197.131L121.782 206.781L77.8071 165.443Z' fill='none' stroke='#231f20' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10.0375' stroke-width='0.451687'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M77.8071 165.443L121.782 206.781' fill='none' stroke='#c26a17' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10.0375' stroke-width='1.05394'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M126.099 209.539C126.422 209.539 127.237 209.515 127.813 209.299C128.724 208.951 128.809 208.256 128.809 208.039C128.809 207.513 128.353 207.033 127.562 207.033C126.303 207.033 124.491 208.171 124.491 210.306C124.491 211.565 125.211 212.44 126.303 212.44C127.934 212.44 128.964 211.17 128.964 211.013C128.964 210.943 128.894 210.881 128.845 210.881C128.809 210.881 128.796 210.894 128.69 211.002C127.921 212.022 126.783 212.202 126.326 212.202C125.642 212.202 125.283 211.661 125.283 210.775C125.283 210.605 125.283 210.306 125.464 209.539H126.099ZM125.523 209.299C126.039 207.451 127.178 207.273 127.562 207.273C128.089 207.273 128.45 207.583 128.45 208.039C128.45 209.299 126.53 209.299 126.027 209.299H125.523ZM133.282 211.578C133.282 210.721 133.194 210.202 132.931 209.691C132.578 208.987 131.93 208.811 131.491 208.811C130.484 208.811 130.115 209.562 130.004 209.787C129.715 210.37 129.7 211.162 129.7 211.578C129.7 212.105 129.723 212.912 130.108 213.552C130.476 214.144 131.067 214.296 131.491 214.296C131.875 214.296 132.562 214.176 132.962 213.384C133.258 212.809 133.282 212.097 133.282 211.578ZM131.491 214.071C131.219 214.071 130.667 213.944 130.5 213.104C130.412 212.649 130.412 211.898 130.412 211.482C130.412 210.93 130.412 210.37 130.5 209.931C130.667 209.115 131.292 209.035 131.491 209.035C131.762 209.035 132.314 209.17 132.474 209.898C132.57 210.339 132.57 210.938 132.57 211.482C132.57 211.953 132.57 212.672 132.474 213.121C132.306 213.96 131.754 214.071 131.491 214.071Z' fill='#c26a17'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M77.8071 165.443L49.993 240.848' fill='none' stroke='#1f5c99' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10.0375' stroke-width='1.05394'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M45.793 244.335C46.116 244.335 46.9316 244.311 47.5072 244.095C48.4184 243.746 48.5031 243.052 48.5031 242.835C48.5031 242.308 48.0467 241.828 47.2562 241.828C45.9968 241.828 44.1854 242.967 44.1854 245.101C44.1854 246.361 44.9053 247.236 45.9968 247.236C47.6279 247.236 48.6584 245.966 48.6584 245.809C48.6584 245.738 48.5878 245.677 48.5392 245.677C48.5031 245.677 48.4905 245.69 48.3839 245.798C47.6154 246.817 46.4768 246.998 46.0204 246.998C45.3366 246.998 44.9774 246.457 44.9774 245.57C44.9774 245.401 44.9774 245.101 45.1578 244.335H45.793ZM45.2174 244.095C45.7334 242.247 46.872 242.068 47.2562 242.068C47.7832 242.068 48.1439 242.379 48.1439 242.835C48.1439 244.095 46.2243 244.095 45.7208 244.095H45.2174ZM51.5771 243.831C51.5771 243.615 51.5614 243.607 51.345 243.607C51.0172 243.927 50.5937 244.118 49.8331 244.118V244.382C50.0495 244.382 50.4808 244.382 50.945 244.167V248.268C50.945 248.564 50.9215 248.66 50.1608 248.66H49.8817V248.924C50.2095 248.9 50.8964 248.9 51.2571 248.9C51.6163 248.9 52.3126 248.9 52.6404 248.924V248.66H52.3597C51.6006 248.66 51.5771 248.564 51.5771 248.268V243.831Z' fill='#1f5c99'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M77.8071 165.443L6.01782 179.13' fill='none' stroke='#c26a17' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10.0375' stroke-width='1.05394'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M2.13454 170.967C2.45762 170.967 3.27317 170.944 3.84876 170.727C4.75997 170.379 4.84466 169.684 4.84466 169.468C4.84466 168.941 4.38828 168.461 3.59782 168.461C2.33842 168.461 .526969 169.6 .526969 171.734C.526969 172.994 1.24684 173.869 2.33842 173.869C3.96952 173.869 4.99993 172.599 4.99993 172.442C4.99993 172.371 4.92936 172.31 4.88074 172.31C4.84466 172.31 4.83211 172.322 4.72546 172.431C3.95697 173.45 2.81834 173.63 2.36195 173.63C1.67815 173.63 1.31899 173.089 1.31899 172.203C1.31899 172.034 1.31899 171.734 1.49935 170.967H2.13454ZM1.55895 170.727C2.07494 168.88 3.21356 168.701 3.59782 168.701C4.12479 168.701 4.48551 169.012 4.48551 169.468C4.48551 170.727 2.56584 170.727 2.0624 170.727H1.55895ZM7.66301 173.925C7.79005 173.806 8.12567 173.541 8.25427 173.43C8.74988 172.973 9.22196 172.534 9.22196 171.806C9.22196 170.855 8.42209 170.24 7.42305 170.24C6.46321 170.24 5.83117 170.967 5.83117 171.678C5.83117 172.07 6.14327 172.126 6.25462 172.126C6.42243 172.126 6.67024 172.007 6.67024 171.703C6.67024 171.287 6.27187 171.287 6.17463 171.287C6.40675 170.704 6.94313 170.503 7.33522 170.503C8.07862 170.503 8.4613 171.135 8.4613 171.806C8.4613 172.638 7.87787 173.246 6.93529 174.214L5.92683 175.252C5.83117 175.34 5.83117 175.357 5.83117 175.556H8.98984L9.22196 174.125H8.97416C8.94905 174.285 8.88632 174.684 8.78908 174.837C8.74204 174.901 8.13351 174.901 8.00647 174.901H6.5824L7.66301 173.925Z' fill='#c26a17'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M77.8071 165.443L33.8319 169.481' fill='none' stroke='#1f5c99' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10.0375' stroke-width='1.05394'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M20.1297 166.155C20.4528 166.155 21.2684 166.131 21.8439 165.915C22.7552 165.567 22.8398 164.872 22.8398 164.656C22.8398 164.129 22.3835 163.649 21.593 163.649C20.3336 163.649 18.5222 164.787 18.5222 166.922C18.5222 168.181 19.242 169.056 20.3336 169.056C21.9647 169.056 22.9951 167.786 22.9951 167.629C22.9951 167.559 22.9245 167.497 22.8759 167.497C22.8398 167.497 22.8273 167.51 22.7206 167.618C21.9522 168.638 20.8135 168.818 20.3571 168.818C19.6733 168.818 19.3142 168.277 19.3142 167.391C19.3142 167.221 19.3142 166.922 19.4945 166.155H20.1297ZM19.5541 165.915C20.0701 164.067 21.2087 163.889 21.593 163.889C22.12 163.889 22.4807 164.199 22.4807 164.656C22.4807 165.915 20.561 165.915 20.0576 165.915H19.5541ZM25.4261 168.073C26.0581 168.073 26.4565 168.537 26.4565 169.376C26.4565 170.375 25.8887 170.672 25.4653 170.672C25.0261 170.672 24.427 170.512 24.1463 170.088C24.4349 170.088 24.634 169.905 24.634 169.64C24.634 169.384 24.4506 169.201 24.1949 169.201C23.9785 169.201 23.7542 169.337 23.7542 169.657C23.7542 170.416 24.5697 170.912 25.481 170.912C26.5443 170.912 27.2893 170.176 27.2893 169.376C27.2893 168.713 26.7607 168.106 25.9452 167.93C26.5773 167.706 27.0493 167.162 27.0493 166.522S26.3294 165.427 25.4982 165.427C24.6419 165.427 23.9942 165.891 23.9942 166.498C23.9942 166.795 24.1949 166.922 24.4019 166.922C24.6497 166.922 24.8097 166.746 24.8097 166.514C24.8097 166.219 24.5541 166.106 24.3784 166.098C24.714 165.659 25.3304 165.634 25.4731 165.634C25.6817 165.634 26.2887 165.698 26.2887 166.522C26.2887 167.082 26.0581 167.417 25.9452 167.546C25.7052 167.794 25.5217 167.809 25.034 167.841C24.8819 167.85 24.8175 167.858 24.8175 167.962C24.8175 168.073 24.8897 168.073 25.0261 168.073H25.4261Z' fill='#1f5c99'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M77.8071 165.443L105.621 135.413' fill='none' stroke='#c26a17' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10.0375' stroke-width='1.05394'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M113.134 136.446C113.457 136.446 114.273 136.422 114.848 136.206C115.76 135.857 115.844 135.163 115.844 134.946C115.844 134.419 115.388 133.939 114.597 133.939C113.338 133.939 111.527 135.078 111.527 137.213C111.527 138.472 112.246 139.347 113.338 139.347C114.969 139.347 116 138.077 116 137.92C116 137.849 115.929 137.788 115.88 137.788C115.844 137.788 115.832 137.801 115.725 137.909C114.957 138.928 113.818 139.109 113.362 139.109C112.678 139.109 112.319 138.568 112.319 137.681C112.319 137.512 112.319 137.213 112.499 136.446H113.134ZM112.559 136.206C113.075 134.358 114.213 134.179 114.597 134.179C115.124 134.179 115.485 134.49 115.485 134.946C115.485 136.206 113.565 136.206 113.062 136.206H112.559ZM119.558 135.862C119.558 135.702 119.558 135.638 119.39 135.638C119.285 135.638 119.277 135.646 119.197 135.757L116.647 139.46V139.723H118.903V140.387C118.903 140.683 118.877 140.771 118.263 140.771H118.078V141.035C118.758 141.011 118.774 141.011 119.23 141.011C119.685 141.011 119.701 141.011 120.382 141.035V140.771H120.196C119.582 140.771 119.558 140.683 119.558 140.387V139.723H120.405V139.46H119.558V135.862ZM118.957 136.51V139.46H116.926L118.957 136.51Z' fill='#c26a17'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M77.8071 165.443L149.596 197.131' fill='none' stroke='#1f5c99' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10.0375' stroke-width='1.05394'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M148 203.211C148.323 203.211 149.138 203.188 149.714 202.971C150.625 202.623 150.71 201.929 150.71 201.712C150.71 201.185 150.254 200.705 149.463 200.705C148.204 200.705 146.392 201.844 146.392 203.978C146.392 205.238 147.112 206.113 148.204 206.113C149.835 206.113 150.865 204.843 150.865 204.686C150.865 204.615 150.795 204.554 150.746 204.554C150.71 204.554 150.697 204.567 150.591 204.675C149.822 205.694 148.684 205.875 148.227 205.875C147.543 205.875 147.184 205.333 147.184 204.447C147.184 204.278 147.184 203.978 147.365 203.211H148ZM147.424 202.971C147.94 201.124 149.079 200.945 149.463 200.945C149.99 200.945 150.351 201.256 150.351 201.712C150.351 202.971 148.431 202.971 147.928 202.971H147.424ZM152.393 203.307C152.496 203.338 152.816 203.418 153.152 203.418C154.151 203.418 154.759 202.716 154.759 202.595C154.759 202.507 154.703 202.484 154.664 202.484C154.647 202.484 154.631 202.484 154.559 202.523C154.247 202.644 153.88 202.739 153.448 202.739C152.976 202.739 152.584 202.62 152.336 202.523C152.256 202.484 152.241 202.484 152.233 202.484C152.128 202.484 152.128 202.572 152.128 202.716V205.057C152.128 205.202 152.128 205.297 152.256 205.297C152.321 205.297 152.344 205.266 152.385 205.202C152.481 205.082 152.785 204.675 153.464 204.675C153.911 204.675 154.127 205.042 154.2 205.194C154.336 205.482 154.352 205.849 154.352 206.162C154.352 206.458 154.344 206.889 154.12 207.241C153.967 207.481 153.648 207.728 153.224 207.728C152.705 207.728 152.192 207.401 152.009 206.881C152.032 206.889 152.081 206.889 152.089 206.889C152.313 206.889 152.489 206.745 152.489 206.497C152.489 206.201 152.256 206.097 152.096 206.097C151.952 206.097 151.696 206.177 151.696 206.521C151.696 207.241 152.321 207.968 153.24 207.968C154.239 207.968 155.087 207.193 155.087 206.201C155.087 205.274 154.414 204.45 153.472 204.45C153.072 204.45 152.696 204.579 152.393 204.85V203.307Z' fill='#1f5c99'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M77.8071 165.443L135.143 84.8861L33.6563 129.429L77.8071 165.443Z' fill='#c26a17' opacity='0.18'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M77.8071 165.443L135.143 84.8861' fill='none' stroke='#c26a17' stroke-dasharray='1.50385,1.12789' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10.0375' stroke-width='0.376406'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M77.8071 165.443L33.6563 129.429' fill='none' stroke='#c26a17' stroke-dasharray='1.50931,1.13198' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10.0375' stroke-width='0.376406'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M117.167 131.752C88.7405 144.228 48.0746 141.116 26.3369 124.801C4.59925 108.485 10.0214 85.1445 38.4476 72.668S107.54 63.3035 129.277 79.619C151.015 95.9345 145.593 119.275 117.167 131.752Z' fill='#eeeeee' opacity='0.75'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M117.167 131.752C88.7405 144.228 48.0746 141.116 26.3369 124.801C4.59925 108.485 10.0214 85.1445 38.4476 72.668S107.54 63.3035 129.277 79.619C151.015 95.9345 145.593 119.275 117.167 131.752Z' fill='none' stroke='#999999' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10.0375' stroke-width='0.376406'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M135.143 84.8861L33.6563 129.429' fill='none' stroke='#c26a17' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10.0375' stroke-width='0.60225'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M99.1937 137.315L19.3428 118.242' fill='none' stroke='#1f5c99' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10.0375' stroke-width='0.60225'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M75.2785 139.371L58.8119 66.6543' fill='none' stroke='#c26a17' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10.0375' stroke-width='0.60225'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M14.1447 95.2876L82.8482 65.133' fill='none' stroke='#1f5c99' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10.0375' stroke-width='0.60225'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M23.0003 82.3723L140.953 110.546' fill='none' stroke='#c26a17' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10.0375' stroke-width='0.60225'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M120.083 74.0266L131.23 123.254' fill='none' stroke='#1f5c99' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10.0375' stroke-width='0.60225'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M99.331 100.604L69.4679 113.711L64.6225 92.3139L99.331 100.604Z' fill='#f2d4d0'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M99.331 100.604L69.4679 113.711L64.6225 92.3139L99.331 100.604Z' fill='none' stroke='#a8322a' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10.0375' stroke-width='0.752812'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M77.8071 165.443L99.331 100.604' fill='none' stroke='#a8322a' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10.0375' stroke-width='0.752812'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M77.8071 165.443L69.4679 113.711' fill='none' stroke='#a8322a' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10.0375' stroke-width='0.752812'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M77.8071 165.443L64.6225 92.3139' fill='none' stroke='#a8322a' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10.0375' stroke-width='0.752812'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<circle cx='77.8071' cy='165.443' fill='#231f20' r='1.12922'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M122.443 66.8631C122.443 66.6483 122.443 66.5871 122.324 66.5871C122.228 66.5871 121.999 66.8522 121.916 66.9604C121.544 66.6592 121.172 66.5871 120.788 66.5871C119.337 66.5871 118.905 67.3791 118.905 68.0394C118.905 68.1711 118.905 68.5915 119.361 69.0102C119.745 69.3458 120.153 69.4305 120.704 69.5387C121.364 69.6705 121.519 69.7066 121.82 69.9465C122.035 70.1253 122.192 70.3904 122.192 70.726C122.192 71.2404 121.891 71.8176 120.837 71.8176C120.045 71.8176 119.469 71.3612 119.206 70.1614C119.157 69.9465 119.157 69.934 119.145 69.9214C119.121 69.8744 119.072 69.8744 119.036 69.8744C118.905 69.8744 118.905 69.934 118.905 70.1504V71.7815C118.905 71.9964 118.905 72.056 119.025 72.056C119.085 72.056 119.098 72.045 119.301 71.7925C119.361 71.7094 119.361 71.6843 119.541 71.4929C119.996 72.056 120.644 72.056 120.848 72.056C122.107 72.056 122.731 71.3612 122.731 70.4139C122.731 69.7662 122.335 69.3819 122.228 69.2737C121.795 68.902 121.472 68.8299 120.68 68.6871C120.321 68.615 119.444 68.4472 119.444 67.7273C119.444 67.3556 119.697 66.8035 120.776 66.8035C122.084 66.8035 122.156 67.9186 122.179 68.2903C122.192 68.3876 122.275 68.3876 122.311 68.3876C122.443 68.3876 122.443 68.3264 122.443 68.1115V66.8631ZM125.149 63.6135L123.481 63.7452V64.0934C124.297 64.0934 124.394 64.1765 124.394 64.7647V71.0491C124.394 71.5886 124.261 71.5886 123.481 71.5886V71.9368C123.817 71.9132 124.405 71.9132 124.766 71.9132C125.125 71.9132 125.724 71.9132 126.06 71.9368V71.5886C125.293 71.5886 125.149 71.5886 125.149 71.0491V63.6135ZM128.426 64.5482C128.426 64.2377 128.173 63.9617 127.838 63.9617C127.525 63.9617 127.262 64.2126 127.262 64.5372C127.262 64.8964 127.549 65.1254 127.838 65.1254C128.209 65.1254 128.426 64.8133 128.426 64.5482ZM126.77 66.78V67.1282C127.538 67.1282 127.646 67.1988 127.646 67.7869V71.0491C127.646 71.5886 127.513 71.5886 126.733 71.5886V71.9368C127.069 71.9132 127.646 71.9132 127.993 71.9132C128.125 71.9132 128.821 71.9132 129.229 71.9368V71.5886C128.449 71.5886 128.401 71.529 128.401 71.0616V66.6483L126.77 66.78ZM133.931 67.4999C133.787 67.4999 133.343 67.4999 133.343 67.9908C133.343 68.2794 133.547 68.4832 133.836 68.4832C134.112 68.4832 134.339 68.3154 134.339 67.9673C134.339 67.1642 133.5 66.5871 132.529 66.5871C131.126 66.5871 130.011 67.8355 130.011 69.3458C130.011 70.8813 131.162 72.056 132.517 72.056C134.099 72.056 134.46 70.6178 134.46 70.5096C134.46 70.4013 134.375 70.4013 134.339 70.4013C134.231 70.4013 134.22 70.4374 134.184 70.5817C133.92 71.4333 133.273 71.7925 132.625 71.7925C131.893 71.7925 130.922 71.1573 130.922 69.3349C130.922 67.343 131.941 66.8522 132.54 66.8522C132.997 66.8522 133.655 67.0309 133.931 67.4999ZM139.363 69.1545C139.627 69.1545 139.65 69.1545 139.65 68.9271C139.65 67.7148 139.002 66.5871 137.552 66.5871C136.184 66.5871 135.128 67.823 135.128 69.3098C135.128 70.8938 136.352 72.056 137.683 72.056C139.111 72.056 139.65 70.7621 139.65 70.5096C139.65 70.4374 139.591 70.3904 139.518 70.3904C139.423 70.3904 139.399 70.45 139.374 70.5096C139.064 71.5165 138.259 71.7925 137.755 71.7925C137.252 71.7925 136.041 71.4569 136.041 69.3819V69.1545H139.363ZM136.052 68.9271C136.148 67.0435 137.203 66.827 137.539 66.827C138.824 66.827 138.896 68.5193 138.907 68.9271H136.052Z' fill='#595959'/>
|
||||
</g>
|
||||
<g fill='#231f20'>
|
||||
<use x='77.067032' y='567.684994' xlink:href='#g3-83'/>
|
||||
<use x='83.570354' y='567.684994' xlink:href='#g3-97'/>
|
||||
<use x='89.423345' y='567.684994' xlink:href='#g3-100'/>
|
||||
<use x='95.926667' y='567.684994' xlink:href='#g3-100'/>
|
||||
<use x='102.42999' y='567.684994' xlink:href='#g3-108'/>
|
||||
<use x='105.681651' y='567.684994' xlink:href='#g3-101'/>
|
||||
<use x='114.786302' y='567.684994' xlink:href='#g3-86'/>
|
||||
<use x='122.586151' y='567.684994' xlink:href='#g3-101'/>
|
||||
<use x='127.788809' y='567.684994' xlink:href='#g3-114'/>
|
||||
<use x='132.341135' y='567.684994' xlink:href='#g3-116'/>
|
||||
<use x='136.89346' y='567.684994' xlink:href='#g3-101'/>
|
||||
<use x='142.096118' y='567.684994' xlink:href='#g3-120'/>
|
||||
<use x='152.176268' y='567.684994' xlink:href='#g3-86'/>
|
||||
<use x='159.976116' y='567.684994' xlink:href='#g3-111'/>
|
||||
<use x='165.829107' y='567.684994' xlink:href='#g3-114'/>
|
||||
<use x='170.381432' y='567.684994' xlink:href='#g3-111'/>
|
||||
<use x='176.234423' y='567.684994' xlink:href='#g3-110'/>
|
||||
<use x='182.737745' y='567.684994' xlink:href='#g3-111'/>
|
||||
<use x='188.590735' y='567.684994' xlink:href='#g3-105'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M371.672 191.924L322.499 220.314L213.019 157.106V100.325L322.499 37.1166L371.672 65.5069V191.924Z' fill='#ebebeb'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M322.499 15.4717V241.959H327.505V15.4717H322.499Z' fill='#c26a17' opacity='0.25'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M409.774 169.925L284.397 242.312L286.9 246.647L412.277 174.261L409.774 169.925Z' fill='#1f5c99' opacity='0.25'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M390.418 202.746L194.274 89.5025L191.771 93.838L387.914 207.081L390.418 202.746Z' fill='#c26a17' opacity='0.25'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M213.019 201.102V56.3287H208.013V201.102H213.019Z' fill='#1f5c99' opacity='0.25'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M194.274 167.928L390.418 54.6845L387.914 50.349L191.771 163.593L194.274 167.928Z' fill='#c26a17' opacity='0.25'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M284.397 15.1185L409.774 87.505L412.277 83.1695L286.9 10.783L284.397 15.1185Z' fill='#1f5c99' opacity='0.25'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M322.499 10.3906V247.04' fill='none' stroke='#c26a17' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10.0375' stroke-width='0.752812'/>
|
||||
</g>
|
||||
<g fill='#c16a17'>
|
||||
<use x='388.828529' y='431.70318' xlink:href='#g1-101'/>
|
||||
<use x='394.253969' y='433.496443' xlink:href='#g2-48'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M416.457 166.067L277.715 246.17' fill='none' stroke='#1f5c99' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10.0375' stroke-width='0.752812'/>
|
||||
</g>
|
||||
<g fill='#1f5c98'>
|
||||
<use x='402.992152' y='518.073095' xlink:href='#g1-101'/>
|
||||
<use x='408.417592' y='519.866358' xlink:href='#g2-49'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M394.818 205.287L189.874 86.9619' fill='none' stroke='#c26a17' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10.0375' stroke-width='0.752812'/>
|
||||
</g>
|
||||
<g fill='#c16a17'>
|
||||
<use x='335.275432' y='462.62207' xlink:href='#g1-101'/>
|
||||
<use x='340.700872' y='464.415333' xlink:href='#g2-50'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M213.019 208.818V48.6126' fill='none' stroke='#1f5c99' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10.0375' stroke-width='0.752812'/>
|
||||
</g>
|
||||
<g fill='#1f5c98'>
|
||||
<use x='253.39509' y='431.70318' xlink:href='#g1-101'/>
|
||||
<use x='258.82053' y='433.496443' xlink:href='#g2-51'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M189.874 170.469L394.818 52.1439' fill='none' stroke='#c26a17' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10.0375' stroke-width='0.752812'/>
|
||||
</g>
|
||||
<g fill='#c16a17'>
|
||||
<use x='335.275432' y='400.784275' xlink:href='#g1-101'/>
|
||||
<use x='340.700872' y='402.577538' xlink:href='#g2-52'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M277.715 11.2605L416.457 91.3631' fill='none' stroke='#1f5c99' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10.0375' stroke-width='0.752812'/>
|
||||
</g>
|
||||
<g fill='#1f5c98'>
|
||||
<use x='402.992152' y='345.333266' xlink:href='#g1-101'/>
|
||||
<use x='408.417592' y='347.126529' xlink:href='#g2-53'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M371.672 191.924L322.499 220.314L213.019 157.106V100.325L322.499 37.1166L371.672 65.5069V191.924Z' fill='none' stroke='#231f20' stroke-dasharray='2.64227,1.58536' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10.0375' stroke-width='0.526969'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M322.499 93.8973V163.533L262.192 128.715L322.499 93.8973Z' fill='#f2d4d0'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M322.499 93.8973V163.533L262.192 128.715L322.499 93.8973Z' fill='none' stroke='#a8322a' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10.0375' stroke-width='0.752812'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M327.618 128.715C327.618 114.786 316.326 103.494 302.397 103.494S277.176 114.786 277.176 128.715S288.468 153.936 302.397 153.936S327.618 142.644 327.618 128.715Z' fill='none' stroke='#8c8c8c' stroke-dasharray='1.50942,1.13207' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10.0375' stroke-width='0.376406'/>
|
||||
</g>
|
||||
<g fill='#737373'>
|
||||
<use x='352.15163' y='402.696887' xlink:href='#g5-49'/>
|
||||
<use x='356.12287' y='402.696887' xlink:href='#g5-48'/>
|
||||
<use x='360.094111' y='399.69037' xlink:href='#g4-14'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M354.457 128.715C354.457 99.9631 331.149 76.655 302.397 76.655S250.337 99.9631 250.337 128.715C250.337 157.467 273.645 180.775 302.397 180.775S354.457 157.467 354.457 128.715Z' fill='none' stroke='#8c8c8c' stroke-dasharray='1.5076,1.1307' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10.0375' stroke-width='0.376406'/>
|
||||
</g>
|
||||
<g fill='#737373'>
|
||||
<use x='352.15163' y='375.957727' xlink:href='#g5-50'/>
|
||||
<use x='356.12287' y='375.957727' xlink:href='#g5-48'/>
|
||||
<use x='360.094111' y='372.95121' xlink:href='#g4-14'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M384.978 128.715C384.978 83.107 348.005 46.1343 302.397 46.1343S219.816 83.107 219.816 128.715S256.789 211.296 302.397 211.296S384.978 174.323 384.978 128.715Z' fill='none' stroke='#8c8c8c' stroke-dasharray='1.50528,1.12896' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10.0375' stroke-width='0.376406'/>
|
||||
</g>
|
||||
<g fill='#737373'>
|
||||
<use x='352.15163' y='345.551077' xlink:href='#g5-51'/>
|
||||
<use x='356.12287' y='345.551077' xlink:href='#g5-48'/>
|
||||
<use x='360.094111' y='342.544559' xlink:href='#g4-14'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M422.417 128.715C422.417 62.43 368.682 8.69514 302.397 8.69514S182.377 62.43 182.377 128.715S236.112 248.735 302.397 248.735S422.417 195 422.417 128.715Z' fill='none' stroke='#999999' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10.0375' stroke-width='0.376406'/>
|
||||
</g>
|
||||
<g fill='#737373'>
|
||||
<use x='352.15163' y='308.251786' xlink:href='#g5-52'/>
|
||||
<use x='356.12287' y='308.251786' xlink:href='#g5-48'/>
|
||||
<use x='360.094111' y='305.245269' xlink:href='#g4-14'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<circle cx='322.499' cy='220.314' fill='#231f20' r='1.31742'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<circle cx='371.672' cy='191.924' fill='#231f20' r='1.31742'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<circle cx='213.019' cy='100.325' fill='#231f20' r='1.31742'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<circle cx='213.019' cy='157.106' fill='#231f20' r='1.31742'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<circle cx='371.672' cy='65.5069' fill='#231f20' r='1.31742'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<circle cx='322.499' cy='37.1166' fill='#231f20' r='1.31742'/>
|
||||
</g>
|
||||
<g fill='#231f20'>
|
||||
<use x='428.976923' y='491.24353' xlink:href='#g2-102'/>
|
||||
<use x='431.564479' y='491.24353' xlink:href='#g2-97'/>
|
||||
<use x='435.798662' y='491.24353' xlink:href='#g2-99'/>
|
||||
<use x='439.56238' y='491.24353' xlink:href='#g2-101'/>
|
||||
<use x='446.148887' y='491.24353' xlink:href='#g2-110'/>
|
||||
<use x='450.853534' y='491.24353' xlink:href='#g2-111'/>
|
||||
<use x='455.087717' y='491.24353' xlink:href='#g2-114'/>
|
||||
<use x='458.387887' y='491.24353' xlink:href='#g2-109'/>
|
||||
<use x='465.444859' y='491.24353' xlink:href='#g2-97'/>
|
||||
<use x='469.679042' y='491.24353' xlink:href='#g2-108'/>
|
||||
<use x='472.031366' y='491.24353' xlink:href='#g2-115'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<circle cx='302.397' cy='128.715' fill='#231f20' r='0.941016'/>
|
||||
</g>
|
||||
<g fill='#231f20'>
|
||||
<use x='347.041262' y='435.212512' xlink:href='#g2-117'/>
|
||||
<use x='351.74591' y='435.212512' xlink:href='#g2-112'/>
|
||||
<use x='333.494802' y='567.552221' xlink:href='#g3-84'/>
|
||||
<use x='340.973622' y='567.552221' xlink:href='#g3-111'/>
|
||||
<use x='346.826613' y='567.552221' xlink:href='#g3-112'/>
|
||||
<use x='357.231929' y='567.552221' xlink:href='#g3-86'/>
|
||||
<use x='366.007275' y='567.552221' xlink:href='#g3-105'/>
|
||||
<use x='369.258937' y='567.552221' xlink:href='#g3-101'/>
|
||||
<use x='374.461595' y='567.552221' xlink:href='#g3-119'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M.526969 279.036H14.0776' fill='none' stroke='#c26a17' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10.0375' stroke-width='1.05394'/>
|
||||
</g>
|
||||
<g fill='#231f20'>
|
||||
<use x='76.444899' y='581.842049' xlink:href='#g2-114'/>
|
||||
<use x='79.745069' y='581.842049' xlink:href='#g2-105'/>
|
||||
<use x='82.097393' y='581.842049' xlink:href='#g2-100'/>
|
||||
<use x='86.802041' y='581.842049' xlink:href='#g2-103'/>
|
||||
<use x='91.036223' y='581.842049' xlink:href='#g2-101'/>
|
||||
<use x='97.62273' y='581.842049' xlink:href='#g2-115'/>
|
||||
<use x='100.963033' y='581.842049' xlink:href='#g2-112'/>
|
||||
<use x='105.902913' y='581.842049' xlink:href='#g2-111'/>
|
||||
<use x='110.137096' y='581.842049' xlink:href='#g2-107'/>
|
||||
<use x='114.371279' y='581.842049' xlink:href='#g2-101'/>
|
||||
<use x='118.134997' y='581.842049' xlink:href='#g2-44'/>
|
||||
<use x='123.310109' y='581.842049' xlink:href='#g2-56'/>
|
||||
<use x='127.544292' y='579.029263' xlink:href='#g0-14'/>
|
||||
<use x='134.684204' y='581.842049' xlink:href='#g2-100'/>
|
||||
<use x='139.388852' y='581.842049' xlink:href='#g2-114'/>
|
||||
<use x='142.689022' y='581.842049' xlink:href='#g2-111'/>
|
||||
<use x='146.923205' y='581.842049' xlink:href='#g2-112'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M113.449 279.036H126.999' fill='none' stroke='#1f5c99' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10.0375' stroke-width='1.05394'/>
|
||||
</g>
|
||||
<g fill='#231f20'>
|
||||
<use x='188.944899' y='581.842049' xlink:href='#g2-103'/>
|
||||
<use x='193.179082' y='581.842049' xlink:href='#g2-117'/>
|
||||
<use x='197.883729' y='581.842049' xlink:href='#g2-108'/>
|
||||
<use x='200.236053' y='581.842049' xlink:href='#g2-108'/>
|
||||
<use x='202.588377' y='581.842049' xlink:href='#g2-121'/>
|
||||
<use x='209.880581' y='581.842049' xlink:href='#g2-115'/>
|
||||
<use x='213.220884' y='581.842049' xlink:href='#g2-112'/>
|
||||
<use x='218.160764' y='581.842049' xlink:href='#g2-111'/>
|
||||
<use x='222.394947' y='581.842049' xlink:href='#g2-107'/>
|
||||
<use x='226.629129' y='581.842049' xlink:href='#g2-101'/>
|
||||
<use x='230.392848' y='581.842049' xlink:href='#g2-44'/>
|
||||
<use x='235.56796' y='581.842049' xlink:href='#g2-51'/>
|
||||
<use x='239.802143' y='581.842049' xlink:href='#g2-50'/>
|
||||
<use x='244.036326' y='579.029263' xlink:href='#g0-14'/>
|
||||
<use x='251.176238' y='581.842049' xlink:href='#g2-100'/>
|
||||
<use x='255.880886' y='581.842049' xlink:href='#g2-114'/>
|
||||
<use x='259.181056' y='581.842049' xlink:href='#g2-111'/>
|
||||
<use x='263.415239' y='581.842049' xlink:href='#g2-112'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M226.371 282.8H233.899V275.272H226.371V282.8Z' fill='#f2d4d0'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M226.371 282.8H233.899V275.272H226.371V282.8Z' fill='none' stroke='#a8322a' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10.0375' stroke-width='0.752812'/>
|
||||
</g>
|
||||
<g fill='#231f20'>
|
||||
<use x='295.444892' y='581.682947' xlink:href='#g2-118'/>
|
||||
<use x='299.679075' y='581.682947' xlink:href='#g2-101'/>
|
||||
<use x='303.442793' y='581.682947' xlink:href='#g2-114'/>
|
||||
<use x='306.742963' y='581.682947' xlink:href='#g2-116'/>
|
||||
<use x='310.036217' y='581.682947' xlink:href='#g2-101'/>
|
||||
<use x='313.799935' y='581.682947' xlink:href='#g2-120'/>
|
||||
<use x='321.092139' y='581.682947' xlink:href='#g2-114'/>
|
||||
<use x='324.392309' y='581.682947' xlink:href='#g2-101'/>
|
||||
<use x='328.156027' y='581.682947' xlink:href='#g2-103'/>
|
||||
<use x='332.39021' y='581.682947' xlink:href='#g2-105'/>
|
||||
<use x='334.742533' y='581.682947' xlink:href='#g2-111'/>
|
||||
<use x='338.976716' y='581.682947' xlink:href='#g2-110'/>
|
||||
</g>
|
||||
<g transform='translate(56.9344 301.852)scale(.996264)'>
|
||||
<path d='M309.18 279.036H322.731' fill='none' stroke='#231f20' stroke-dasharray='2.33631,1.40179' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10.0375' stroke-width='0.526969'/>
|
||||
</g>
|
||||
<g fill='#231f20'>
|
||||
<use x='383.944896' y='582.552747' xlink:href='#g2-99'/>
|
||||
<use x='387.708614' y='582.552747' xlink:href='#g2-111'/>
|
||||
<use x='391.942797' y='582.552747' xlink:href='#g2-110'/>
|
||||
<use x='396.647445' y='582.552747' xlink:href='#g2-101'/>
|
||||
<use x='403.233951' y='582.552747' xlink:href='#g2-111'/>
|
||||
<use x='407.468134' y='582.552747' xlink:href='#g2-102'/>
|
||||
<use x='412.878479' y='582.552747' xlink:href='#g2-102'/>
|
||||
<use x='415.466035' y='582.552747' xlink:href='#g2-97'/>
|
||||
<use x='419.700218' y='582.552747' xlink:href='#g2-99'/>
|
||||
<use x='423.463936' y='582.552747' xlink:href='#g2-101'/>
|
||||
<use x='430.050443' y='582.552747' xlink:href='#g2-110'/>
|
||||
<use x='434.75509' y='582.552747' xlink:href='#g2-111'/>
|
||||
<use x='438.989273' y='582.552747' xlink:href='#g2-114'/>
|
||||
<use x='442.289443' y='582.552747' xlink:href='#g2-109'/>
|
||||
<use x='449.346415' y='582.552747' xlink:href='#g2-97'/>
|
||||
<use x='453.580597' y='582.552747' xlink:href='#g2-108'/>
|
||||
<use x='455.932921' y='582.552747' xlink:href='#g2-115'/>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 75 KiB |
323
docs/images/vertex_regions.asy
Normal file
323
docs/images/vertex_regions.asy
Normal file
|
|
@ -0,0 +1,323 @@
|
|||
settings.outformat = "svg";
|
||||
settings.render = 0;
|
||||
settings.prc = false;
|
||||
|
||||
import three;
|
||||
|
||||
real px = 0.75bp;
|
||||
|
||||
pen ink = rgb("231f20");
|
||||
pen meshPen = ink + 0.6px;
|
||||
// Half opacity over white matches the opaque f2d4d0 of the other figures
|
||||
pen regionFill = rgb("e5a9a1") + opacity(0.5);
|
||||
pen regionShade = rgb("7a1f18");
|
||||
pen regionPen = rgb("a8322a") + 0.9px;
|
||||
pen rayPen = rgb("a8322a") + 0.6px;
|
||||
pen spokePen = rgb("1f5c99") + 1.0px;
|
||||
pen cliffFill = gray(0.88) + opacity(0.6);
|
||||
pen guidePen = gray(0.45) + 0.6px + linetype(new real[] {4, 3});
|
||||
|
||||
real panelSize = 170px;
|
||||
real capRadius = 0.55;
|
||||
real arrowSize = 5px;
|
||||
|
||||
triple lightDirection = unit((1, 4, 2));
|
||||
|
||||
// Extreme rays of the cone of normals n with n . d <= 0 for every direction d
|
||||
triple[] RegionRays(triple[] d)
|
||||
{
|
||||
triple[] rays;
|
||||
for (int i = 0; i < d.length; ++i)
|
||||
{
|
||||
for (int j = i + 1; j < d.length; ++j)
|
||||
{
|
||||
triple c = cross(d[i], d[j]);
|
||||
if (abs(c) < 1e-6)
|
||||
continue;
|
||||
|
||||
for (real s : new real[] {1, -1})
|
||||
{
|
||||
triple r = s * unit(c);
|
||||
bool inside = true;
|
||||
for (triple e : d)
|
||||
inside = inside && dot(r, unit(e)) <= 1e-6;
|
||||
|
||||
bool duplicate = false;
|
||||
for (triple q : rays)
|
||||
duplicate = duplicate || dot(r, q) > 1 - 1e-6;
|
||||
|
||||
if (inside && !duplicate)
|
||||
rays.push(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
triple axis = (0, 0, 0);
|
||||
for (triple r : rays)
|
||||
axis += r;
|
||||
axis = unit(axis);
|
||||
|
||||
triple t1 = unit(cross(axis, abs(axis.x) < 0.9 ? X : Y));
|
||||
triple t2 = cross(axis, t1);
|
||||
real[] angles;
|
||||
for (triple r : rays)
|
||||
angles.push(atan2(dot(r, t2), dot(r, t1)));
|
||||
|
||||
int[] order = sequence(rays.length);
|
||||
order = sort(order, new bool(int a, int b) { return angles[a] < angles[b]; });
|
||||
triple[] sorted;
|
||||
for (int k : order)
|
||||
sorted.push(rays[k]);
|
||||
return sorted;
|
||||
}
|
||||
|
||||
triple Arc(triple a, triple b, real t)
|
||||
{
|
||||
return unit((1 - t) * a + t * b);
|
||||
}
|
||||
|
||||
// Extreme rays of the region, drawn as arrows leaving the rim
|
||||
void DrawRayTips(picture pic, triple v, triple[] rays, real radius)
|
||||
{
|
||||
for (triple r : rays)
|
||||
draw(pic, (v + radius * r) -- (v + (radius + 0.3) * r), regionPen, Arrow3(arrowSize));
|
||||
}
|
||||
|
||||
// Convex hull by monotone chain
|
||||
pair[] ConvexHull(pair[] points)
|
||||
{
|
||||
pair[] p = sort(points, new bool(pair a, pair b) { return a.x < b.x || (a.x == b.x && a.y < b.y); });
|
||||
pair[] hull;
|
||||
for (int pass = 0; pass < 2; ++pass)
|
||||
{
|
||||
int base = hull.length;
|
||||
for (pair q : p)
|
||||
{
|
||||
while (hull.length >= base + 2 && cross(hull[hull.length - 1] - hull[hull.length - 2], q - hull[hull.length - 2]) <= 0)
|
||||
hull.pop();
|
||||
hull.push(q);
|
||||
}
|
||||
hull.pop();
|
||||
p = reverse(p);
|
||||
}
|
||||
return hull;
|
||||
}
|
||||
|
||||
// The region is convex, so its outline is the hull of its projected points. Filling that once
|
||||
// avoids the seams that overlapping translucent patches would show.
|
||||
void FillProjected(picture pic, triple v, triple[] points)
|
||||
{
|
||||
triple view = unit(currentprojection.camera - currentprojection.target);
|
||||
triple u1 = unit(cross(currentprojection.up, view));
|
||||
triple u2 = cross(view, u1);
|
||||
|
||||
pair[] flat;
|
||||
for (triple q : points)
|
||||
flat.push((dot(q - v, u1), dot(q - v, u2)));
|
||||
|
||||
pair[] hull = ConvexHull(flat);
|
||||
path3 outline = v + hull[0].x * u1 + hull[0].y * u2;
|
||||
for (int k = 1; k < hull.length; ++k)
|
||||
outline = outline -- (v + hull[k].x * u1 + hull[k].y * u2);
|
||||
draw(pic, surface(outline -- cycle, planar = true), regionFill, nolight);
|
||||
}
|
||||
|
||||
void DrawRegion(picture pic, triple v, triple[] rays, real radius)
|
||||
{
|
||||
int arcSteps = 12;
|
||||
int n = rays.length;
|
||||
|
||||
triple axis = (0, 0, 0);
|
||||
for (triple r : rays)
|
||||
axis += r;
|
||||
axis = unit(axis);
|
||||
|
||||
triple[] points = { v };
|
||||
path3 rim;
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
if (n == 2 && i == 1)
|
||||
break;
|
||||
|
||||
triple a = rays[i];
|
||||
triple b = rays[(i + 1) % n];
|
||||
for (int k = 0; k <= arcSteps; ++k)
|
||||
{
|
||||
triple p = v + radius * Arc(a, b, k / arcSteps);
|
||||
rim = i == 0 && k == 0 ? p : rim -- p;
|
||||
points.push(p);
|
||||
|
||||
// Interior points for the silhouette of the spherical cap
|
||||
for (int j = 1; j < 6 && n > 2; ++j)
|
||||
points.push(v + radius * Arc(axis, Arc(a, b, k / arcSteps), j / 6));
|
||||
}
|
||||
}
|
||||
|
||||
FillProjected(pic, v, points);
|
||||
|
||||
// Darken the flat sides with the same light as the mesh. Sides on the near half of the cone never
|
||||
// overlap each other in projection, nor do sides on the far half, so each adds one layer.
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
if (n == 2 && i == 1)
|
||||
break;
|
||||
|
||||
triple a = rays[i];
|
||||
triple b = rays[(i + 1) % n];
|
||||
triple side = unit(cross(a, b));
|
||||
|
||||
path3 sector = v + radius * a;
|
||||
for (int k = 1; k <= arcSteps; ++k)
|
||||
sector = sector -- (v + radius * Arc(a, b, k / arcSteps));
|
||||
sector = v -- sector -- cycle;
|
||||
|
||||
real shade = 1 - abs(dot(side, lightDirection));
|
||||
draw(pic, surface(sector, planar = true), regionShade + opacity(0.35 * shade), nolight);
|
||||
}
|
||||
|
||||
draw(pic, n == 2 ? rim : rim -- cycle, regionPen);
|
||||
for (triple r : rays)
|
||||
draw(pic, v -- (v + radius * r), rayPen);
|
||||
DrawRayTips(pic, v, rays, radius);
|
||||
}
|
||||
|
||||
// Flat shading in world space, so every panel is lit the same way
|
||||
pen Shade(path3 face)
|
||||
{
|
||||
triple n = unit(cross(point(face, 1) - point(face, 0), point(face, 2) - point(face, 0)));
|
||||
real k = 0.74 + 0.26 * abs(dot(n, lightDirection));
|
||||
return rgb(k * 0.843, k * 0.890, k * 0.957);
|
||||
}
|
||||
|
||||
void DrawFan(picture pic, triple v, triple[] rim, bool closed)
|
||||
{
|
||||
int count = closed ? rim.length : rim.length - 1;
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
path3 t = v -- rim[i] -- rim[(i + 1) % rim.length] -- cycle;
|
||||
draw(pic, surface(t), Shade(t), nolight);
|
||||
draw(pic, t, meshPen);
|
||||
}
|
||||
}
|
||||
|
||||
void DrawSpokes(picture pic, triple v, triple[] ends)
|
||||
{
|
||||
for (triple e : ends)
|
||||
draw(pic, v -- (v + 0.45 * (e - v)), spokePen, Arrow3(arrowSize));
|
||||
}
|
||||
|
||||
frame[] panels;
|
||||
string[] titles;
|
||||
|
||||
// Box corner, three faces meet at a convex vertex
|
||||
{
|
||||
currentprojection = orthographic((3.5, 2.6, 2.8), up = Y);
|
||||
picture pic;
|
||||
size(pic, panelSize, panelSize);
|
||||
triple v = (0, 0, 0);
|
||||
|
||||
path3[] faces = {
|
||||
(0, 0, 0) -- (0, -1, 0) -- (0, -1, -1) -- (0, 0, -1) -- cycle,
|
||||
(0, 0, 0) -- (0, 0, -1) -- (-1, 0, -1) -- (-1, 0, 0) -- cycle,
|
||||
(0, 0, 0) -- (-1, 0, 0) -- (-1, -1, 0) -- (0, -1, 0) -- cycle,
|
||||
};
|
||||
for (path3 f : faces)
|
||||
{
|
||||
draw(pic, surface(f), Shade(f), nolight);
|
||||
draw(pic, f, meshPen);
|
||||
}
|
||||
|
||||
triple[] ends = { (-1, 0, 0), (0, -1, 0), (0, 0, -1) };
|
||||
DrawSpokes(pic, v, ends);
|
||||
DrawRegion(pic, v, RegionRays(ends), capRadius);
|
||||
dot(pic, v, ink + 3px);
|
||||
|
||||
panels.push(pic.fit());
|
||||
titles.push("convex corner");
|
||||
}
|
||||
|
||||
// A vertex on a ridge, the region collapses to a flat wedge
|
||||
{
|
||||
currentprojection = orthographic((3.0, 2.4, 2.2), up = Y);
|
||||
picture pic;
|
||||
size(pic, panelSize, panelSize);
|
||||
triple v = (0, 0, 0);
|
||||
real h = tan(30 * pi / 180);
|
||||
|
||||
triple[] rim = { (1, 0, 0), (1, -h, 1), (-1, -h, 1), (-1, 0, 0), (-1, -h, -1), (1, -h, -1) };
|
||||
DrawFan(pic, v, rim, true);
|
||||
DrawSpokes(pic, v, rim);
|
||||
DrawRegion(pic, v, RegionRays(rim), capRadius);
|
||||
dot(pic, v, ink + 3px);
|
||||
|
||||
panels.push(pic.fit());
|
||||
titles.push("ridge");
|
||||
}
|
||||
|
||||
// Saddle hub, spokes alternate 8 degree ridges and 32 degree gullies
|
||||
{
|
||||
currentprojection = orthographic((2.0, 4.0, 3.0), up = Y);
|
||||
picture pic;
|
||||
size(pic, panelSize, panelSize);
|
||||
triple v = (0, 0, 0);
|
||||
|
||||
triple[] rim;
|
||||
for (int i = 0; i < 6; ++i)
|
||||
{
|
||||
real angle = i * 60;
|
||||
real drop = i % 2 == 1 ? 32 : 8;
|
||||
rim.push((Cos(angle), -Tan(drop), Sin(angle)));
|
||||
}
|
||||
|
||||
DrawFan(pic, v, rim, true);
|
||||
DrawSpokes(pic, v, rim);
|
||||
DrawRegion(pic, v, RegionRays(rim), 1.2);
|
||||
dot(pic, v, ink + 3px);
|
||||
|
||||
panels.push(pic.fit());
|
||||
titles.push("saddle hub");
|
||||
}
|
||||
|
||||
// Corner of an open sheet, the cliffs below the boundary edges close the region
|
||||
{
|
||||
currentprojection = orthographic((3.5, 2.6, 2.8), up = Y);
|
||||
picture pic;
|
||||
size(pic, panelSize, panelSize);
|
||||
triple v = (0, 0, 0);
|
||||
real depth = 0.6;
|
||||
|
||||
path3[] cliffs = {
|
||||
(0, 0, 0) -- (0, 0, -1) -- (0, -depth, -1) -- (0, -depth, 0) -- cycle,
|
||||
(0, 0, 0) -- (-1, 0, 0) -- (-1, -depth, 0) -- (0, -depth, 0) -- cycle,
|
||||
};
|
||||
for (path3 c : cliffs)
|
||||
{
|
||||
draw(pic, surface(c), cliffFill, nolight);
|
||||
draw(pic, c, guidePen);
|
||||
}
|
||||
|
||||
triple[] rim = { (-1, 0, 0), (-1, 0, -1), (0, 0, -1) };
|
||||
DrawFan(pic, v, rim, false);
|
||||
DrawSpokes(pic, v, rim);
|
||||
|
||||
triple[] directions = copy(rim);
|
||||
directions.push((0, -1, 0));
|
||||
DrawRegion(pic, v, RegionRays(directions), capRadius);
|
||||
dot(pic, v, ink + 3px);
|
||||
label(pic, "cliff", (0, -depth, -0.5), S, gray(0.35));
|
||||
|
||||
panels.push(pic.fit());
|
||||
titles.push("open corner");
|
||||
}
|
||||
|
||||
real gap = 24px;
|
||||
real x = 0;
|
||||
for (int i = 0; i < panels.length; ++i)
|
||||
{
|
||||
frame f = panels[i];
|
||||
pair lo = min(f);
|
||||
pair hi = max(f);
|
||||
add(shift(x - lo.x, -lo.y) * f);
|
||||
label(titles[i], (x + 0.5 * (hi.x - lo.x), -8px), S, ink);
|
||||
x += hi.x - lo.x + gap;
|
||||
}
|
||||
1050
docs/images/vertex_regions.svg
Normal file
1050
docs/images/vertex_regions.svg
Normal file
File diff suppressed because it is too large
Load diff
|
After Width: | Height: | Size: 104 KiB |
|
|
@ -80,14 +80,13 @@ B3_API b3ContactEvents b3World_GetContactEvents( b3WorldId worldId );
|
|||
B3_API b3JointEvents b3World_GetJointEvents( b3WorldId worldId );
|
||||
|
||||
/// Overlap test for all shapes that *potentially* overlap the provided AABB
|
||||
B3_API b3TreeStats b3World_OverlapAABB( b3WorldId worldId, b3AABB aabb, b3QueryFilter filter,
|
||||
b3OverlapResultFcn* fcn, void* context );
|
||||
B3_API b3TreeStats b3World_OverlapAABB( b3WorldId worldId, b3AABB aabb, b3QueryFilter filter, b3OverlapResultFcn* fcn,
|
||||
void* context );
|
||||
|
||||
/// Overlap test for all shapes that overlap the provided shape proxy. The proxy points are relative
|
||||
/// to the world origin, which lets the query stay precise far from the world origin.
|
||||
B3_API b3TreeStats b3World_OverlapShape( b3WorldId worldId, b3Pos origin, const b3ShapeProxy* proxy,
|
||||
b3QueryFilter filter, b3OverlapResultFcn* fcn,
|
||||
void* context );
|
||||
b3QueryFilter filter, b3OverlapResultFcn* fcn, void* context );
|
||||
|
||||
/// Cast a ray into the world to collect shapes in the path of the ray.
|
||||
/// Your callback function controls whether you get the closest point, any point, or n-points.
|
||||
|
|
@ -100,23 +99,21 @@ B3_API b3TreeStats b3World_OverlapShape( b3WorldId worldId, b3Pos origin, const
|
|||
/// @param fcn A user implemented callback function
|
||||
/// @param context A user context that is passed along to the callback function
|
||||
/// @return traversal performance counters
|
||||
B3_API b3TreeStats b3World_CastRay( b3WorldId worldId, b3Pos origin, b3Vec3 translation,
|
||||
b3QueryFilter filter, b3CastResultFcn* fcn, void* context );
|
||||
B3_API b3TreeStats b3World_CastRay( b3WorldId worldId, b3Pos origin, b3Vec3 translation, b3QueryFilter filter,
|
||||
b3CastResultFcn* fcn, void* context );
|
||||
|
||||
/// Cast a ray into the world to collect the closest hit. This is a convenience function. Ignores
|
||||
/// initial overlap. This is less general than b3World_CastRay() and does not allow for custom
|
||||
/// filtering. Ignores back-side collision on meshes and height-fields.
|
||||
B3_API b3RayResult b3World_CastRayClosest( b3WorldId worldId, b3Pos origin, b3Vec3 translation,
|
||||
b3QueryFilter filter );
|
||||
B3_API b3RayResult b3World_CastRayClosest( b3WorldId worldId, b3Pos origin, b3Vec3 translation, b3QueryFilter filter );
|
||||
|
||||
/// Cast a shape through the world. Similar to a cast ray except that a shape is cast instead of a
|
||||
/// point. The proxy points are relative to the origin and the hit points come back as world
|
||||
/// positions, so the cast stays precise far from the world origin. Ignores back-side collision on
|
||||
/// meshes and height-fields.
|
||||
/// @see b3World_CastRay
|
||||
B3_API b3TreeStats b3World_CastShape( b3WorldId worldId, b3Pos origin, const b3ShapeProxy* proxy,
|
||||
b3Vec3 translation, b3QueryFilter filter,
|
||||
b3CastResultFcn* fcn, void* context );
|
||||
B3_API b3TreeStats b3World_CastShape( b3WorldId worldId, b3Pos origin, const b3ShapeProxy* proxy, b3Vec3 translation,
|
||||
b3QueryFilter filter, b3CastResultFcn* fcn, void* context );
|
||||
|
||||
/// Cast a capsule mover through the world. This is a special shape cast that handles sliding along
|
||||
/// other shapes while reducing clipping. This is not a good source of information about what the
|
||||
|
|
@ -130,15 +127,14 @@ B3_API b3TreeStats b3World_CastShape( b3WorldId worldId, b3Pos origin, const b3S
|
|||
/// @param fcn Optional callback for custom shape filtering
|
||||
/// @param context A user context that is passed along to the callback function
|
||||
/// @return the translation fraction
|
||||
B3_API float b3World_CastMover( b3WorldId worldId, b3Pos origin, const b3Capsule* mover,
|
||||
b3Vec3 translation, b3QueryFilter filter, b3MoverFilterFcn* fcn,
|
||||
void* context );
|
||||
B3_API float b3World_CastMover( b3WorldId worldId, b3Pos origin, const b3Capsule* mover, b3Vec3 translation,
|
||||
b3QueryFilter filter, b3MoverFilterFcn* fcn, void* context );
|
||||
|
||||
/// Collide a capsule mover with the world, gathering collision planes that can be fed to
|
||||
/// b3SolvePlanes. Useful for kinematic character movement. The mover and the returned planes are
|
||||
/// relative to the origin. Ignores back-side collision on meshes and height-fields.
|
||||
B3_API void b3World_CollideMover( b3WorldId worldId, b3Pos origin, const b3Capsule* mover,
|
||||
b3QueryFilter filter, b3PlaneResultFcn* fcn, void* context );
|
||||
B3_API void b3World_CollideMover( b3WorldId worldId, b3Pos origin, const b3Capsule* mover, b3QueryFilter filter,
|
||||
b3PlaneResultFcn* fcn, void* context );
|
||||
|
||||
/// Enable/disable sleep. If your application does not need sleeping, you can gain some performance
|
||||
/// by disabling sleep completely at the world level.
|
||||
|
|
@ -187,8 +183,7 @@ B3_API void b3World_SetHitEventThreshold( b3WorldId worldId, float value );
|
|||
B3_API float b3World_GetHitEventThreshold( b3WorldId worldId );
|
||||
|
||||
/// Register the custom filter callback. This is optional.
|
||||
B3_API void b3World_SetCustomFilterCallback( b3WorldId worldId, b3CustomFilterFcn* fcn,
|
||||
void* context );
|
||||
B3_API void b3World_SetCustomFilterCallback( b3WorldId worldId, b3CustomFilterFcn* fcn, void* context );
|
||||
|
||||
/// Register the pre-solve callback. This is optional.
|
||||
B3_API void b3World_SetPreSolveCallback( b3WorldId worldId, b3PreSolveFcn* fcn, void* context );
|
||||
|
|
@ -212,8 +207,7 @@ B3_API void b3World_Explode( b3WorldId worldId, const b3ExplosionDef* explosionD
|
|||
/// @param dampingRatio The contact bounciness with 1 being critical damping (non-dimensional)
|
||||
/// @param contactSpeed The maximum contact constraint push out speed (meters per second)
|
||||
/// @note Advanced feature
|
||||
B3_API void b3World_SetContactTuning( b3WorldId worldId, float hertz, float dampingRatio,
|
||||
float contactSpeed );
|
||||
B3_API void b3World_SetContactTuning( b3WorldId worldId, float hertz, float dampingRatio, float contactSpeed );
|
||||
|
||||
/// Set the contact point recycling distance. Setting this to zero disables contact point recycling.
|
||||
/// Usually in meters.
|
||||
|
|
@ -421,8 +415,7 @@ B3_API void b3RecPlayer_SetWorkerCount( b3RecPlayer* player, int count );
|
|||
/// @param minIntervalFrames finest spacing between keyframes, in frames
|
||||
/// A zero budget or a non-positive interval keeps that value. Clears the existing ring, so call
|
||||
/// b3RecPlayer_Restart afterward to repopulate it under the new policy.
|
||||
B3_API void b3RecPlayer_SetKeyframePolicy( b3RecPlayer* player, size_t budgetBytes,
|
||||
int minIntervalFrames );
|
||||
B3_API void b3RecPlayer_SetKeyframePolicy( b3RecPlayer* player, size_t budgetBytes, int minIntervalFrames );
|
||||
|
||||
/// @return the keyframe memory budget in bytes
|
||||
B3_API size_t b3RecPlayer_GetKeyframeBudget( const b3RecPlayer* player );
|
||||
|
|
@ -453,10 +446,8 @@ B3_API b3BodyId b3RecPlayer_GetBodyId( const b3RecPlayer* player, int index );
|
|||
/// @param createDebugShape called when a replayed shape is added; returns a user draw handle
|
||||
/// @param destroyDebugShape called when a replayed shape is removed; may be NULL
|
||||
/// @param context user context passed to both callbacks
|
||||
B3_API void b3RecPlayer_SetDebugShapeCallbacks( b3RecPlayer* player,
|
||||
b3CreateDebugShapeCallback* createDebugShape,
|
||||
b3DestroyDebugShapeCallback* destroyDebugShape,
|
||||
void* context );
|
||||
B3_API void b3RecPlayer_SetDebugShapeCallbacks( b3RecPlayer* player, b3CreateDebugShapeCallback* createDebugShape,
|
||||
b3DestroyDebugShapeCallback* destroyDebugShape, void* context );
|
||||
|
||||
/// Draw the spatial queries recorded during the most recently replayed frame, layered on top of the
|
||||
/// world. Call after b3World_Draw. NULL draw function pointers are skipped.
|
||||
|
|
@ -465,8 +456,7 @@ B3_API void b3RecPlayer_SetDebugShapeCallbacks( b3RecPlayer* player,
|
|||
/// @param queryIndex index of the frame query to draw, or -1 to draw all of them
|
||||
/// @param selectedIndex index of the query to emphasize (reserved color plus a label), or -1 for
|
||||
/// none
|
||||
B3_API void b3RecPlayer_DrawFrameQueries( b3RecPlayer* player, b3DebugDraw* draw, int queryIndex,
|
||||
int selectedIndex );
|
||||
B3_API void b3RecPlayer_DrawFrameQueries( b3RecPlayer* player, b3DebugDraw* draw, int queryIndex, int selectedIndex );
|
||||
|
||||
/// The kind of a recorded spatial query, matching the public query and cast functions.
|
||||
typedef enum b3RecQueryType
|
||||
|
|
@ -510,8 +500,7 @@ B3_API int b3RecPlayer_GetFrameQueryCount( const b3RecPlayer* player );
|
|||
B3_API b3RecQueryInfo b3RecPlayer_GetFrameQuery( const b3RecPlayer* player, int index );
|
||||
|
||||
/// Get one result of a recorded query from the most recently replayed frame.
|
||||
B3_API b3RecQueryHit b3RecPlayer_GetFrameQueryHit( const b3RecPlayer* player, int queryIndex,
|
||||
int hitIndex );
|
||||
B3_API b3RecQueryHit b3RecPlayer_GetFrameQueryHit( const b3RecPlayer* player, int queryIndex, int hitIndex );
|
||||
|
||||
/**@}*/ // recording
|
||||
|
||||
|
|
@ -601,8 +590,7 @@ B3_API void b3Body_SetAngularVelocity( b3BodyId bodyId, b3Vec3 angularVelocity )
|
|||
/// The result will be close but maybe not exact. This is meant for kinematic bodies.
|
||||
/// The target is not applied if the velocity would be below the sleep threshold.
|
||||
/// This will optionally wake the body if asleep, but only if the movement is significant.
|
||||
B3_API void b3Body_SetTargetTransform( b3BodyId bodyId, b3WorldTransform target, float timeStep,
|
||||
bool wake );
|
||||
B3_API void b3Body_SetTargetTransform( b3BodyId bodyId, b3WorldTransform target, float timeStep, bool wake );
|
||||
|
||||
/// Get the linear velocity of a local point attached to a body. Usually in meters per second.
|
||||
B3_API b3Vec3 b3Body_GetLocalPointVelocity( b3BodyId bodyId, b3Vec3 localPoint );
|
||||
|
|
@ -828,35 +816,30 @@ B3_API float b3Body_GetClosestPoint( b3BodyId bodyId, b3Vec3* result, b3Vec3 tar
|
|||
|
||||
/// Cast a ray at a specific body using a specified body transform.
|
||||
/// Ignores back-side collision on meshes and height-fields.
|
||||
B3_API b3BodyCastResult b3Body_CastRay( b3BodyId bodyId, b3Pos origin, b3Vec3 translation,
|
||||
b3QueryFilter filter, float maxFraction,
|
||||
b3WorldTransform bodyTransform );
|
||||
B3_API b3BodyCastResult b3Body_CastRay( b3BodyId bodyId, b3Pos origin, b3Vec3 translation, b3QueryFilter filter,
|
||||
float maxFraction, b3WorldTransform bodyTransform );
|
||||
|
||||
/// Cast a shape at a specific body using a specified body transform.
|
||||
/// Ignores back-side collision on meshes and height-fields.
|
||||
B3_API b3BodyCastResult b3Body_CastShape( b3BodyId bodyId, b3Pos origin, const b3ShapeProxy* proxy,
|
||||
b3Vec3 translation, b3QueryFilter filter,
|
||||
float maxFraction, bool canEncroach,
|
||||
B3_API b3BodyCastResult b3Body_CastShape( b3BodyId bodyId, b3Pos origin, const b3ShapeProxy* proxy, b3Vec3 translation,
|
||||
b3QueryFilter filter, float maxFraction, bool canEncroach,
|
||||
b3WorldTransform bodyTransform );
|
||||
|
||||
/// Overlap a shape with a specific body using a specified body transform.
|
||||
B3_API bool b3Body_OverlapShape( b3BodyId bodyId, b3Pos origin, const b3ShapeProxy* proxy,
|
||||
b3QueryFilter filter, b3WorldTransform bodyTransform );
|
||||
B3_API bool b3Body_OverlapShape( b3BodyId bodyId, b3Pos origin, const b3ShapeProxy* proxy, b3QueryFilter filter,
|
||||
b3WorldTransform bodyTransform );
|
||||
|
||||
/// Collide a character mover with a specific body using a specified body transform.
|
||||
/// Only considers convex shapes on the body.
|
||||
B3_API int b3Body_CollideMover( b3BodyId bodyId, b3BodyPlaneResult* bodyPlanes, int planeCapacity,
|
||||
b3Pos origin, const b3Capsule* mover, b3QueryFilter filter,
|
||||
b3WorldTransform bodyTransform );
|
||||
B3_API int b3Body_CollideMover( b3BodyId bodyId, b3BodyPlaneResult* bodyPlanes, int planeCapacity, b3Pos origin,
|
||||
const b3Capsule* mover, b3QueryFilter filter, b3WorldTransform bodyTransform );
|
||||
|
||||
/// Perform a time of impact between a character mover and a body using specified sweep transforms.
|
||||
/// Initial overlap of any shape on the body is ignored. A non-overlapped shape can still be hit.
|
||||
/// Only considers convex shapes on the body.
|
||||
B3_API b3BodyTOIResult b3Body_TimeOfImpactMover( b3BodyId bodyId, b3Pos origin,
|
||||
const b3Capsule* mover, b3Vec3 moverTranslation,
|
||||
b3QueryFilter filter,
|
||||
b3WorldTransform bodyTransform1,
|
||||
b3WorldTransform bodyTransform2 );
|
||||
B3_API b3BodyTOIResult b3Body_TimeOfImpactMover( b3BodyId bodyId, b3Pos origin, const b3Capsule* mover,
|
||||
b3Vec3 moverTranslation, b3QueryFilter filter,
|
||||
b3WorldTransform bodyTransform1, b3WorldTransform bodyTransform2 );
|
||||
|
||||
/** @} */ // body
|
||||
|
||||
|
|
@ -875,29 +858,25 @@ B3_API b3BodyTOIResult b3Body_TimeOfImpactMover( b3BodyId bodyId, b3Pos origin,
|
|||
/// Create a circle shape and attach it to a body. The shape definition and geometry are fully
|
||||
/// cloned. Contacts are not created until the next time step.
|
||||
/// @return the shape id for accessing the shape
|
||||
B3_API b3ShapeId b3CreateSphereShape( b3BodyId bodyId, const b3ShapeDef* def,
|
||||
const b3Sphere* sphere );
|
||||
B3_API b3ShapeId b3CreateSphereShape( b3BodyId bodyId, const b3ShapeDef* def, const b3Sphere* sphere );
|
||||
|
||||
/// Create a capsule shape and attach it to a body. The shape definition and geometry are fully
|
||||
/// cloned. Contacts are not created until the next time step.
|
||||
/// @return the shape id for accessing the shape
|
||||
B3_API b3ShapeId b3CreateCapsuleShape( b3BodyId bodyId, const b3ShapeDef* def,
|
||||
const b3Capsule* capsule );
|
||||
B3_API b3ShapeId b3CreateCapsuleShape( b3BodyId bodyId, const b3ShapeDef* def, const b3Capsule* capsule );
|
||||
|
||||
/// Create a convex hull shape and attach it to a body. The shape definition is fully cloned.
|
||||
/// Contacts are not created until the next time step.
|
||||
/// @return the shape id for accessing the shape
|
||||
B3_API b3ShapeId b3CreateHullShape( b3BodyId bodyId, const b3ShapeDef* def,
|
||||
const b3HullData* hull );
|
||||
B3_API b3ShapeId b3CreateHullShape( b3BodyId bodyId, const b3ShapeDef* def, const b3HullData* hull );
|
||||
|
||||
/// Create a convex hull shape and attach it to a body. The hull is cloned then transformed with
|
||||
/// scale applied first. Use this for non-uniform or mirrored scale or a baked local transform. The
|
||||
/// baked result is shared through the world hull database. The shape definition and geometry are
|
||||
/// fully cloned. Contacts are not created until the next time step.
|
||||
/// @return the shape id for accessing the shape
|
||||
B3_API b3ShapeId b3CreateTransformedHullShape( b3BodyId bodyId, const b3ShapeDef* def,
|
||||
const b3HullData* hull, b3Transform transform,
|
||||
b3Vec3 scale );
|
||||
B3_API b3ShapeId b3CreateTransformedHullShape( b3BodyId bodyId, const b3ShapeDef* def, const b3HullData* hull,
|
||||
b3Transform transform, b3Vec3 scale );
|
||||
|
||||
/// Create a mesh hull shape and attach it to a body. The shape definition is fully cloned but the
|
||||
/// mesh is not. Contacts are not created until the next time step. Mesh collision only creates
|
||||
|
|
@ -905,8 +884,7 @@ B3_API b3ShapeId b3CreateTransformedHullShape( b3BodyId bodyId, const b3ShapeDef
|
|||
/// @warning this holds reference to the input mesh data which must remain valid for the lifetime of
|
||||
/// this shape
|
||||
/// @return the shape id for accessing the shape
|
||||
B3_API b3ShapeId b3CreateMeshShape( b3BodyId bodyId, const b3ShapeDef* def, const b3MeshData* mesh,
|
||||
b3Vec3 scale );
|
||||
B3_API b3ShapeId b3CreateMeshShape( b3BodyId bodyId, const b3ShapeDef* def, const b3MeshData* mesh, b3Vec3 scale );
|
||||
|
||||
/// Create a height-field shape and attach it to a body. The shape definition is fully cloned but
|
||||
/// the height field is not. Contacts are not created until the next time step. Height field is only
|
||||
|
|
@ -920,8 +898,7 @@ B3_API b3ShapeId b3CreateHeightFieldShape( b3BodyId bodyId, const b3ShapeDef* de
|
|||
/// Baked compound shapes are only allowed on static bodies.
|
||||
/// Note: runtime compounds are achieved by adding multiple shapes to a body.
|
||||
/// Runtime compounds can be dynamic and/or kinematic.
|
||||
B3_API b3ShapeId b3CreateBakedCompoundShape( b3BodyId bodyId, b3ShapeDef* def,
|
||||
const b3CompoundData* compound );
|
||||
B3_API b3ShapeId b3CreateBakedCompoundShape( b3BodyId bodyId, b3ShapeDef* def, const b3CompoundData* compound );
|
||||
|
||||
/// Destroy a shape. You may defer the body mass update which can improve performance if several
|
||||
/// shapes on a
|
||||
|
|
@ -987,8 +964,7 @@ B3_API b3SurfaceMaterial b3Shape_GetSurfaceMaterial( b3ShapeId shapeId );
|
|||
B3_API int b3Shape_GetMeshMaterialCount( b3ShapeId shapeId );
|
||||
|
||||
/// Set a surface material for a mesh shape.
|
||||
B3_API void b3Shape_SetMeshMaterial( b3ShapeId shapeId, b3SurfaceMaterial surfaceMaterial,
|
||||
int index );
|
||||
B3_API void b3Shape_SetMeshMaterial( b3ShapeId shapeId, b3SurfaceMaterial surfaceMaterial, int index );
|
||||
|
||||
/// Get a surface material for a mesh shape
|
||||
B3_API b3SurfaceMaterial b3Shape_GetMeshSurfaceMaterial( b3ShapeId shapeId, int index );
|
||||
|
|
@ -1121,8 +1097,7 @@ B3_API b3Vec3 b3Shape_GetClosestPoint( b3ShapeId shapeId, b3Vec3 target );
|
|||
/// @param maxSpeed the maximum relative speed. Speed cap is necessary for stability. Typically
|
||||
/// 10m/s or less.
|
||||
/// @param wake should this wake the body
|
||||
B3_API void b3Shape_ApplyWind( b3ShapeId shapeId, b3Vec3 wind, float drag, float lift,
|
||||
float maxSpeed, bool wake );
|
||||
B3_API void b3Shape_ApplyWind( b3ShapeId shapeId, b3Vec3 wind, float drag, float lift, float maxSpeed, bool wake );
|
||||
|
||||
/** @} */ // shape
|
||||
|
||||
|
|
@ -1271,12 +1246,10 @@ B3_API void b3DistanceJoint_EnableSpring( b3JointId jointId, bool enableSpring )
|
|||
B3_API bool b3DistanceJoint_IsSpringEnabled( b3JointId jointId );
|
||||
|
||||
/// Set the force range for the spring.
|
||||
B3_API void b3DistanceJoint_SetSpringForceRange( b3JointId jointId, float lowerForce,
|
||||
float upperForce );
|
||||
B3_API void b3DistanceJoint_SetSpringForceRange( b3JointId jointId, float lowerForce, float upperForce );
|
||||
|
||||
/// Get the force range for the spring.
|
||||
B3_API void b3DistanceJoint_GetSpringForceRange( b3JointId jointId, float* lowerForce,
|
||||
float* upperForce );
|
||||
B3_API void b3DistanceJoint_GetSpringForceRange( b3JointId jointId, float* lowerForce, float* upperForce );
|
||||
|
||||
/// Set the spring stiffness in Hertz
|
||||
B3_API void b3DistanceJoint_SetSpringHertz( b3JointId jointId, float hertz );
|
||||
|
|
@ -1651,8 +1624,7 @@ B3_API float b3RevoluteJoint_GetLowerLimit( b3JointId jointId );
|
|||
B3_API float b3RevoluteJoint_GetUpperLimit( b3JointId jointId );
|
||||
|
||||
/// Set the revolute joint limits in radians
|
||||
B3_API void b3RevoluteJoint_SetLimits( b3JointId jointId, float lowerLimitRadians,
|
||||
float upperLimitRadians );
|
||||
B3_API void b3RevoluteJoint_SetLimits( b3JointId jointId, float lowerLimitRadians, float upperLimitRadians );
|
||||
|
||||
/// Enable/disable a revolute joint motor
|
||||
B3_API void b3RevoluteJoint_EnableMotor( b3JointId jointId, bool enableMotor );
|
||||
|
|
@ -1718,8 +1690,7 @@ B3_API float b3SphericalJoint_GetLowerTwistLimit( b3JointId jointId );
|
|||
B3_API float b3SphericalJoint_GetUpperTwistLimit( b3JointId jointId );
|
||||
|
||||
/// Set the spherical joint limits in radians
|
||||
B3_API void b3SphericalJoint_SetTwistLimits( b3JointId jointId, float lowerLimitRadians,
|
||||
float upperLimitRadians );
|
||||
B3_API void b3SphericalJoint_SetTwistLimits( b3JointId jointId, float lowerLimitRadians, float upperLimitRadians );
|
||||
|
||||
/// Get the spherical joint current twist angle in radians.
|
||||
B3_API float b3SphericalJoint_GetTwistAngle( b3JointId jointId );
|
||||
|
|
@ -1924,8 +1895,7 @@ B3_API float b3WheelJoint_GetLowerSteeringLimit( b3JointId jointId );
|
|||
B3_API float b3WheelJoint_GetUpperSteeringLimit( b3JointId jointId );
|
||||
|
||||
/// Set the wheel joint steering limits in radians.
|
||||
B3_API void b3WheelJoint_SetSteeringLimits( b3JointId jointId, float lowerRadians,
|
||||
float upperRadians );
|
||||
B3_API void b3WheelJoint_SetSteeringLimits( b3JointId jointId, float lowerRadians, float upperRadians );
|
||||
|
||||
/// Set the wheel joint target steering angle in radians.
|
||||
B3_API void b3WheelJoint_SetTargetSteeringAngle( b3JointId jointId, float radians );
|
||||
|
|
|
|||
|
|
@ -39,25 +39,28 @@ B3_API void b3DynamicTree_SetCategoryBits( b3DynamicTree* tree, int proxyId, uin
|
|||
/// Get the category bits on a proxy.
|
||||
B3_API uint64_t b3DynamicTree_GetCategoryBits( b3DynamicTree* tree, int proxyId );
|
||||
|
||||
/// Query an AABB for overlapping proxies. The callback function is called for each proxy that overlaps the supplied AABB.
|
||||
/// Query an AABB for overlapping proxies. The callback function is called for each proxy that overlaps the supplied
|
||||
/// AABB.
|
||||
/// @return performance data
|
||||
B3_API b3TreeStats b3DynamicTree_Query( const b3DynamicTree* tree, b3AABB aabb, uint64_t maskBits, bool requireAllBits,
|
||||
b3TreeQueryCallbackFcn* callback, void* context );
|
||||
|
||||
/// Query an AABB for the closest object. The callback function is called for each proxy that might be closest to the supplied
|
||||
/// point.
|
||||
/// Query an AABB for the closest object. The callback function is called for each proxy that might be closest to the
|
||||
/// supplied point.
|
||||
/// @param tree the dynamic tree to query
|
||||
/// @param point the query point
|
||||
/// @param maskBits proxies are skipped if the bit-wise AND with the proxy category bits is zero
|
||||
/// @param requireAllBits proxies are skipped if the bit-wise AND with the proxy category bits does not equal the maskBits
|
||||
/// @param requireAllBits proxies are skipped if the bit-wise AND with the proxy category bits does not equal the
|
||||
/// maskBits
|
||||
/// @param callback a user provided instance of b3TreeQueryClosestCallbackFcn
|
||||
/// @param context a user context object that is provided to the callback
|
||||
/// @param minDistanceSqr the initial and final minimum squared distance. Provide a small initial to restrict the search and
|
||||
/// improve performance. If the value is large this query has performance that scales linearly with the number of proxies and
|
||||
/// would be slower than a brute force search.
|
||||
/// @param minDistanceSqr the initial and final minimum squared distance. Provide a small initial to restrict the search
|
||||
/// and improve performance. If the value is large this query has performance that scales linearly with the number of
|
||||
/// proxies and would be slower than a brute force search.
|
||||
/// @return performance data
|
||||
B3_API b3TreeStats b3DynamicTree_QueryClosest( const b3DynamicTree* tree, b3Vec3 point, uint64_t maskBits, bool requireAllBits,
|
||||
b3TreeQueryClosestCallbackFcn* callback, void* context, float* minDistanceSqr );
|
||||
B3_API b3TreeStats b3DynamicTree_QueryClosest( const b3DynamicTree* tree, b3Vec3 point, uint64_t maskBits,
|
||||
bool requireAllBits, b3TreeQueryClosestCallbackFcn* callback,
|
||||
void* context, float* minDistanceSqr );
|
||||
|
||||
/// Ray cast against the proxies in the tree. This relies on the callback
|
||||
/// to perform an exact ray cast in the case where the proxy contains a shape.
|
||||
|
|
@ -342,6 +345,28 @@ B3_INLINE const uint8_t* b3GetMeshFlags( const b3MeshData* mesh )
|
|||
return (const uint8_t*)( (intptr_t)mesh + mesh->flagsOffset );
|
||||
}
|
||||
|
||||
/// Get read only quantized angles between neighboring triangle normals.
|
||||
B3_INLINE const int8_t* b3GetMeshEdgeAngles( const b3MeshData* mesh )
|
||||
{
|
||||
if ( mesh->edgeAngleOffset == 0 )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (const int8_t*)( (intptr_t)mesh + mesh->edgeAngleOffset );
|
||||
}
|
||||
|
||||
/// Get read only vertex flags.
|
||||
B3_INLINE const uint8_t* b3GetMeshVertexFlags( const b3MeshData* mesh )
|
||||
{
|
||||
if ( mesh->vertexFlagOffset == 0 )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (const uint8_t*)( (intptr_t)mesh + mesh->vertexFlagOffset );
|
||||
}
|
||||
|
||||
/// Create a grid mesh along the x and z axes.
|
||||
/// @param xCount the number of rows in the x direction
|
||||
/// @param zCount the number of rows in the z direction
|
||||
|
|
@ -422,8 +447,8 @@ B3_API b3HeightFieldData* b3CreateHeightField( const b3HeightFieldDef* data );
|
|||
B3_API b3HeightFieldData* b3CreateGrid( int rowCount, int columnCount, b3Vec3 scale, bool makeHoles );
|
||||
|
||||
/// Create a wave grid as a height field.
|
||||
B3_API b3HeightFieldData* b3CreateWave( int rowCount, int columnCount, b3Vec3 scale, float rowFrequency, float columnFrequency,
|
||||
bool makeHoles );
|
||||
B3_API b3HeightFieldData* b3CreateWave( int rowCount, int columnCount, b3Vec3 scale, float rowFrequency,
|
||||
float columnFrequency, bool makeHoles );
|
||||
|
||||
/// Destroy a height field.
|
||||
B3_API void b3DestroyHeightField( b3HeightFieldData* heightField );
|
||||
|
|
@ -522,7 +547,8 @@ B3_API bool b3OverlapCapsule( const b3Capsule* shape, b3Transform shapeTransform
|
|||
B3_API bool b3OverlapCompound( const b3CompoundData* shape, b3Transform shapeTransform, const b3ShapeProxy* proxy );
|
||||
|
||||
/// Overlap shape versus height field
|
||||
B3_API bool b3OverlapHeightField( const b3HeightFieldData* shape, b3Transform shapeTransform, const b3ShapeProxy* proxy );
|
||||
B3_API bool b3OverlapHeightField( const b3HeightFieldData* shape, b3Transform shapeTransform,
|
||||
const b3ShapeProxy* proxy );
|
||||
|
||||
/// Overlap shape versus hull
|
||||
B3_API bool b3OverlapHull( const b3HullData* shape, b3Transform shapeTransform, const b3ShapeProxy* proxy );
|
||||
|
|
@ -580,29 +606,34 @@ B3_API b3CastOutput b3ShapeCastHeightField( const b3HeightFieldData* shape, cons
|
|||
/// Query callback.
|
||||
typedef bool b3MeshQueryFcn( b3Vec3 a, b3Vec3 b, b3Vec3 c, int triangleIndex, void* context );
|
||||
|
||||
/// Query a mesh for triangles overlapping a bounding box in local space. May have false positives. Useful for debug draw.
|
||||
/// Query a mesh for triangles overlapping a bounding box in local space. May have false positives. Useful for debug
|
||||
/// draw.
|
||||
/// @param mesh the mesh to query, includes scale
|
||||
/// @param bounds the bounding box in local space
|
||||
/// @param fcn a user function to collect triangles
|
||||
/// @param context the context sent to the user function.
|
||||
B3_API void b3QueryMesh( const b3Mesh* mesh, const b3AABB bounds, b3MeshQueryFcn* fcn, void* context );
|
||||
|
||||
/// Query a height field for triangles overlapping a bounding box in local space. May have false positives. Useful for debug draw.
|
||||
/// Query a height field for triangles overlapping a bounding box in local space. May have false positives. Useful for
|
||||
/// debug draw.
|
||||
/// @param heightField the height field to query
|
||||
/// @param bounds the bounding box in local space
|
||||
/// @param fcn a user function to collect triangles
|
||||
/// @param context the context sent to the user function.
|
||||
B3_API void b3QueryHeightField( const b3HeightFieldData* heightField, b3AABB bounds, b3MeshQueryFcn* fcn, void* context );
|
||||
B3_API void b3QueryHeightField( const b3HeightFieldData* heightField, b3AABB bounds, b3MeshQueryFcn* fcn,
|
||||
void* context );
|
||||
|
||||
/// Compute the closest points between two shapes represented as point clouds.
|
||||
/// b3SimplexCache cache is input/output. On the first call set b3SimplexCache.count to zero.
|
||||
/// The query runs in frame A, so the witness points and normal are returned in frame A.
|
||||
/// The underlying GJK algorithm may be debugged by passing in debug simplexes and capacity. You may pass in NULL and 0 for these.
|
||||
/// The underlying GJK algorithm may be debugged by passing in debug simplexes and capacity. You may pass in NULL and 0
|
||||
/// for these.
|
||||
B3_API b3DistanceOutput b3ShapeDistance( const b3DistanceInput* input, b3SimplexCache* cache, b3Simplex* simplexes,
|
||||
int simplexCapacity );
|
||||
|
||||
/// Perform a linear shape cast of shape B moving and shape A fixed. Determines the hit point, normal, and translation fraction.
|
||||
/// The query runs in frame A, so the hit point and normal are returned in frame A. Initially touching shapes are a miss.
|
||||
/// Perform a linear shape cast of shape B moving and shape A fixed. Determines the hit point, normal, and translation
|
||||
/// fraction. The query runs in frame A, so the hit point and normal are returned in frame A. Initially touching shapes
|
||||
/// are a miss.
|
||||
B3_API b3CastOutput b3ShapeCast( const b3ShapeCastPairInput* input );
|
||||
|
||||
/// Evaluate the transform sweep at a specific time.
|
||||
|
|
@ -630,16 +661,16 @@ B3_API void b3CollideCapsuleAndSphere( b3LocalManifold* manifold, int capacity,
|
|||
const b3Sphere* sphereB, b3Transform transformBtoA );
|
||||
|
||||
/// Collide a hull and a sphere.
|
||||
B3_API void b3CollideHullAndSphere( b3LocalManifold* manifold, int capacity, const b3HullData* hullA, const b3Sphere* sphereB,
|
||||
b3Transform transformBtoA, b3SimplexCache* cache );
|
||||
B3_API void b3CollideHullAndSphere( b3LocalManifold* manifold, int capacity, const b3HullData* hullA,
|
||||
const b3Sphere* sphereB, b3Transform transformBtoA, b3SimplexCache* cache );
|
||||
|
||||
/// Collide two capsules.
|
||||
B3_API void b3CollideCapsules( b3LocalManifold* manifold, int capacity, const b3Capsule* capsuleA, const b3Capsule* capsuleB,
|
||||
b3Transform transformBtoA );
|
||||
B3_API void b3CollideCapsules( b3LocalManifold* manifold, int capacity, const b3Capsule* capsuleA,
|
||||
const b3Capsule* capsuleB, b3Transform transformBtoA );
|
||||
|
||||
/// Collide a hull and a capsule.
|
||||
B3_API void b3CollideHullAndCapsule( b3LocalManifold* manifold, int capacity, const b3HullData* hullA, const b3Capsule* capsuleB,
|
||||
b3Transform transformBtoA, b3SimplexCache* cache );
|
||||
B3_API void b3CollideHullAndCapsule( b3LocalManifold* manifold, int capacity, const b3HullData* hullA,
|
||||
const b3Capsule* capsuleB, b3Transform transformBtoA, b3SimplexCache* cache );
|
||||
|
||||
/// Collide two hulls.
|
||||
B3_API void b3CollideHulls( b3LocalManifold* manifold, int capacity, const b3HullData* hullA, const b3HullData* hullB,
|
||||
|
|
@ -650,24 +681,46 @@ B3_API void b3CollideTriangleAndCapsule( b3LocalManifold* manifold, int capacity
|
|||
const b3Capsule* capsuleB, b3SimplexCache* cache );
|
||||
|
||||
/// Collide a triangle and hull. Normal points from triangle to hull.
|
||||
B3_API void b3CollideTriangleAndHull( b3LocalManifold* manifold, int capacity, b3Vec3 v1, b3Vec3 v2, b3Vec3 v3, int triangleFlags,
|
||||
const b3HullData* hullB, b3SATCache* cache, bool enableSpeculative );
|
||||
B3_API void b3CollideTriangleAndHull( b3LocalManifold* manifold, int capacity, b3Vec3 v1, b3Vec3 v2, b3Vec3 v3,
|
||||
const b3HullData* hullB, b3SATCache* cache,
|
||||
bool enableSpeculative );
|
||||
|
||||
/// Collide a triangle and sphere. Normal points from triangle to sphere.
|
||||
B3_API void b3CollideTriangleAndSphere( b3LocalManifold* manifold, int capacity, const b3Vec3* triangleA,
|
||||
const b3Sphere* sphereB );
|
||||
|
||||
/// Collide a mesh and hull for testing.
|
||||
B3_API int b3CollideMeshAndHull( b3Manifold* manifolds, int capacity, const b3Mesh* mesh, const b3HullData* hull,
|
||||
b3Transform transformBtoA, bool enableSpeculative, bool handleGhosts );
|
||||
|
||||
/// Collide a mesh and sphere for testing.
|
||||
B3_API int b3CollideMeshAndSphere( b3Manifold* manifolds, int capacity, const b3Mesh* mesh, const b3Sphere* sphere,
|
||||
b3Transform transformBtoA, bool enableSpeculative, bool handleGhosts );
|
||||
|
||||
/// This is used for computing 2D hulls in service of contact manifold simplification.
|
||||
/// Placed here for testing. Internal.
|
||||
typedef struct b3Point2D
|
||||
{
|
||||
b3Vec2 p; // 2D point
|
||||
float separation; // separation of the associated contact point
|
||||
int originalIndex; // original index of the associated contact point
|
||||
b3Vec2 p; ///< 2D point
|
||||
float separation; ///< separation of the associated contact point
|
||||
int originalIndex; ///< original index of the associated contact point
|
||||
} b3Point2D;
|
||||
|
||||
/// Options for how a 2D hull is built.
|
||||
typedef enum b3Hull2DFlags
|
||||
{
|
||||
/// Keep collinear points.
|
||||
b3_hull2DKeepCollinear = 0x01,
|
||||
|
||||
/// Only merge identical points.
|
||||
b3_hull2DExactMerge = 0x02,
|
||||
|
||||
/// Order the output points by the input order.
|
||||
b3_hull2DIndexOrder = 0x04,
|
||||
} b3Hull2DFlags;
|
||||
|
||||
/// Compute a 2D hull. Used internally for contact manifold simplification. Here for testing.
|
||||
B3_API int b3Hull2D( b3Point2D* pts, int count, b3Point2D* hull );
|
||||
B3_API int b3Hull2D( b3Point2D* pts, int count, b3Point2D* hull, int flags );
|
||||
|
||||
/// Simplify a 2D hull. Used internally for contact manifold simplification. Here for testing.
|
||||
B3_API int b3SimplifyHull2D( b3Point2D* hull, int count, int target );
|
||||
|
|
|
|||
|
|
@ -137,10 +137,3 @@ B3_API float b3GetLengthUnitsPerMeter( void );
|
|||
#define B3_CHILD_POWER ( 64 - 2 * B3_SHAPE_POWER )
|
||||
#define B3_MAX_SHAPES ( 1 << B3_SHAPE_POWER )
|
||||
#define B3_MAX_CHILD_SHAPES ( 1 << B3_CHILD_POWER )
|
||||
|
||||
/// This is the limit on how many mesh or heightfield triangles a single convex shape can collide with.
|
||||
/// Increasing this will increase stack usage, so be careful. I recommend to simplify your collision data
|
||||
/// before increasing this. For example, using render mesh for collision often leads to poor performance.
|
||||
#ifndef B3_MAX_MESH_CONTACT_TRIANGLES
|
||||
#define B3_MAX_MESH_CONTACT_TRIANGLES 512
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -189,7 +189,48 @@ B3_INLINE float b3LerpFloat( float a, float b, float alpha )
|
|||
/// This is hand coded for cross-platform determinism. The atan2f
|
||||
/// function in the standard library is not cross-platform deterministic.
|
||||
/// Accurate to around 0.0023 degrees.
|
||||
B3_API float b3Atan2( float y, float x );
|
||||
/// https://stackoverflow.com/questions/46210708/atan2-approximation-with-11bits-in-mantissa-on-x86with-sse2-and-armwith-vfpv4
|
||||
B3_INLINE float b3Atan2( float y, float x )
|
||||
{
|
||||
// Added check for (0,0) to match atan2f and avoid NaN
|
||||
if ( x == 0.0f && y == 0.0f )
|
||||
{
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
float ax = b3AbsFloat( x );
|
||||
float ay = b3AbsFloat( y );
|
||||
float mx = b3MaxFloat( ay, ax );
|
||||
float mn = b3MinFloat( ay, ax );
|
||||
float a = mn / mx;
|
||||
|
||||
// Minimax polynomial approximation to atan(a) on [0,1]
|
||||
float s = a * a;
|
||||
float c = s * a;
|
||||
float q = s * s;
|
||||
float r = 0.024840285f * q + 0.18681418f;
|
||||
float t = -0.094097948f * q - 0.33213072f;
|
||||
r = r * s + t;
|
||||
r = r * c + a;
|
||||
|
||||
// Map to full circle
|
||||
if ( ay > ax )
|
||||
{
|
||||
r = 1.57079637f - r;
|
||||
}
|
||||
|
||||
if ( x < 0 )
|
||||
{
|
||||
r = 3.14159274f - r;
|
||||
}
|
||||
|
||||
if ( y < 0 )
|
||||
{
|
||||
r = -r;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/// Compute the cosine and sine of an angle in radians. Implemented
|
||||
/// for cross-platform determinism.
|
||||
|
|
|
|||
|
|
@ -31,8 +31,7 @@ typedef void b3TaskCallback( void* taskContext );
|
|||
/// @param userContext the scheduler context object that is opaque to Box3D
|
||||
/// @param taskName the Box3D task name that the scheduler can use for diagnostics
|
||||
/// @ingroup world
|
||||
typedef void* b3EnqueueTaskCallback( b3TaskCallback* task, void* taskContext, void* userContext,
|
||||
const char* taskName );
|
||||
typedef void* b3EnqueueTaskCallback( b3TaskCallback* task, void* taskContext, void* userContext, const char* taskName );
|
||||
|
||||
/// Finishes a user task object that wraps a Box3D task. This must block until the task has
|
||||
/// completed. The step blocks here on the tasks it spawned, so b3World_Step holds its stack across
|
||||
|
|
@ -64,8 +63,8 @@ typedef float b3FrictionCallback( float frictionA, uint64_t userMaterialIdA, flo
|
|||
/// this is called from a worker thread.
|
||||
/// @warning This function should not attempt to modify Box3D state or user application state.
|
||||
/// @ingroup world
|
||||
typedef float b3RestitutionCallback( float restitutionA, uint64_t userMaterialIdA,
|
||||
float restitutionB, uint64_t userMaterialIdB );
|
||||
typedef float b3RestitutionCallback( float restitutionA, uint64_t userMaterialIdA, float restitutionB,
|
||||
uint64_t userMaterialIdB );
|
||||
|
||||
/// Prototype for a contact filter callback.
|
||||
/// This is called when a contact pair is considered for collision. This allows you to
|
||||
|
|
@ -93,8 +92,7 @@ typedef bool b3CustomFilterFcn( b3ShapeId shapeIdA, b3ShapeId shapeIdB, void* co
|
|||
/// full contact manifold.
|
||||
/// @warning Do not attempt to modify the world inside this callback
|
||||
/// @ingroup world
|
||||
typedef bool b3PreSolveFcn( b3ShapeId shapeIdA, b3ShapeId shapeIdB, b3Pos point, b3Vec3 normal,
|
||||
void* context );
|
||||
typedef bool b3PreSolveFcn( b3ShapeId shapeIdA, b3ShapeId shapeIdB, b3Pos point, b3Vec3 normal, void* context );
|
||||
|
||||
/// Prototype callback for overlap queries.
|
||||
/// Called for each shape found in the query.
|
||||
|
|
@ -122,9 +120,8 @@ typedef bool b3OverlapResultFcn( b3ShapeId shapeId, void* context );
|
|||
/// @return -1 to filter, 0 to terminate, fraction to clip the ray for closest hit, 1 to continue
|
||||
/// @see b3World_CastRay
|
||||
/// @ingroup world
|
||||
typedef float b3CastResultFcn( b3ShapeId shapeId, b3Pos point, b3Vec3 normal, float fraction,
|
||||
uint64_t userMaterialId, int triangleIndex, int childIndex,
|
||||
void* context );
|
||||
typedef float b3CastResultFcn( b3ShapeId shapeId, b3Pos point, b3Vec3 normal, float fraction, uint64_t userMaterialId,
|
||||
int triangleIndex, int childIndex, void* context );
|
||||
|
||||
/// Optional world capacities that can be use to avoid run-time allocations
|
||||
/// @ingroup world
|
||||
|
|
@ -1628,7 +1625,6 @@ typedef struct b3SimplexCache
|
|||
/// Value use to compare length, area, volume of two simplexes.
|
||||
float metric;
|
||||
|
||||
// todo use an index of 0xFF as a sentinel and remove the count
|
||||
/// The number of stored simplex points
|
||||
uint16_t count;
|
||||
|
||||
|
|
@ -1650,7 +1646,7 @@ typedef struct b3ShapeCastPairInput
|
|||
b3Transform transform; ///< Transform of shape B in shape A's frame, the relative pose B in A
|
||||
b3Vec3 translationB; ///< The translation of shape B, in A's frame
|
||||
float maxFraction; ///< The fraction of the translation to consider, typically 1
|
||||
bool canEncroach; ///< Allows shapes with a radius to move slightly closer if already touching
|
||||
bool canEncroach; ///< Allows shapes with a radius to move slightly closer if already touching
|
||||
} b3ShapeCastPairInput;
|
||||
|
||||
/// Input for b3ShapeDistance
|
||||
|
|
@ -1905,24 +1901,21 @@ typedef bool b3TreeQueryCallbackFcn( int proxyId, uint64_t userData, void* conte
|
|||
/// This function receives the minimum distance squared so far and proxy to check in the closest
|
||||
/// query.
|
||||
/// @return minimum distance squared to user objects in the proxy
|
||||
typedef float b3TreeQueryClosestCallbackFcn( float distanceSqrMin, int proxyId, uint64_t userData,
|
||||
void* context );
|
||||
typedef float b3TreeQueryClosestCallbackFcn( float distanceSqrMin, int proxyId, uint64_t userData, void* context );
|
||||
|
||||
/// This function receives clipped AABB cast input for a proxy. The function returns the new cast
|
||||
/// fraction.
|
||||
/// - return a value of 0 to terminate the cast
|
||||
/// - return a value less than input->maxFraction to clip the cast
|
||||
/// - return a value of input->maxFraction to continue the cast without clipping
|
||||
typedef float b3TreeBoxCastCallbackFcn( const b3BoxCastInput* input, int proxyId, uint64_t userData,
|
||||
void* context );
|
||||
typedef float b3TreeBoxCastCallbackFcn( const b3BoxCastInput* input, int proxyId, uint64_t userData, void* context );
|
||||
|
||||
/// This function receives clipped ray cast input for a proxy. The function
|
||||
/// returns the new ray fraction.
|
||||
/// - return a value of 0 to terminate the ray cast
|
||||
/// - return a value less than input->maxFraction to clip the ray
|
||||
/// - return a value of input->maxFraction to continue the ray cast without clipping
|
||||
typedef float b3TreeRayCastCallbackFcn( const b3RayCastInput* input, int proxyId, uint64_t userData,
|
||||
void* context );
|
||||
typedef float b3TreeRayCastCallbackFcn( const b3RayCastInput* input, int proxyId, uint64_t userData, void* context );
|
||||
|
||||
/**@}*/ // tree
|
||||
|
||||
|
|
@ -2009,8 +2002,7 @@ typedef struct b3BodyTOIResult
|
|||
|
||||
/// Used to collect collision planes for character movers.
|
||||
/// Return true to continue gathering planes.
|
||||
typedef bool b3PlaneResultFcn( b3ShapeId shapeId, const b3PlaneResult* plane, int planeCount,
|
||||
void* context );
|
||||
typedef bool b3PlaneResultFcn( b3ShapeId shapeId, const b3PlaneResult* plane, int planeCount, void* context );
|
||||
|
||||
/// Used to filter shapes for shape casting character movers.
|
||||
/// Return true to accept the collision
|
||||
|
|
@ -2260,7 +2252,7 @@ typedef struct b3MeshDef
|
|||
} b3MeshDef;
|
||||
|
||||
/// 64-bit mesh version. Useful for validating serialized data.
|
||||
#define B3_MESH_VERSION 0xAAAB9A00F1A8AAF7ull
|
||||
#define B3_MESH_VERSION 0x24AA0BF74682501Dull
|
||||
|
||||
/// Triangle mesh edge flags.
|
||||
typedef enum b3MeshEdgeFlags
|
||||
|
|
@ -2291,6 +2283,16 @@ typedef struct b3MeshTriangle
|
|||
int32_t index3; ///< Index of vertex 3.
|
||||
} b3MeshTriangle;
|
||||
|
||||
/// Indicates an isolated edge (treated as a cliff).
|
||||
#define B3_BOUNDARY_EDGE_ANGLE ( -128 )
|
||||
|
||||
/// Mesh vertex flags. Used for ghost collision handling.
|
||||
typedef enum b3MeshVertexFlags
|
||||
{
|
||||
b3_flatVertex = 0x01, ///< All edges are flat.
|
||||
b3_concaveVertex = 0x02, ///< Any edge is concave.
|
||||
} b3MeshVertexFlags;
|
||||
|
||||
/// A mesh BVH node.
|
||||
typedef struct b3MeshNode
|
||||
{
|
||||
|
|
@ -2327,7 +2329,8 @@ typedef struct b3MeshNode
|
|||
uint32_t triangleOffset;
|
||||
} b3MeshNode;
|
||||
|
||||
/// This is a sorted triangle collision bounding volume hierarchy.
|
||||
/// This is a sorted triangle collision bounding volume hierarchy. Offsets are a byte
|
||||
/// count offset from the struct address.
|
||||
/// @note This struct has data hanging off the end and cannot be directly copied.
|
||||
typedef struct b3MeshData
|
||||
{
|
||||
|
|
@ -2352,35 +2355,41 @@ typedef struct b3MeshData
|
|||
/// The number of degenerate triangles. Diagnostic.
|
||||
int32_t degenerateCount;
|
||||
|
||||
/// Offset of the node array in bytes from the struct address.
|
||||
/// Offset of the node array.
|
||||
int32_t nodeOffset;
|
||||
|
||||
/// The number of BVH nodes.
|
||||
int32_t nodeCount;
|
||||
|
||||
/// Offset of the vertex array in bytes from the struct address.
|
||||
/// Offset of the vertex array.
|
||||
int32_t vertexOffset;
|
||||
|
||||
/// The number of vertices.
|
||||
int32_t vertexCount;
|
||||
|
||||
/// Offset of the triangle array in bytes from the struct address.
|
||||
/// Offset of the triangle array.
|
||||
int32_t triangleOffset;
|
||||
|
||||
/// The number of triangles.
|
||||
int32_t triangleCount;
|
||||
|
||||
/// Offset of the material array in bytes from the struct address.
|
||||
/// Offset of the material array.
|
||||
int32_t materialOffset;
|
||||
|
||||
/// The number of materials.
|
||||
int32_t materialCount;
|
||||
|
||||
/// Offset of the triangle flag array in bytes from the struct address.
|
||||
/// Offset of the triangle flag array.
|
||||
int32_t flagsOffset;
|
||||
|
||||
/// Explicit padding.
|
||||
int32_t padding;
|
||||
// Offset to the edge neighbor angles.
|
||||
int32_t edgeAngleOffset;
|
||||
|
||||
/// Offset of the vertex flag array.
|
||||
int32_t vertexFlagOffset;
|
||||
|
||||
/// Offset the vertex neighbor angle ring.
|
||||
int32_t vertexRingOffset;
|
||||
} b3MeshData;
|
||||
|
||||
/// This allows mesh data to be re-used with different scales.
|
||||
|
|
@ -2441,7 +2450,7 @@ typedef struct b3HeightFieldDef
|
|||
#define B3_HEIGHT_FIELD_HOLE 0xFF
|
||||
|
||||
/// 64-bit height-field version. Useful for validating serialized data.
|
||||
#define B3_HEIGHT_FIELD_VERSION 0x8E41E5FB084848F8ull
|
||||
#define B3_HEIGHT_FIELD_VERSION 0x5A69A297D7ACE1CDull
|
||||
|
||||
/// A height field with compressed storage.
|
||||
/// @note This data structure has data hanging off the end and cannot be directly copied.
|
||||
|
|
@ -2489,11 +2498,15 @@ typedef struct b3HeightFieldData
|
|||
/// uint8_t, one per triangle.
|
||||
int32_t flagsOffset;
|
||||
|
||||
/// Offset to the vertex ghost collision flag. Array of bits.
|
||||
int32_t vertexFlagOffset;
|
||||
|
||||
/// Triangle winding.
|
||||
uint8_t clockwise;
|
||||
|
||||
/// Explicit padding.
|
||||
uint8_t padding[7];
|
||||
uint8_t padding[3];
|
||||
|
||||
} b3HeightFieldData;
|
||||
|
||||
/**@}*/ // height_field
|
||||
|
|
@ -2797,6 +2810,12 @@ typedef struct b3ManifoldPoint
|
|||
|
||||
/// Did this contact point exist in the previous step?
|
||||
bool persisted;
|
||||
|
||||
// b3TriangleFeature
|
||||
uint8_t triangleFeature;
|
||||
|
||||
// b3MeshContactFlags
|
||||
uint8_t meshFlags;
|
||||
} b3ManifoldPoint;
|
||||
|
||||
/// A contact manifold describes the contact points between colliding shapes.
|
||||
|
|
@ -2824,7 +2843,7 @@ typedef struct b3Manifold
|
|||
} b3Manifold;
|
||||
|
||||
/// Cached separating axis feature.
|
||||
typedef enum
|
||||
typedef enum b3SeparatingFeature
|
||||
{
|
||||
b3_invalidAxis = 0,
|
||||
b3_backsideAxis,
|
||||
|
|
@ -2840,7 +2859,7 @@ typedef enum
|
|||
} b3SeparatingFeature;
|
||||
|
||||
/// Cached triangle feature.
|
||||
typedef enum
|
||||
typedef enum b3TriangleFeature
|
||||
{
|
||||
b3_featureNone = 0,
|
||||
b3_featureTriangleFace,
|
||||
|
|
@ -2856,6 +2875,14 @@ typedef enum
|
|||
b3_featureVertex3
|
||||
} b3TriangleFeature;
|
||||
|
||||
/// This gives debug information about how a contact point was generated.
|
||||
typedef enum b3MeshContactFlags
|
||||
{
|
||||
b3_meshContactHullFace = 0x01, ///< Normal is a hull face normal.
|
||||
b3_meshContactSnapped = 0x02, ///< The normal is snapped to the triangle normal.
|
||||
b3_meshContactDeep = 0x04, ///< The contact is considered deep (2 * linear slop).
|
||||
} b3MeshContactFlags;
|
||||
|
||||
/// Separating axis test cache. Provides temporal acceleration of collision routines.
|
||||
typedef struct
|
||||
{
|
||||
|
|
@ -2907,6 +2934,12 @@ typedef struct b3LocalManifoldPoint
|
|||
|
||||
/// The triangle index when collide with a mesh or height-field.
|
||||
int triangleIndex;
|
||||
|
||||
// b3TriangleFeature
|
||||
uint8_t triangleFeature;
|
||||
|
||||
// b3MeshContactFlags
|
||||
uint8_t meshFlags;
|
||||
} b3LocalManifoldPoint;
|
||||
|
||||
/// A local manifold with no dynamic information. Used by b3Collide functions.
|
||||
|
|
@ -2927,18 +2960,8 @@ typedef struct b3LocalManifold
|
|||
/// The index of the triangle.
|
||||
int triangleIndex;
|
||||
|
||||
int i1; ///< Vertex 1 index.
|
||||
int i2; ///< Vertex 2 index.
|
||||
int i3; ///< Vertex 3 index.
|
||||
|
||||
/// The squared distance of a sphere from a triangle. For ghost collision reduction.
|
||||
float squaredDistance;
|
||||
|
||||
/// The triangle feature involved.
|
||||
b3TriangleFeature feature;
|
||||
|
||||
/// b3MeshEdgeFlags.
|
||||
int triangleFlags;
|
||||
} b3LocalManifold;
|
||||
|
||||
/**@}*/ // collision
|
||||
|
|
@ -3157,8 +3180,7 @@ typedef struct b3DebugDraw
|
|||
/// Draws a user shape. The userShape pointer is owned by the application and is known to Box3D
|
||||
/// as an opaque pointer returned from b3CreateDebugShapeCallback. When this is called the drawn
|
||||
/// shape has passed a culling test against drawingBounds below.
|
||||
void ( *DrawShapeFcn )( void* userShape, b3WorldTransform transform, b3HexColor color,
|
||||
void* context );
|
||||
void ( *DrawShapeFcn )( void* userShape, b3WorldTransform transform, b3HexColor color, void* context );
|
||||
|
||||
/// Draw a line segment.
|
||||
void ( *DrawSegmentFcn )( b3Pos p1, b3Pos p2, b3HexColor color, void* context );
|
||||
|
|
@ -3173,15 +3195,13 @@ typedef struct b3DebugDraw
|
|||
void ( *DrawSphereFcn )( b3Pos p, float radius, b3HexColor color, float alpha, void* context );
|
||||
|
||||
/// Draw a capsule.
|
||||
void ( *DrawCapsuleFcn )( b3Pos p1, b3Pos p2, float radius, b3HexColor color, float alpha,
|
||||
void* context );
|
||||
void ( *DrawCapsuleFcn )( b3Pos p1, b3Pos p2, float radius, b3HexColor color, float alpha, void* context );
|
||||
|
||||
/// Draw a bounding box.
|
||||
void ( *DrawBoundsFcn )( b3AABB aabb, b3HexColor color, void* context );
|
||||
|
||||
/// Draw an oriented box.
|
||||
void ( *DrawBoxFcn )( b3Vec3 extents, b3WorldTransform transform, b3HexColor color,
|
||||
void* context );
|
||||
void ( *DrawBoxFcn )( b3Vec3 extents, b3WorldTransform transform, b3HexColor color, void* context );
|
||||
|
||||
/// Draw a string in world space
|
||||
void ( *DrawStringFcn )( b3Pos p, const char* s, b3HexColor color, void* context );
|
||||
|
|
|
|||
|
|
@ -34,6 +34,16 @@ FetchContent_Declare(nfd
|
|||
)
|
||||
FetchContent_MakeAvailable(nfd)
|
||||
|
||||
# meshoptimizer for the s&box Ghost Collisions remesh toggle. Static lib, target meshoptimizer.
|
||||
set(MESHOPT_INSTALL OFF CACHE BOOL "" FORCE)
|
||||
FetchContent_Declare(meshoptimizer
|
||||
GIT_REPOSITORY https://github.com/zeux/meshoptimizer.git
|
||||
GIT_TAG v1.3
|
||||
GIT_SHALLOW TRUE
|
||||
GIT_PROGRESS TRUE
|
||||
)
|
||||
FetchContent_MakeAvailable(meshoptimizer)
|
||||
|
||||
# The shader compiler is only needed when recompiling shaders. A fresh clone
|
||||
# with BOX3D_BUILD_SHADERS=OFF builds from the committed headers and skips this.
|
||||
if(BOX3D_BUILD_SHADERS)
|
||||
|
|
@ -187,6 +197,7 @@ set(SAMPLE_FILES
|
|||
sample_determinism.cpp
|
||||
sample_events.cpp
|
||||
sample_geometry.cpp
|
||||
sample_ghost.cpp
|
||||
sample_issues.cpp
|
||||
sample_joint.cpp
|
||||
sample_manifold.cpp
|
||||
|
|
@ -220,7 +231,7 @@ target_include_directories(samples PRIVATE
|
|||
|
||||
# gfx: the renderer + Draw*/adapter. shared: human, utils (Random*), the
|
||||
# benchmark/determinism helpers the samples lean on.
|
||||
target_link_libraries(samples PRIVATE gfx shared imgui implot imguizmo sokol nfd)
|
||||
target_link_libraries(samples PRIVATE gfx shared imgui implot imguizmo sokol nfd meshoptimizer)
|
||||
|
||||
# MSVC auto-links winmm via a #pragma comment in main.cpp. MinGW ignores that
|
||||
# pragma, so link the timeBeginPeriod/timeEndPeriod library explicitly.
|
||||
|
|
|
|||
|
|
@ -50,11 +50,27 @@ typedef struct
|
|||
float radius;
|
||||
} DebugCapsule;
|
||||
|
||||
// Hull/mesh/heightfield. Scale only for mesh.
|
||||
// A slice of a mesh holding the triangles that share one material color.
|
||||
// A zero color draws with the shape color.
|
||||
typedef struct
|
||||
{
|
||||
MeshHandle handle;
|
||||
uint32_t color;
|
||||
} DebugMeshPart;
|
||||
|
||||
// Hull/mesh/heightfield. Scale only for mesh. A top-level mesh whose material
|
||||
// slots carry different custom colors is drawn as parts, one per color. The
|
||||
// slot colors are snapshot so a runtime material change rebuilds the parts.
|
||||
// The whole mesh handle is kept for highlight and material overrides.
|
||||
typedef struct
|
||||
{
|
||||
MeshHandle handle;
|
||||
b3Vec3 scale;
|
||||
const b3MeshData* data;
|
||||
uint32_t* slotColors;
|
||||
int slotCount;
|
||||
DebugMeshPart* parts;
|
||||
int partCount;
|
||||
} DebugMesh;
|
||||
|
||||
typedef struct
|
||||
|
|
@ -148,6 +164,138 @@ static const float kBodyTypeRoughness[3] = { 0.70f, 0.55f, 0.40f };
|
|||
static const float kDebugMaterialMetallic[6] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.85f };
|
||||
static const float kDebugMaterialRoughness[6] = { 0.50f, 0.85f, 0.65f, 0.95f, 0.30f, 0.35f };
|
||||
|
||||
static void ReleaseMeshParts( DebugMesh* geom )
|
||||
{
|
||||
for ( int i = 0; i < geom->partCount; ++i )
|
||||
{
|
||||
ReleaseMeshReference( geom->parts[i].handle );
|
||||
}
|
||||
free( geom->parts );
|
||||
free( geom->slotColors );
|
||||
geom->parts = NULL;
|
||||
geom->partCount = 0;
|
||||
geom->slotColors = NULL;
|
||||
geom->slotCount = 0;
|
||||
}
|
||||
|
||||
// Group the mesh triangles by the custom color of their material slot. Slots
|
||||
// sharing a color share a part, so a conveyor with many belt slots of one
|
||||
// color costs one draw. Nothing is split when every used slot has one color.
|
||||
static void BuildMeshParts( DebugShape* us )
|
||||
{
|
||||
DebugMesh* geom = &us->geom;
|
||||
ReleaseMeshParts( geom );
|
||||
|
||||
const b3MeshData* data = geom->data;
|
||||
const uint8_t* indices = data != NULL ? b3GetMeshMaterialIndices( data ) : NULL;
|
||||
const int slotCount = b3Shape_GetMeshMaterialCount( us->shapeId );
|
||||
if ( indices == NULL || slotCount <= 1 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
geom->slotColors = (uint32_t*)malloc( (size_t)slotCount * sizeof( uint32_t ) );
|
||||
uint8_t* used = (uint8_t*)calloc( (size_t)slotCount, 1 );
|
||||
uint8_t* mask = (uint8_t*)malloc( (size_t)slotCount );
|
||||
uint32_t* colors = (uint32_t*)malloc( (size_t)slotCount * sizeof( uint32_t ) );
|
||||
if ( geom->slotColors == NULL || used == NULL || mask == NULL || colors == NULL )
|
||||
{
|
||||
free( used );
|
||||
free( mask );
|
||||
free( colors );
|
||||
free( geom->slotColors );
|
||||
geom->slotColors = NULL;
|
||||
return;
|
||||
}
|
||||
geom->slotCount = slotCount;
|
||||
|
||||
for ( int i = 0; i < slotCount; ++i )
|
||||
{
|
||||
geom->slotColors[i] = b3Shape_GetMeshSurfaceMaterial( us->shapeId, i ).customColor;
|
||||
}
|
||||
|
||||
for ( int t = 0; t < data->triangleCount; ++t )
|
||||
{
|
||||
const int slot = indices[t] < slotCount ? indices[t] : slotCount - 1;
|
||||
used[slot] = 1;
|
||||
}
|
||||
|
||||
int colorCount = 0;
|
||||
for ( int i = 0; i < slotCount; ++i )
|
||||
{
|
||||
if ( used[i] == 0 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
bool found = false;
|
||||
for ( int j = 0; j < colorCount; ++j )
|
||||
{
|
||||
if ( colors[j] == geom->slotColors[i] )
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( found == false )
|
||||
{
|
||||
colors[colorCount++] = geom->slotColors[i];
|
||||
}
|
||||
}
|
||||
|
||||
if ( colorCount > 1 )
|
||||
{
|
||||
geom->parts = (DebugMeshPart*)malloc( (size_t)colorCount * sizeof( DebugMeshPart ) );
|
||||
for ( int j = 0; geom->parts != NULL && j < colorCount; ++j )
|
||||
{
|
||||
for ( int i = 0; i < slotCount; ++i )
|
||||
{
|
||||
mask[i] = ( used[i] != 0 && geom->slotColors[i] == colors[j] ) ? 1 : 0;
|
||||
}
|
||||
|
||||
MeshHandle handle = FindOrAddMeshSubset( data, mask, slotCount );
|
||||
if ( IsMeshHandleValid( handle ) == false )
|
||||
{
|
||||
// Fall back to drawing the whole mesh in the shape color
|
||||
for ( int k = 0; k < geom->partCount; ++k )
|
||||
{
|
||||
ReleaseMeshReference( geom->parts[k].handle );
|
||||
}
|
||||
free( geom->parts );
|
||||
geom->parts = NULL;
|
||||
geom->partCount = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
geom->parts[geom->partCount].handle = handle;
|
||||
geom->parts[geom->partCount].color = colors[j];
|
||||
geom->partCount += 1;
|
||||
}
|
||||
}
|
||||
|
||||
free( used );
|
||||
free( mask );
|
||||
free( colors );
|
||||
}
|
||||
|
||||
// Rebuild the parts when a slot color changed since they were built
|
||||
static void RefreshMeshParts( DebugShape* us )
|
||||
{
|
||||
DebugMesh* geom = &us->geom;
|
||||
if ( geom->slotCount <= 1 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for ( int i = 0; i < geom->slotCount; ++i )
|
||||
{
|
||||
if ( b3Shape_GetMeshSurfaceMaterial( us->shapeId, i ).customColor != geom->slotColors[i] )
|
||||
{
|
||||
BuildMeshParts( us );
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void InitAdapter( void )
|
||||
{
|
||||
for ( int i = 0; i < BOX3D_USER_SHAPE_CAPACITY; ++i )
|
||||
|
|
@ -183,6 +331,7 @@ void ResetAdapterPool( void )
|
|||
DebugShape* us = &s_adapter.pool[i];
|
||||
if ( us->kind == Box3DUS_Hull || us->kind == Box3DUS_Mesh || us->kind == Box3DUS_HeightField )
|
||||
{
|
||||
ReleaseMeshParts( &us->geom );
|
||||
ReleaseMeshReference( us->geom.handle );
|
||||
}
|
||||
else if ( us->kind == Box3DUS_Compound )
|
||||
|
|
@ -532,11 +681,13 @@ static int CreateCompoundChild( const b3ChildShape* child, const DebugShape* par
|
|||
break;
|
||||
case b3_hullShape:
|
||||
us->kind = Box3DUS_Hull;
|
||||
us->geom = (DebugMesh){ 0 };
|
||||
us->geom.handle = handle;
|
||||
us->geom.scale = b3Vec3_one;
|
||||
break;
|
||||
case b3_meshShape:
|
||||
us->kind = Box3DUS_Mesh;
|
||||
us->geom = (DebugMesh){ 0 };
|
||||
us->geom.handle = handle;
|
||||
us->geom.scale = (b3Vec3){ child->mesh.scale.x, child->mesh.scale.y, child->mesh.scale.z };
|
||||
break;
|
||||
|
|
@ -603,6 +754,7 @@ static void* AdapterCreateDebugShape( const b3DebugShape* debugShape, void* cont
|
|||
DebugShape* us = &s_adapter.pool[index];
|
||||
us->kind = Box3DUS_Hull;
|
||||
PopulateCommonFields( us, debugShape );
|
||||
us->geom = (DebugMesh){ 0 };
|
||||
us->geom.handle = handle;
|
||||
us->geom.scale = b3Vec3_one;
|
||||
return us;
|
||||
|
|
@ -625,8 +777,11 @@ static void* AdapterCreateDebugShape( const b3DebugShape* debugShape, void* cont
|
|||
DebugShape* us = &s_adapter.pool[index];
|
||||
us->kind = Box3DUS_Mesh;
|
||||
PopulateCommonFields( us, debugShape );
|
||||
us->geom = (DebugMesh){ 0 };
|
||||
us->geom.handle = handle;
|
||||
us->geom.scale = (b3Vec3){ mesh->scale.x, mesh->scale.y, mesh->scale.z };
|
||||
us->geom.data = mesh->data;
|
||||
BuildMeshParts( us );
|
||||
return us;
|
||||
}
|
||||
|
||||
|
|
@ -647,6 +802,7 @@ static void* AdapterCreateDebugShape( const b3DebugShape* debugShape, void* cont
|
|||
DebugShape* us = &s_adapter.pool[index];
|
||||
us->kind = Box3DUS_HeightField;
|
||||
PopulateCommonFields( us, debugShape );
|
||||
us->geom = (DebugMesh){ 0 };
|
||||
us->geom.handle = handle;
|
||||
us->geom.scale = b3Vec3_one;
|
||||
return us;
|
||||
|
|
@ -740,6 +896,7 @@ static void DestroyDebugShape( void* userShape, void* context )
|
|||
}
|
||||
else if ( us->kind == Box3DUS_Hull || us->kind == Box3DUS_Mesh || us->kind == Box3DUS_HeightField )
|
||||
{
|
||||
ReleaseMeshParts( &us->geom );
|
||||
ReleaseMeshReference( us->geom.handle );
|
||||
}
|
||||
|
||||
|
|
@ -757,8 +914,8 @@ static void DestroyDebugShape( void* userShape, void* context )
|
|||
// center, capsule frame) layers on top of baseTransform, so the same path
|
||||
// serves a top-level shape (base = body transform) and a compound child
|
||||
// (base = body transform composed with the child transform).
|
||||
static void AppendResolvedShape( const DebugShape* us, b3Transform baseTransform, Vec4 c, float metallic, float roughness,
|
||||
TransparentShadowCast shadowCast, HighlightKind hk )
|
||||
static void AppendResolvedShape( const DebugShape* us, b3Transform baseTransform, Vec4 c, float metallic,
|
||||
float roughness, TransparentShadowCast shadowCast, HighlightKind hk )
|
||||
{
|
||||
if ( us->kind == Box3DUS_Sphere )
|
||||
{
|
||||
|
|
@ -782,7 +939,24 @@ static void AppendResolvedShape( const DebugShape* us, b3Transform baseTransform
|
|||
{
|
||||
MeshMaterialMode mode = us->isGround ? MESH_MATERIAL_MODE_GROUND_GRID : MESH_MATERIAL_MODE_SOLID;
|
||||
float cell = us->isGround ? BOX3D_GROUND_GRID_CELL_SIZE : 0.0f;
|
||||
AppendMesh( us->geom.handle, baseTransform, us->geom.scale, c, metallic, roughness, mode, cell, shadowCast );
|
||||
if ( us->geom.partCount > 0 && us->hasMaterial == false )
|
||||
{
|
||||
for ( int i = 0; i < us->geom.partCount; ++i )
|
||||
{
|
||||
const DebugMeshPart* part = &us->geom.parts[i];
|
||||
Vec4 pc = c;
|
||||
if ( part->color != 0 )
|
||||
{
|
||||
pc = HexColorToLinear( (b3HexColor)part->color );
|
||||
pc.w = c.w;
|
||||
}
|
||||
AppendMesh( part->handle, baseTransform, us->geom.scale, pc, metallic, roughness, mode, cell, shadowCast );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
AppendMesh( us->geom.handle, baseTransform, us->geom.scale, c, metallic, roughness, mode, cell, shadowCast );
|
||||
}
|
||||
if ( hk != HIGHLIGHT_KIND_NONE )
|
||||
{
|
||||
AppendHighlightGeometry( us->geom.handle, baseTransform, us->geom.scale, hk );
|
||||
|
|
@ -790,9 +964,8 @@ static void AppendResolvedShape( const DebugShape* us, b3Transform baseTransform
|
|||
}
|
||||
}
|
||||
|
||||
// Context for the compound cull query. Carries the resolved material and the
|
||||
// body relative transform so each visited child appends exactly as the full
|
||||
// walk would.
|
||||
// Context for the compound cull query. Carries the resolved material and the body relative transform so each visited
|
||||
// child appends exactly as the full walk would.
|
||||
typedef struct
|
||||
{
|
||||
const DebugShape* parent;
|
||||
|
|
@ -842,6 +1015,11 @@ static void DrawShape( void* userShape, b3WorldTransform shapeTransform, b3HexCo
|
|||
|
||||
RefreshMaterialFromOverride( us );
|
||||
|
||||
if ( us->kind == Box3DUS_Mesh )
|
||||
{
|
||||
RefreshMeshParts( us );
|
||||
}
|
||||
|
||||
Vec4 c;
|
||||
float metallic;
|
||||
float roughness;
|
||||
|
|
@ -964,8 +1142,8 @@ static void DrawTransformFcn( b3WorldTransform transform, void* context )
|
|||
Vec4 blue = MakeVec4( 0.0f, 0.0f, 1.0f, 1.0f );
|
||||
OverlayAppendLine( origin, b3MulAdd( origin, L, basis.cx ), red, BOX3D_LINE_THICKNESS_PX, OVERLAY_THICKNESS_PIXELS,
|
||||
OVERLAY_OCCLUSION_HIDE );
|
||||
OverlayAppendLine( origin, b3MulAdd( origin, L, basis.cy ), green, BOX3D_LINE_THICKNESS_PX, OVERLAY_THICKNESS_PIXELS,
|
||||
OVERLAY_OCCLUSION_HIDE );
|
||||
OverlayAppendLine( origin, b3MulAdd( origin, L, basis.cy ), green, BOX3D_LINE_THICKNESS_PX,
|
||||
OVERLAY_THICKNESS_PIXELS, OVERLAY_OCCLUSION_HIDE );
|
||||
OverlayAppendLine( origin, b3MulAdd( origin, L, basis.cz ), blue, BOX3D_LINE_THICKNESS_PX, OVERLAY_THICKNESS_PIXELS,
|
||||
OVERLAY_OCCLUSION_HIDE );
|
||||
}
|
||||
|
|
@ -988,22 +1166,22 @@ static void DrawCapsuleFcn( b3Pos p1, b3Pos p2, float radius, b3HexColor color,
|
|||
{
|
||||
(void)context;
|
||||
|
||||
b3Vec3 e = b3SubPos(p2, p1);
|
||||
b3Vec3 e = b3SubPos( p2, p1 );
|
||||
float length = b3Length( e );
|
||||
if (length < FLT_EPSILON)
|
||||
if ( length < FLT_EPSILON )
|
||||
{
|
||||
DrawSphereEx( (b3WorldTransform){ p1, b3Quat_identity }, radius, HexColorAToVec4( color, alpha ), DEFAULT_METALLIC,
|
||||
DEFAULT_ROUGHNESS, TRANSPARENT_SHADOW_NONE );
|
||||
DrawSphereEx( (b3WorldTransform){ p1, b3Quat_identity }, radius, HexColorAToVec4( color, alpha ),
|
||||
DEFAULT_METALLIC, DEFAULT_ROUGHNESS, TRANSPARENT_SHADOW_NONE );
|
||||
return;
|
||||
}
|
||||
|
||||
b3Vec3 en = b3MulSV( 1.0f / length, e );
|
||||
b3WorldTransform transform;
|
||||
transform.p = b3OffsetPos( p1, b3MulSV( 0.5f, e ));
|
||||
transform.p = b3OffsetPos( p1, b3MulSV( 0.5f, e ) );
|
||||
transform.q = b3ComputeQuatBetweenUnitVectors( b3Vec3_axisX, en );
|
||||
|
||||
DrawCapsuleEx( transform, 0.5f * length, radius, HexColorAToVec4( color, alpha ), DEFAULT_METALLIC,
|
||||
DEFAULT_ROUGHNESS, TRANSPARENT_SHADOW_NONE );
|
||||
DEFAULT_ROUGHNESS, TRANSPARENT_SHADOW_NONE );
|
||||
}
|
||||
|
||||
static void DrawBoundsFcn( b3AABB aabb, b3HexColor color, void* context )
|
||||
|
|
|
|||
|
|
@ -420,11 +420,14 @@ static inline int MeshEdgeLess( const EdgeRecord* a, const EdgeRecord* b )
|
|||
return a->v1 < b->v1;
|
||||
}
|
||||
|
||||
static MeshHandle BuildMeshData( const b3MeshData* meshData )
|
||||
// A NULL slotMask builds every triangle. Otherwise only triangles whose material
|
||||
// slot has a nonzero mask entry are emitted, and their edges with them.
|
||||
static MeshHandle BuildMeshData( const b3MeshData* meshData, uint64_t hash, const uint8_t* slotMask, int slotCount )
|
||||
{
|
||||
const b3Vec3* verts = b3GetMeshVertices( meshData );
|
||||
const b3MeshTriangle* tris = b3GetMeshTriangles( meshData );
|
||||
const uint8_t* flags = b3GetMeshFlags( meshData );
|
||||
const uint8_t* materialIndices = slotMask != NULL ? b3GetMeshMaterialIndices( meshData ) : NULL;
|
||||
if ( !verts || !tris || meshData->triangleCount <= 0 )
|
||||
{
|
||||
fprintf( stderr, "error: mesh missing arrays or empty (hash=0x%016" PRIx64 ")\n", meshData->hash );
|
||||
|
|
@ -436,6 +439,15 @@ static MeshHandle BuildMeshData( const b3MeshData* meshData )
|
|||
|
||||
for ( int t = 0; t < meshData->triangleCount; ++t )
|
||||
{
|
||||
if ( materialIndices != NULL )
|
||||
{
|
||||
const int slot = materialIndices[t] < slotCount ? materialIndices[t] : slotCount - 1;
|
||||
if ( slotMask[slot] == 0 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
const b3MeshTriangle tri = tris[t];
|
||||
const b3Vec3 a = verts[tri.index1];
|
||||
const b3Vec3 b = verts[tri.index2];
|
||||
|
|
@ -523,7 +535,7 @@ static MeshHandle BuildMeshData( const b3MeshData* meshData )
|
|||
eb.count = write + 1;
|
||||
}
|
||||
|
||||
const MeshHandle h = RegisterMesh( meshData->hash, buf.vertices, buf.vertexCount, buf.indices, buf.indexCount, "geom_mesh" );
|
||||
const MeshHandle h = RegisterMesh( hash, buf.vertices, buf.vertexCount, buf.indices, buf.indexCount, "geom_mesh" );
|
||||
|
||||
if ( IsMeshHandleValid( h ) )
|
||||
{
|
||||
|
|
@ -821,7 +833,37 @@ MeshHandle FindOrAddMesh( const b3MeshData* meshData )
|
|||
return existing;
|
||||
}
|
||||
|
||||
return BuildMeshData( meshData );
|
||||
return BuildMeshData( meshData, meshData->hash, NULL, 0 );
|
||||
}
|
||||
|
||||
MeshHandle FindOrAddMeshSubset( const b3MeshData* meshData, const uint8_t* slotMask, int slotCount )
|
||||
{
|
||||
if ( !meshData || meshData->hash == 0 || slotMask == NULL || slotCount <= 0 ||
|
||||
b3GetMeshMaterialIndices( meshData ) == NULL )
|
||||
{
|
||||
return FindOrAddMesh( meshData );
|
||||
}
|
||||
|
||||
// FNV-1a over the mask, seeded with the mesh hash
|
||||
uint64_t hash = meshData->hash ^ 0xcbf29ce484222325ull;
|
||||
for ( int i = 0; i < slotCount; ++i )
|
||||
{
|
||||
hash ^= slotMask[i] != 0 ? 1u : 0u;
|
||||
hash *= 0x100000001b3ull;
|
||||
}
|
||||
if ( hash == 0 || hash == meshData->hash )
|
||||
{
|
||||
hash += 1;
|
||||
}
|
||||
|
||||
MeshHandle existing = FindMesh( hash );
|
||||
if ( IsMeshHandleValid( existing ) )
|
||||
{
|
||||
AddMeshReference( existing );
|
||||
return existing;
|
||||
}
|
||||
|
||||
return BuildMeshData( meshData, hash, slotMask, slotCount );
|
||||
}
|
||||
|
||||
MeshHandle FindOrAddHeightField( const b3HeightFieldData* heightField )
|
||||
|
|
|
|||
|
|
@ -39,6 +39,12 @@ MeshHandle FindOrAddHull( const b3HullData* hull );
|
|||
// draw time. Two b3Mesh sharing the same b3MeshData share one entry.
|
||||
MeshHandle FindOrAddMesh( const b3MeshData* meshData );
|
||||
|
||||
// Acquire the subset of a mesh whose triangles sit in a material slot with a
|
||||
// nonzero slotMask entry. Keyed by the mesh hash mixed with the mask, so shapes
|
||||
// sharing a mesh and a slot grouping share one entry. Falls back to the whole
|
||||
// mesh when the mesh carries no material indices.
|
||||
MeshHandle FindOrAddMeshSubset( const b3MeshData* meshData, const uint8_t* slotMask, int slotCount );
|
||||
|
||||
// Acquire for b3HeightFieldData. The `scale` vector is part of the height
|
||||
// field's hash (folded into construction), so two heightfields with
|
||||
// different scales hash to different entries, per-instance scale stays
|
||||
|
|
|
|||
|
|
@ -40,7 +40,8 @@ EdgeOverlayParams GetDefaultEdgeParams( void )
|
|||
p.zBias = 1.0e-6f;
|
||||
p.convexColor = MakeVec4( 0.1f, 0.8f, 0.1f, 0.75f );
|
||||
p.concaveColor = MakeVec4( 0.8f, 0.10f, 0.10f, 0.75f );
|
||||
p.flatColor = MakeVec4( 0.6f, 0.6f, 0.6f, 0.5f );
|
||||
p.flatColor = MakeVec4( 0.6f, 0.6f, 0.6f, 0.2f );
|
||||
p.alphaScale = 1.0f;
|
||||
return p;
|
||||
}
|
||||
|
||||
|
|
@ -106,9 +107,11 @@ void ShutdownEdges( void )
|
|||
s_edges.ready = false;
|
||||
}
|
||||
|
||||
static inline Vec4 Premultiply( Vec4 c )
|
||||
static inline Vec4 Premultiply( Vec4 c, float alphaScale )
|
||||
{
|
||||
return MakeVec4( c.x * c.w, c.y * c.w, c.z * c.w, c.w );
|
||||
float a = c.w * alphaScale;
|
||||
a = a < 1.0f ? a : 1.0f;
|
||||
return MakeVec4( c.x * a, c.y * a, c.z * a, a );
|
||||
}
|
||||
|
||||
// Per-batch policy: does the toggle want this batch drawn at all?
|
||||
|
|
@ -160,13 +163,13 @@ static void SubmitBatches( int width, int height, const Mat4* view, const Mat4*
|
|||
edge_ub_pass_t passMesh = { 0 };
|
||||
if ( params->showEdgeConvexity )
|
||||
{
|
||||
passMesh.convex_color = Premultiply( params->convexColor );
|
||||
passMesh.concave_color = Premultiply( params->concaveColor );
|
||||
passMesh.flat_color = Premultiply( params->flatColor );
|
||||
passMesh.convex_color = Premultiply( params->convexColor, params->alphaScale );
|
||||
passMesh.concave_color = Premultiply( params->concaveColor, params->alphaScale );
|
||||
passMesh.flat_color = Premultiply( params->flatColor, params->alphaScale );
|
||||
}
|
||||
else
|
||||
{
|
||||
Vec4 flat = Premultiply( params->flatColor );
|
||||
Vec4 flat = Premultiply( params->flatColor, params->alphaScale );
|
||||
passMesh.convex_color = flat;
|
||||
passMesh.concave_color = flat;
|
||||
passMesh.flat_color = flat;
|
||||
|
|
@ -175,7 +178,7 @@ static void SubmitBatches( int width, int height, const Mat4* view, const Mat4*
|
|||
edge_ub_pass_t passHull = { 0 };
|
||||
|
||||
Vec4 hullEdgeColor = { 0.5f, 0.5f, 0.5f, 0.5f };
|
||||
Vec4 hull = Premultiply( hullEdgeColor );
|
||||
Vec4 hull = Premultiply( hullEdgeColor, params->alphaScale );
|
||||
passHull.convex_color = hull;
|
||||
passHull.concave_color = hull;
|
||||
passHull.flat_color = hull;
|
||||
|
|
|
|||
|
|
@ -6,18 +6,14 @@
|
|||
// into two submission paths to match the silhouette quality of the
|
||||
// rest of the scene:
|
||||
//
|
||||
// Opaque path (RenderEdgesInMSAA): opaque-arena batches (meshes,
|
||||
// heightfields, opaque hulls if policy 1b is ever relaxed). Draws
|
||||
// inside the caller's currently-open MSAA scene pass, picking up the
|
||||
// same 4x MSAA as the opaque shapes. Pipeline tracks scene_target's
|
||||
// color/depth formats and sample_count.
|
||||
// Opaque path (RenderEdgesInMSAA): opaque-arena batches (meshes, heightfields, opaque hulls). Draws inside the caller's
|
||||
// currently-open MSAA scene pass, picking up the same 4x MSAA as the opaque shapes. Pipeline tracks scene_target's
|
||||
// color/depth formats and sample_count.
|
||||
//
|
||||
// Transparent path (RenderEdgesPostTransparent): transparent-arena batches
|
||||
// (hulls per policy 1b). Opens its own single-sample pass against the
|
||||
// resolved scene color + GTAO prepass depth, so edges sit on top of the
|
||||
// transparent draws that have already blended into the resolve. MSAA
|
||||
// isn't available here (the resolve already happened), the FS's
|
||||
// fwidth-based AA does what it can.
|
||||
// Transparent path (RenderEdgesPostTransparent): transparent-arena batches (just hulls). Opens its own single-sample
|
||||
// pass against the resolved scene color + GTAO prepass depth, so edges sit on top of the transparent draws that have
|
||||
// already blended into the resolve. MSAA isn't available here (the resolve already happened), the FS's fwidth-based AA
|
||||
// does what it can.
|
||||
|
||||
#pragma once
|
||||
|
||||
|
|
@ -43,6 +39,7 @@ typedef struct EdgeOverlayParams
|
|||
Vec4 convexColor; // straight (non-premultiplied) linear RGBA, premultiplied inside
|
||||
Vec4 concaveColor;
|
||||
Vec4 flatColor;
|
||||
float alphaScale; // multiplies the alpha of every edge color, clamped to 1
|
||||
} EdgeOverlayParams;
|
||||
|
||||
EdgeOverlayParams GetDefaultEdgeParams( void );
|
||||
|
|
|
|||
|
|
@ -126,6 +126,7 @@ void SampleContext::Save()
|
|||
fprintf( file, " \"drawDistance\": %g,\n", drawDistance );
|
||||
fprintf( file, " \"showHullEdges\": %s,\n", GetEdgeOverlayParams().showHulls ? "true" : "false" );
|
||||
fprintf( file, " \"showEdgeConvexity\": %s,\n", GetEdgeOverlayParams().showEdgeConvexity ? "true" : "false" );
|
||||
fprintf( file, " \"edgeAlpha\": %g,\n", GetEdgeOverlayParams().alphaScale );
|
||||
fprintf( file, " \"showMetrics\": %s,\n", showMetrics ? "true" : "false" );
|
||||
fprintf( file, " \"showProfile\": %s,\n", showProfile ? "true" : "false" );
|
||||
fprintf( file, " \"replayKeyframeBudgetMB\": %d,\n", replayKeyframeBudgetMB );
|
||||
|
|
@ -274,6 +275,12 @@ void SampleContext::Load()
|
|||
p.showEdgeConvexity = strncmp( s, "true", 4 ) == 0;
|
||||
SetEdgeOverlayParams( &p );
|
||||
}
|
||||
else if ( jsoneq( data, &tokens[i], "edgeAlpha" ) == 0 )
|
||||
{
|
||||
EdgeOverlayParams p = GetEdgeOverlayParams();
|
||||
p.alphaScale = b3ClampFloat( ParseFloat( data, tokens[i + 1] ), 0.0f, 4.0f );
|
||||
SetEdgeOverlayParams( &p );
|
||||
}
|
||||
else if ( jsoneq( data, &tokens[i], "showMetrics" ) == 0 )
|
||||
{
|
||||
const char* s = data + tokens[i + 1].start;
|
||||
|
|
@ -1376,8 +1383,52 @@ void Sample::DrawTextLine( const char* text, ... )
|
|||
char buffer[512];
|
||||
vsnprintf( buffer, sizeof( buffer ), text, args );
|
||||
va_end( args );
|
||||
DrawScreenString( m_textX, m_textLine, MakeColor( b3_colorWhite ), buffer );
|
||||
m_textLine += m_textIncrement;
|
||||
|
||||
// The text arena keeps 63 characters per string, so wrap long lines at spaces and indent the rest
|
||||
constexpr int capacity = 63;
|
||||
constexpr int indent = 2;
|
||||
const char* start = buffer;
|
||||
bool first = true;
|
||||
while ( true )
|
||||
{
|
||||
int width = first ? capacity : capacity - indent;
|
||||
int length = (int)strlen( start );
|
||||
int cut = length;
|
||||
if ( length > width )
|
||||
{
|
||||
cut = width;
|
||||
while ( cut > 0 && start[cut] != ' ' )
|
||||
{
|
||||
cut -= 1;
|
||||
}
|
||||
|
||||
if ( cut == 0 )
|
||||
{
|
||||
cut = width;
|
||||
}
|
||||
}
|
||||
|
||||
char line[capacity + 1];
|
||||
int offset = first ? 0 : indent;
|
||||
memset( line, ' ', offset );
|
||||
memcpy( line + offset, start, cut );
|
||||
line[offset + cut] = '\0';
|
||||
DrawScreenString( m_textX, m_textLine, MakeColor( b3_colorWhite ), line );
|
||||
m_textLine += m_textIncrement;
|
||||
|
||||
start += cut;
|
||||
while ( *start == ' ' )
|
||||
{
|
||||
start += 1;
|
||||
}
|
||||
|
||||
if ( *start == '\0' )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
|
||||
SampleEntry g_sampleEntries[MAX_SAMPLES];
|
||||
|
|
@ -1712,6 +1763,11 @@ static void DrawRenderMenu( SampleContext& ctx )
|
|||
ImGui::Separator();
|
||||
|
||||
ImGui::PushItemWidth( 8.0f * ImGui::GetFontSize() );
|
||||
if ( ImGui::SliderFloat( "Edge Alpha", &edgeParams.alphaScale, 0.0f, 4.0f, "%.2f" ) )
|
||||
{
|
||||
SetEdgeOverlayParams( &edgeParams );
|
||||
}
|
||||
|
||||
float ev = GetExposure();
|
||||
if ( ImGui::SliderFloat( "Exposure", &ev, -8.0f, 4.0f, "%.2f" ) )
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2900,6 +2900,7 @@ public:
|
|||
e_random = 0,
|
||||
e_circle = 1,
|
||||
e_sliver = 2,
|
||||
e_grid = 3,
|
||||
};
|
||||
|
||||
static Sample* Create( SampleContext* context )
|
||||
|
|
@ -2923,6 +2924,7 @@ public:
|
|||
m_pointCount = 20;
|
||||
m_drawScale = 1.0f;
|
||||
m_drawLabels = true;
|
||||
m_hullFlags = 0;
|
||||
|
||||
Generate();
|
||||
}
|
||||
|
|
@ -2961,6 +2963,20 @@ public:
|
|||
m_inputPoints[i].originalIndex = i;
|
||||
}
|
||||
}
|
||||
else if ( m_sourceMode == e_grid )
|
||||
{
|
||||
// Every border point is collinear with its neighbors, so the hull keeps them only with
|
||||
// the collinear flag
|
||||
m_drawScale = 1.0f;
|
||||
m_inputCount = 36;
|
||||
|
||||
for ( int i = 0; i < m_inputCount; ++i )
|
||||
{
|
||||
m_inputPoints[i].p = { -5.0f + 2.0f * (float)( i % 6 ), -5.0f + 2.0f * (float)( i / 6 ) };
|
||||
m_inputPoints[i].separation = 0.0f;
|
||||
m_inputPoints[i].originalIndex = i;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// A near degenerate sliver with a duplicate pair. Welding and collinear removal have
|
||||
|
|
@ -2998,7 +3014,7 @@ public:
|
|||
scratch[i] = m_inputPoints[i];
|
||||
}
|
||||
|
||||
m_hullCount = b3Hull2D( scratch, m_inputCount, m_hullPoints );
|
||||
m_hullCount = b3Hull2D( scratch, m_inputCount, m_hullPoints, m_hullFlags );
|
||||
|
||||
for ( int i = 0; i < m_hullCount; ++i )
|
||||
{
|
||||
|
|
@ -3010,13 +3026,13 @@ public:
|
|||
|
||||
bool DrawControls() override
|
||||
{
|
||||
const char* modes[] = { "Random", "Circle", "Sliver" };
|
||||
const char* modes[] = { "Random", "Circle", "Sliver", "Grid" };
|
||||
if ( ImGui::Combo( "Source", &m_sourceMode, modes, IM_ARRAYSIZE( modes ) ) )
|
||||
{
|
||||
Generate();
|
||||
}
|
||||
|
||||
if ( m_sourceMode != e_sliver )
|
||||
if ( m_sourceMode == e_random || m_sourceMode == e_circle )
|
||||
{
|
||||
if ( ImGui::SliderInt( "Point Count", &m_pointCount, 4, m_pointCapacity ) )
|
||||
{
|
||||
|
|
@ -3033,6 +3049,8 @@ public:
|
|||
}
|
||||
|
||||
ImGui::SliderInt( "Target Count", &m_targetCount, 3, m_inputCount );
|
||||
ImGui::CheckboxFlags( "Keep Collinear", &m_hullFlags, b3_hull2DKeepCollinear );
|
||||
ImGui::CheckboxFlags( "Exact Merge", &m_hullFlags, b3_hull2DExactMerge );
|
||||
ImGui::Checkbox( "Draw Labels", &m_drawLabels );
|
||||
|
||||
return true;
|
||||
|
|
@ -3110,6 +3128,7 @@ public:
|
|||
int m_simplifiedCount;
|
||||
int m_targetCount;
|
||||
int m_pointCount;
|
||||
int m_hullFlags;
|
||||
bool m_drawLabels;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include "gfx/debug_adapter.h"
|
||||
#include "gfx/draw.h"
|
||||
#include "imgui.h"
|
||||
#include "mesh_drop.h"
|
||||
#include "sample.h"
|
||||
#include "utils.h"
|
||||
|
||||
|
|
@ -387,38 +388,9 @@ public:
|
|||
|
||||
static int sampleNeedleMesh = RegisterSample( "Continuous", "Needle Mesh", NeedleMesh::Create );
|
||||
|
||||
struct IndexPair
|
||||
{
|
||||
int index1;
|
||||
int index2;
|
||||
};
|
||||
|
||||
static inline IndexPair ConvertToPair( void* userData )
|
||||
{
|
||||
static_assert( sizeof( intptr_t ) >= 8 && sizeof( int ) == 4 );
|
||||
intptr_t value = (intptr_t)userData;
|
||||
int index1 = (int)value;
|
||||
int index2 = (int)( value >> 32 );
|
||||
return { index1, index2 };
|
||||
}
|
||||
|
||||
static inline void* ConvertToUserData( IndexPair pair )
|
||||
{
|
||||
intptr_t value = (intptr_t)pair.index2 << 32 | (intptr_t)pair.index1;
|
||||
return (void*)value;
|
||||
}
|
||||
|
||||
class MeshDrop : public Sample
|
||||
{
|
||||
public:
|
||||
enum ShapeType
|
||||
{
|
||||
e_box,
|
||||
e_capsule,
|
||||
e_cylinder,
|
||||
e_sphere,
|
||||
};
|
||||
|
||||
explicit MeshDrop( SampleContext* context )
|
||||
: Sample( context )
|
||||
{
|
||||
|
|
@ -428,20 +400,21 @@ public:
|
|||
GetGuiDraw()->forceScale = 0.1f;
|
||||
}
|
||||
|
||||
m_settings = GetDefaultMeshDropSettings();
|
||||
m_groundId = b3_nullBodyId;
|
||||
m_groundMesh = nullptr;
|
||||
m_groundAmplitude = 0.5f;
|
||||
CreateGround();
|
||||
|
||||
m_bodies = new b3BodyId[m_bodyCount];
|
||||
memset( m_bodies, 0, m_bodyCount * sizeof( b3BodyId ) );
|
||||
for ( int i = 0; i < MESH_DROP_BODY_COUNT; ++i )
|
||||
{
|
||||
m_bodies[i] = b3_nullBodyId;
|
||||
}
|
||||
|
||||
m_cylinder = b3CreateCylinder( 0.4f, 0.05f, 0.0f, 6 );
|
||||
m_shapeType = e_box;
|
||||
m_cylinder = CreateMeshDropCylinder();
|
||||
m_seed = 0;
|
||||
m_runCount = 0;
|
||||
m_failure = false;
|
||||
m_autoGenerate = false;
|
||||
m_collide = true;
|
||||
m_stepWhilePaused = true;
|
||||
|
||||
Generate();
|
||||
|
|
@ -449,7 +422,6 @@ public:
|
|||
|
||||
~MeshDrop() override
|
||||
{
|
||||
delete[] m_bodies;
|
||||
b3DestroyHull( m_cylinder );
|
||||
b3DestroyMesh( m_groundMesh );
|
||||
}
|
||||
|
|
@ -468,58 +440,13 @@ public:
|
|||
m_groundMesh = nullptr;
|
||||
}
|
||||
|
||||
b3BodyDef bodyDef = b3DefaultBodyDef();
|
||||
m_groundId = b3CreateBody( m_worldId, &bodyDef );
|
||||
|
||||
int gridCount = 40;
|
||||
float cellWidth = 1.0f;
|
||||
float rowHz = 0.1f;
|
||||
float columnHz = 0.2f;
|
||||
|
||||
m_groundMesh = b3CreateWaveMesh( gridCount, gridCount, cellWidth, m_groundAmplitude, rowHz, columnHz );
|
||||
b3ShapeDef shapeDef = b3DefaultShapeDef();
|
||||
shapeDef.filter.categoryBits = 1;
|
||||
b3CreateMeshShape( m_groundId, &shapeDef, m_groundMesh, b3Vec3_one );
|
||||
|
||||
float extent = 0.5f * gridCount * cellWidth;
|
||||
float halfHeight = 1.0f;
|
||||
|
||||
{
|
||||
b3Transform transform;
|
||||
transform.p = { 0.0f, halfHeight, -extent };
|
||||
transform.q = b3Quat_identity;
|
||||
b3BoxHull wallBox = b3MakeTransformedBoxHull( extent, halfHeight, 0.1f, transform );
|
||||
b3CreateHullShape( m_groundId, &shapeDef, &wallBox.base );
|
||||
}
|
||||
|
||||
{
|
||||
b3Transform transform;
|
||||
transform.p = { 0.0f, halfHeight, extent };
|
||||
transform.q = b3Quat_identity;
|
||||
b3BoxHull wallBox = b3MakeTransformedBoxHull( extent, halfHeight, 0.1f, transform );
|
||||
b3CreateHullShape( m_groundId, &shapeDef, &wallBox.base );
|
||||
}
|
||||
|
||||
{
|
||||
b3Transform transform;
|
||||
transform.p = { -extent, halfHeight, 0.0f };
|
||||
transform.q = b3Quat_identity;
|
||||
b3BoxHull wallBox = b3MakeTransformedBoxHull( 0.1f, halfHeight, extent, transform );
|
||||
b3CreateHullShape( m_groundId, &shapeDef, &wallBox.base );
|
||||
}
|
||||
|
||||
{
|
||||
b3Transform transform;
|
||||
transform.p = { extent, halfHeight, 0.0f };
|
||||
transform.q = b3Quat_identity;
|
||||
b3BoxHull wallBox = b3MakeTransformedBoxHull( 0.1f, halfHeight, extent, transform );
|
||||
b3CreateHullShape( m_groundId, &shapeDef, &wallBox.base );
|
||||
}
|
||||
m_groundMesh = CreateMeshDropMesh( m_settings.amplitude );
|
||||
m_groundId = CreateMeshDropGround( m_worldId, m_groundMesh );
|
||||
}
|
||||
|
||||
void Generate()
|
||||
{
|
||||
for ( int i = 0; i < m_bodyCount; ++i )
|
||||
for ( int i = 0; i < MESH_DROP_BODY_COUNT; ++i )
|
||||
{
|
||||
if ( B3_IS_NULL( m_bodies[i] ) )
|
||||
{
|
||||
|
|
@ -530,107 +457,53 @@ public:
|
|||
m_bodies[i] = b3_nullBodyId;
|
||||
}
|
||||
|
||||
// The soft contact solver cannot always resolve this small shape at 4 sub-steps.
|
||||
// Also this small shape has trouble moving advancing in the time of impact code
|
||||
// because the size is very close to the tolerances used.
|
||||
// b3BoxHull box = b3MakeBoxHull( 0.01f, 0.1f, 0.02f );
|
||||
b3BoxHull box = b3MakeBoxHull( 0.02f, 0.2f, 0.04f );
|
||||
b3Capsule capsule = { { 0.0f, -0.2f, 0.0f }, { 0.0f, 0.2f, 0.0f }, 0.05f };
|
||||
b3Sphere sphere = { b3Vec3_zero, 0.05f };
|
||||
|
||||
int bodyIndex = 0;
|
||||
|
||||
b3BodyDef bodyDef = b3DefaultBodyDef();
|
||||
bodyDef.type = b3_dynamicBody;
|
||||
|
||||
b3ShapeDef shapeDef = b3DefaultShapeDef();
|
||||
shapeDef.baseMaterial.rollingResistance = m_shapeType == e_capsule ? 0.4f : 0.1f;
|
||||
|
||||
// Don't allow shapes to collide with each other. This
|
||||
// makes isolating failures easier.
|
||||
if ( m_collide == false )
|
||||
{
|
||||
shapeDef.filter.categoryBits = 2;
|
||||
shapeDef.filter.maskBits = 1;
|
||||
}
|
||||
|
||||
g_randomSeed = (uint32_t)b3GetTicks();
|
||||
|
||||
bool simulateAll = true;
|
||||
// g_randomSeed = 1910133196;
|
||||
// A non-zero seed replays a generation reported by the mesh_soak tool
|
||||
m_seed = m_replaySeed != 0 ? m_replaySeed : (uint32_t)b3GetTicks();
|
||||
|
||||
m_runCount += 1;
|
||||
m_stepCount = 0;
|
||||
printf( "run %d seed %u\n", m_runCount, g_randomSeed );
|
||||
printf( "run %d seed %u\n", m_runCount, m_seed );
|
||||
|
||||
for ( int i = 0; i < m_gridCount; ++i )
|
||||
MeshDropSettings settings = m_settings;
|
||||
if ( m_solo[0] >= 0 && m_solo[1] >= 0 )
|
||||
{
|
||||
for ( int j = 0; j < m_gridCount; ++j )
|
||||
{
|
||||
b3Vec3 linearVelocity = RandomVec3Uniform( -1.0f, 1.0f );
|
||||
b3Vec3 angularVelocity = RandomVec3Uniform( -5.0f, 5.0f );
|
||||
|
||||
if ( simulateAll || ( i == 19 && j == 20 ) )
|
||||
{
|
||||
bodyDef.position = { 0.5f * ( i - 0.5f * m_gridCount ), 5.0f, 0.5f * ( j - 0.5f * m_gridCount ) };
|
||||
bodyDef.linearVelocity = linearVelocity;
|
||||
bodyDef.angularVelocity = angularVelocity;
|
||||
// bodyDef.angularDamping = 0.1f;
|
||||
bodyDef.userData = ConvertToUserData( { i, j } );
|
||||
b3BodyId bodyId = b3CreateBody( m_worldId, &bodyDef );
|
||||
|
||||
if ( m_shapeType == e_box )
|
||||
{
|
||||
b3CreateHullShape( bodyId, &shapeDef, &box.base );
|
||||
}
|
||||
else if ( m_shapeType == e_capsule )
|
||||
{
|
||||
b3CreateCapsuleShape( bodyId, &shapeDef, &capsule );
|
||||
}
|
||||
else if ( m_shapeType == e_cylinder )
|
||||
{
|
||||
b3CreateHullShape( bodyId, &shapeDef, m_cylinder );
|
||||
}
|
||||
else
|
||||
{
|
||||
b3CreateSphereShape( bodyId, &shapeDef, &sphere );
|
||||
}
|
||||
|
||||
m_bodies[bodyIndex] = bodyId;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_bodies[bodyIndex] = b3_nullBodyId;
|
||||
}
|
||||
bodyIndex += 1;
|
||||
}
|
||||
settings.soloIndex = MESH_DROP_GRID_COUNT * m_solo[0] + m_solo[1];
|
||||
}
|
||||
|
||||
assert( bodyIndex == m_bodyCount );
|
||||
CreateMeshDropBodies( m_worldId, settings, m_seed, m_cylinder, m_bodies );
|
||||
ResetMeshDropDepth( &m_depth, settings, m_cylinder );
|
||||
}
|
||||
|
||||
bool DrawControls() override
|
||||
{
|
||||
const char* shapeTypes[] = { "box", "capsule", "cylinder", "sphere" };
|
||||
int shapeType = (int)m_shapeType;
|
||||
if ( ImGui::Combo( "Type", &shapeType, shapeTypes, IM_ARRAYSIZE( shapeTypes ) ) )
|
||||
int shapeType = (int)m_settings.shape;
|
||||
if ( ImGui::Combo( "Type", &shapeType, g_meshDropShapeNames, e_meshDropShapeCount ) )
|
||||
{
|
||||
m_stepCount = 0;
|
||||
m_shapeType = ShapeType( shapeType );
|
||||
m_settings.shape = MeshDropShape( shapeType );
|
||||
Generate();
|
||||
}
|
||||
|
||||
if ( ImGui::SliderFloat( "Amplitude", &m_groundAmplitude, 0.0f, 1.0f ) )
|
||||
if ( ImGui::SliderFloat( "Amplitude", &m_settings.amplitude, 0.0f, 1.0f ) )
|
||||
{
|
||||
CreateGround();
|
||||
Generate();
|
||||
}
|
||||
|
||||
if ( ImGui::Checkbox( "Collide", &m_collide ) )
|
||||
if ( ImGui::Checkbox( "Collide", &m_settings.collide ) )
|
||||
{
|
||||
Generate();
|
||||
}
|
||||
|
||||
ImGui::InputScalar( "Seed", ImGuiDataType_U32, &m_replaySeed );
|
||||
|
||||
// Drop only the body at these indices, -1 for all
|
||||
if ( ImGui::InputInt2( "Solo", m_solo ) )
|
||||
{
|
||||
m_solo[0] = b3ClampInt( m_solo[0], -1, MESH_DROP_GRID_COUNT - 1 );
|
||||
m_solo[1] = b3ClampInt( m_solo[1], -1, MESH_DROP_GRID_COUNT - 1 );
|
||||
}
|
||||
|
||||
if ( ImGui::Button( "Generate" ) )
|
||||
{
|
||||
Generate();
|
||||
|
|
@ -647,8 +520,14 @@ public:
|
|||
|
||||
void Step() override
|
||||
{
|
||||
int stepCount = m_stepCount;
|
||||
Sample::Step();
|
||||
|
||||
if ( m_stepCount != stepCount )
|
||||
{
|
||||
UpdateMeshDropDepth( m_worldId, &m_depth );
|
||||
}
|
||||
|
||||
{
|
||||
PickRay pickRay = m_camera->BuildPickRay( m_context->mouseX, m_context->mouseY );
|
||||
|
||||
|
|
@ -657,13 +536,25 @@ public:
|
|||
if ( result.hit )
|
||||
{
|
||||
b3BodyId bodyId = b3Shape_GetBody( result.shapeId );
|
||||
void* userData = b3Body_GetUserData( bodyId );
|
||||
IndexPair pair = ConvertToPair( userData );
|
||||
DrawTextLine( "indices: (%d, %d)\n", pair.index1, pair.index2 );
|
||||
int index = GetMeshDropBodyIndex( b3Body_GetUserData( bodyId ) );
|
||||
if ( index >= 0 )
|
||||
{
|
||||
DrawTextLine( "indices: (%d, %d)", index / MESH_DROP_GRID_COUNT, index % MESH_DROP_GRID_COUNT );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for ( int i = 0; i < m_bodyCount && m_failure == false; i += 1 )
|
||||
DrawTextLine( "seed %u", m_seed );
|
||||
|
||||
if ( m_depth.maxIndex >= 0 )
|
||||
{
|
||||
int index = m_depth.maxIndex;
|
||||
DrawTextLine( "deepest: (%d, %d) %.1f slop at step %d", index / MESH_DROP_GRID_COUNT, index % MESH_DROP_GRID_COUNT,
|
||||
m_depth.maxDepth / B3_LINEAR_SLOP, m_depth.maxStep );
|
||||
}
|
||||
|
||||
float tunnelHeight = GetMeshDropTunnelHeight();
|
||||
for ( int i = 0; i < MESH_DROP_BODY_COUNT && m_failure == false; i += 1 )
|
||||
{
|
||||
b3BodyId bodyId = m_bodies[i];
|
||||
if ( B3_IS_NULL( bodyId ) )
|
||||
|
|
@ -672,19 +563,14 @@ public:
|
|||
}
|
||||
|
||||
b3Pos massCenter = b3Body_GetWorldCenter( bodyId );
|
||||
if ( massCenter.y < -2.0f )
|
||||
if ( massCenter.y < tunnelHeight )
|
||||
{
|
||||
IndexPair pair = ConvertToPair( b3Body_GetUserData( bodyId ) );
|
||||
printf( "index1: %d - index2: %d\n", pair.index1, pair.index2 );
|
||||
printf( "index1: %d - index2: %d\n", i / MESH_DROP_GRID_COUNT, i % MESH_DROP_GRID_COUNT );
|
||||
printf( "(%6.2f, %6.2f, %6.2f)\n", massCenter.x, massCenter.y, massCenter.z );
|
||||
m_context->pause = true;
|
||||
m_failure = true;
|
||||
m_autoGenerate = false;
|
||||
}
|
||||
|
||||
// This is for debugging the fallback inner sphere
|
||||
// b3Sphere sphere = {massCenter, 0.015f};
|
||||
// DrawSphere( m_scene, b3Transform_identity, sphere, b3_colorLightGray );
|
||||
}
|
||||
|
||||
if ( m_autoGenerate )
|
||||
|
|
@ -709,13 +595,13 @@ public:
|
|||
for ( int i = 0; i < n; ++i )
|
||||
{
|
||||
b3World_Step( m_worldId, timeStep, m_context->subStepCount );
|
||||
UpdateMeshDropDepth( m_worldId, &m_depth );
|
||||
}
|
||||
|
||||
m_stepCount += n;
|
||||
}
|
||||
|
||||
int maxSteps = m_shapeType == e_capsule ? 3000 : 1000;
|
||||
if ( m_stepCount > maxSteps )
|
||||
if ( m_stepCount > GetMeshDropStepLimit( m_settings.shape ) )
|
||||
{
|
||||
m_context->pause = true;
|
||||
m_failure = true;
|
||||
|
|
@ -729,20 +615,18 @@ public:
|
|||
return new MeshDrop( context );
|
||||
}
|
||||
|
||||
static constexpr int m_gridCount = 32;
|
||||
// static constexpr int m_gridCount = 3;
|
||||
static constexpr int m_bodyCount = m_gridCount * m_gridCount;
|
||||
|
||||
MeshDropSettings m_settings;
|
||||
MeshDropDepth m_depth;
|
||||
b3MeshData* m_groundMesh;
|
||||
float m_groundAmplitude;
|
||||
b3BodyId m_groundId;
|
||||
b3HullData* m_cylinder;
|
||||
b3BodyId* m_bodies;
|
||||
ShapeType m_shapeType;
|
||||
b3BodyId m_bodies[MESH_DROP_BODY_COUNT];
|
||||
uint32_t m_seed;
|
||||
int m_runCount;
|
||||
bool m_failure;
|
||||
bool m_autoGenerate;
|
||||
bool m_collide;
|
||||
uint32_t m_replaySeed = 0;
|
||||
int m_solo[2] = { -1, -1 };
|
||||
};
|
||||
|
||||
static int sampleMeshDrop = RegisterSample( "Continuous", "Mesh Drop", MeshDrop::Create );
|
||||
|
|
|
|||
3749
samples/sample_ghost.cpp
Normal file
3749
samples/sample_ghost.cpp
Normal file
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -2320,6 +2320,8 @@ public:
|
|||
m_upperSteeringDegrees = 45.0f;
|
||||
m_maxSteeringTorque = 5.0f;
|
||||
m_targetSteeringDegrees = 0.0f;
|
||||
m_wheelType = WheelType::sphere;
|
||||
m_cylinderSides = 16;
|
||||
|
||||
b3BodyId groundId;
|
||||
{
|
||||
|
|
@ -2371,15 +2373,10 @@ public:
|
|||
b3CreateParallelJoint( m_worldId, ¶llelJointDef );
|
||||
}
|
||||
|
||||
shapeDef.density = 2.0f;
|
||||
shapeDef.baseMaterial.friction = 3.0f;
|
||||
|
||||
bodyDef.type = b3_dynamicBody;
|
||||
bodyDef.allowFastRotation = true;
|
||||
bodyDef.rotation = b3ComputeQuatBetweenUnitVectors( b3Vec3_axisY, b3Vec3_axisZ );
|
||||
|
||||
// b3HullData* hull = b3CreateCylinder( 0.25f, 0.4f, 0.0f, 16 );
|
||||
|
||||
b3WheelJointDef jointDef = b3DefaultWheelJointDef();
|
||||
jointDef.base.bodyIdA = m_chassisId;
|
||||
jointDef.base.localFrameA.q = b3ComputeQuatBetweenUnitVectors( b3Vec3_axisX, b3Vec3_axisY );
|
||||
|
|
@ -2401,15 +2398,11 @@ public:
|
|||
jointDef.lowerSteeringLimit = B3_PI / 180.0f * m_lowerSteeringDegrees;
|
||||
jointDef.upperSteeringLimit = B3_PI / 180.0f * m_upperSteeringDegrees;
|
||||
|
||||
b3Sphere sphere = { b3Vec3_zero, 0.4f };
|
||||
|
||||
{
|
||||
bodyDef.position = { 1.5f, 2.0f, 0.8f };
|
||||
b3BodyId bodyId = b3CreateBody( m_worldId, &bodyDef );
|
||||
b3CreateSphereShape( bodyId, &shapeDef, &sphere );
|
||||
// b3CreateHullShape( bodyId, &shapeDef, hull );
|
||||
m_wheelIds[0] = b3CreateBody( m_worldId, &bodyDef );
|
||||
|
||||
jointDef.base.bodyIdB = bodyId;
|
||||
jointDef.base.bodyIdB = m_wheelIds[0];
|
||||
jointDef.base.localFrameA.p = { 1.5f, -0.5f, 0.8f };
|
||||
jointDef.enableSteering = true;
|
||||
jointDef.enableSpinMotor = false;
|
||||
|
|
@ -2418,11 +2411,9 @@ public:
|
|||
|
||||
{
|
||||
bodyDef.position = { 1.5f, 2.0f, -0.8f };
|
||||
b3BodyId bodyId = b3CreateBody( m_worldId, &bodyDef );
|
||||
b3CreateSphereShape( bodyId, &shapeDef, &sphere );
|
||||
// b3CreateHullShape( bodyId, &shapeDef, hull );
|
||||
m_wheelIds[1] = b3CreateBody( m_worldId, &bodyDef );
|
||||
|
||||
jointDef.base.bodyIdB = bodyId;
|
||||
jointDef.base.bodyIdB = m_wheelIds[1];
|
||||
jointDef.base.localFrameA.p = { 1.5f, -0.5f, -0.8f };
|
||||
jointDef.enableSteering = true;
|
||||
jointDef.enableSpinMotor = false;
|
||||
|
|
@ -2431,11 +2422,9 @@ public:
|
|||
|
||||
{
|
||||
bodyDef.position = { -1.5f, 2.0f, 0.8f };
|
||||
b3BodyId bodyId = b3CreateBody( m_worldId, &bodyDef );
|
||||
b3CreateSphereShape( bodyId, &shapeDef, &sphere );
|
||||
// b3CreateHullShape( bodyId, &shapeDef, hull );
|
||||
m_wheelIds[2] = b3CreateBody( m_worldId, &bodyDef );
|
||||
|
||||
jointDef.base.bodyIdB = bodyId;
|
||||
jointDef.base.bodyIdB = m_wheelIds[2];
|
||||
jointDef.base.localFrameA.p = { -1.5f, -0.5f, 0.8f };
|
||||
jointDef.enableSteering = false;
|
||||
jointDef.enableSpinMotor = true;
|
||||
|
|
@ -2444,18 +2433,21 @@ public:
|
|||
|
||||
{
|
||||
bodyDef.position = { -1.5f, 2.0f, -0.8f };
|
||||
b3BodyId bodyId = b3CreateBody( m_worldId, &bodyDef );
|
||||
b3CreateSphereShape( bodyId, &shapeDef, &sphere );
|
||||
// b3CreateHullShape( bodyId, &shapeDef, hull );
|
||||
m_wheelIds[3] = b3CreateBody( m_worldId, &bodyDef );
|
||||
|
||||
jointDef.base.bodyIdB = bodyId;
|
||||
jointDef.base.bodyIdB = m_wheelIds[3];
|
||||
jointDef.base.localFrameA.p = { -1.5f, -0.5f, -0.8f };
|
||||
jointDef.enableSteering = false;
|
||||
jointDef.enableSpinMotor = true;
|
||||
m_rearRightId = b3CreateWheelJoint( m_worldId, &jointDef );
|
||||
}
|
||||
|
||||
// b3DestroyHull( hull );
|
||||
for ( int i = 0; i < 4; ++i )
|
||||
{
|
||||
m_wheelShapeIds[i] = b3_nullShapeId;
|
||||
}
|
||||
|
||||
CreateWheelShapes();
|
||||
|
||||
m_camera->m_thirdPerson = false;
|
||||
|
||||
|
|
@ -2474,6 +2466,59 @@ public:
|
|||
b3DestroyHeightField( m_heightField );
|
||||
}
|
||||
|
||||
void CreateWheelShapes()
|
||||
{
|
||||
b3ShapeDef shapeDef = b3DefaultShapeDef();
|
||||
shapeDef.density = 2.0f;
|
||||
shapeDef.baseMaterial.friction = 3.0f;
|
||||
|
||||
float radius = 0.4f;
|
||||
float width = 0.25f;
|
||||
|
||||
b3HullData* cylinder = nullptr;
|
||||
if ( m_wheelType == WheelType::cylinder )
|
||||
{
|
||||
float w = 1.5f * width;
|
||||
cylinder = b3CreateCylinder( w, radius, -0.5f * w, m_cylinderSides );
|
||||
}
|
||||
|
||||
for ( int i = 0; i < 4; ++i )
|
||||
{
|
||||
if ( B3_IS_NON_NULL( m_wheelShapeIds[i] ) )
|
||||
{
|
||||
b3DestroyShape( m_wheelShapeIds[i], false );
|
||||
}
|
||||
|
||||
b3BodyId bodyId = m_wheelIds[i];
|
||||
|
||||
switch ( m_wheelType )
|
||||
{
|
||||
case WheelType::sphere:
|
||||
{
|
||||
b3Sphere sphere = { b3Vec3_zero, radius };
|
||||
m_wheelShapeIds[i] = b3CreateSphereShape( bodyId, &shapeDef, &sphere );
|
||||
}
|
||||
break;
|
||||
|
||||
case WheelType::capsule:
|
||||
{
|
||||
b3Capsule capsule = { { 0.0f, -0.5f * width, 0.0f }, { 0.0f, 0.5f * width, 0.0f }, radius };
|
||||
m_wheelShapeIds[i] = b3CreateCapsuleShape( bodyId, &shapeDef, &capsule );
|
||||
}
|
||||
break;
|
||||
|
||||
case WheelType::cylinder:
|
||||
m_wheelShapeIds[i] = b3CreateHullShape( bodyId, &shapeDef, cylinder );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( cylinder != nullptr )
|
||||
{
|
||||
b3DestroyHull( cylinder );
|
||||
}
|
||||
}
|
||||
|
||||
void Keyboard( int key, int action, int mods ) override
|
||||
{
|
||||
if ( key == KEY_T && action == ACTION_PRESS )
|
||||
|
|
@ -2484,6 +2529,32 @@ public:
|
|||
|
||||
bool DrawControls() override
|
||||
{
|
||||
ImGui::Text( "Wheels" );
|
||||
if ( ImGui::RadioButton( "Sphere", m_wheelType == WheelType::sphere ) )
|
||||
{
|
||||
m_wheelType = WheelType::sphere;
|
||||
CreateWheelShapes();
|
||||
}
|
||||
|
||||
if ( ImGui::RadioButton( "Capsule", m_wheelType == WheelType::capsule ) )
|
||||
{
|
||||
m_wheelType = WheelType::capsule;
|
||||
CreateWheelShapes();
|
||||
}
|
||||
|
||||
if ( ImGui::RadioButton( "Cylinder", m_wheelType == WheelType::cylinder ) )
|
||||
{
|
||||
m_wheelType = WheelType::cylinder;
|
||||
CreateWheelShapes();
|
||||
}
|
||||
|
||||
if ( ImGui::SliderInt( "Sides", &m_cylinderSides, 3, 32 ) && m_wheelType == WheelType::cylinder )
|
||||
{
|
||||
CreateWheelShapes();
|
||||
}
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
ImGui::Text( "Suspension" );
|
||||
if ( ImGui::SliderFloat( "Min##Suspension", &m_lowerTranslation, -10.0f, 10.0f, "%.1f" ) )
|
||||
{
|
||||
|
|
@ -2659,8 +2730,19 @@ public:
|
|||
return new Driving( context );
|
||||
}
|
||||
|
||||
enum class WheelType
|
||||
{
|
||||
sphere,
|
||||
capsule,
|
||||
cylinder,
|
||||
};
|
||||
|
||||
b3HeightFieldData* m_heightField;
|
||||
b3BodyId m_chassisId;
|
||||
b3BodyId m_wheelIds[4];
|
||||
b3ShapeId m_wheelShapeIds[4];
|
||||
WheelType m_wheelType;
|
||||
int m_cylinderSides;
|
||||
b3JointId m_frontLeftId;
|
||||
b3JointId m_frontRightId;
|
||||
b3JointId m_rearLeftId;
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -10,9 +10,13 @@
|
|||
|
||||
#include "box3d/box3d.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <float.h>
|
||||
#include <imgui.h>
|
||||
#include <queue>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <vector>
|
||||
|
||||
enum class ShapeType
|
||||
{
|
||||
|
|
@ -1621,3 +1625,4 @@ public:
|
|||
};
|
||||
|
||||
static int sampleHollowBox = RegisterSample( "Mesh", "Hollow Box", HollowBox::Create );
|
||||
|
||||
|
|
|
|||
|
|
@ -5,8 +5,14 @@ set(BOX3D_SHARED_FILES
|
|||
benchmarks.h
|
||||
determinism.c
|
||||
determinism.h
|
||||
ghost_collisions.c
|
||||
ghost_collisions.h
|
||||
ghost_oracle.c
|
||||
ghost_oracle.h
|
||||
human.c
|
||||
human.h
|
||||
mesh_drop.c
|
||||
mesh_drop.h
|
||||
overflow_color.c
|
||||
overflow_color.h
|
||||
stability.c
|
||||
|
|
|
|||
867
shared/ghost_collisions.c
Normal file
867
shared/ghost_collisions.c
Normal file
|
|
@ -0,0 +1,867 @@
|
|||
// SPDX-FileCopyrightText: 2026 Erin Catto
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "ghost_collisions.h"
|
||||
|
||||
#include "box3d/box3d.h"
|
||||
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define GHOST_HALF_LENGTH 20.0f
|
||||
#define GHOST_HALF_WIDTH 3.0f
|
||||
#define GHOST_START_X -16.0f
|
||||
|
||||
// The rail deflects the body sideways and the floor is frictionless, so a narrow floor ends the run off
|
||||
// the side instead of at the far end
|
||||
#define GHOST_RAIL_HALF_LENGTH ( 0.5f * GHOST_HALF_LENGTH )
|
||||
#define GHOST_RAIL_HALF_WIDTH ( 2.0f * GHOST_HALF_WIDTH )
|
||||
|
||||
// A run takes about 144 steps, clear of 150 where the 900 step scan would flip between 5 and 6 runs
|
||||
#define GHOST_RAIL_START_X -5.3f
|
||||
|
||||
// A 34 degree chamfer like the s&box beams
|
||||
#define GHOST_CHAMFER_WIDTH 0.05f
|
||||
#define GHOST_CHAMFER_DROP ( GHOST_CHAMFER_WIDTH / 1.5f )
|
||||
|
||||
#define GHOST_RAIL_SKIRT 0.4f
|
||||
|
||||
typedef struct PeelPreset
|
||||
{
|
||||
int columnCount;
|
||||
float scaleX;
|
||||
float startZ;
|
||||
} PeelPreset;
|
||||
|
||||
static const PeelPreset s_peelPresets[GHOST_PEEL_PRESET_COUNT] = {
|
||||
{ 4, 0.1f, -55.0f },
|
||||
{ 4, 0.1f, -54.0f },
|
||||
{ 4, 0.01f, -55.0f },
|
||||
{ 16, 0.01f, -54.0f },
|
||||
};
|
||||
|
||||
const char* g_ghostSceneNames[e_ghostSceneCount] = {
|
||||
"Flat", "Concave", "Cliff", "Crest", "Bumps", "Internal", "Chamfer", "Rail",
|
||||
};
|
||||
|
||||
const char* g_ghostBodyNames[e_ghostBodyCount] = { "Box", "H Capsule", "V Capsule", "Sphere", "Cylinder" };
|
||||
|
||||
const char* g_ghostPeelPresetNames[GHOST_PEEL_PRESET_COUNT] = {
|
||||
"4.1:-55",
|
||||
"4.1:-54",
|
||||
"4.01:-55",
|
||||
"16.01:-54",
|
||||
};
|
||||
|
||||
GhostSettings GetDefaultGhostSettings( void )
|
||||
{
|
||||
GhostSettings settings = {
|
||||
.scene = e_ghostFlat,
|
||||
.body = e_ghostBox,
|
||||
.peelPreset = 0,
|
||||
.mirror = false,
|
||||
.heightField = false,
|
||||
.cellSize = 0.25f,
|
||||
.speed = 6.0f,
|
||||
.yaw = 0.0f,
|
||||
.friction = 0.0f,
|
||||
.fixedRotation = false,
|
||||
.speculative = true,
|
||||
};
|
||||
return settings;
|
||||
}
|
||||
|
||||
typedef struct MeshBuilder
|
||||
{
|
||||
b3Vec3* vertices;
|
||||
int vertexCount;
|
||||
int32_t* indices;
|
||||
int indexCount;
|
||||
} MeshBuilder;
|
||||
|
||||
// The profile runs in +x with the solid below it. The mirror flips x in the data and the mesh
|
||||
// scale flips it back, so the world geometry is the same either way.
|
||||
static void AddGrid( MeshBuilder* builder, const b3Vec2* points, int pointCount, float halfWidth, int zCount, bool alternate,
|
||||
bool mirror )
|
||||
{
|
||||
float sign = mirror ? -1.0f : 1.0f;
|
||||
int stride = zCount + 1;
|
||||
int base = builder->vertexCount;
|
||||
|
||||
builder->vertices = realloc( builder->vertices, ( builder->vertexCount + pointCount * stride ) * sizeof( b3Vec3 ) );
|
||||
for ( int i = 0; i < pointCount; ++i )
|
||||
{
|
||||
for ( int j = 0; j <= zCount; ++j )
|
||||
{
|
||||
float z = -halfWidth + 2.0f * halfWidth * (float)j / (float)zCount;
|
||||
builder->vertices[builder->vertexCount++] = (b3Vec3){ sign * points[i].x, points[i].y, z };
|
||||
}
|
||||
}
|
||||
|
||||
int triangleCount = 2 * ( pointCount - 1 ) * zCount;
|
||||
builder->indices = realloc( builder->indices, ( builder->indexCount + 3 * triangleCount ) * sizeof( int32_t ) );
|
||||
for ( int i = 0; i + 1 < pointCount; ++i )
|
||||
{
|
||||
for ( int j = 0; j < zCount; ++j )
|
||||
{
|
||||
int a = base + i * stride + j;
|
||||
int b = a + 1;
|
||||
int c = a + stride + 1;
|
||||
int d = a + stride;
|
||||
|
||||
int corners[6] = { a, b, c, c, d, a };
|
||||
|
||||
// Alternate the diagonal like cooked level geometry
|
||||
if ( alternate && ( ( i + j ) & 1 ) )
|
||||
{
|
||||
int flipped[6] = { a, b, d, b, c, d };
|
||||
memcpy( corners, flipped, sizeof( corners ) );
|
||||
}
|
||||
|
||||
for ( int k = 0; k < 6; k += 3 )
|
||||
{
|
||||
builder->indices[builder->indexCount++] = corners[k];
|
||||
builder->indices[builder->indexCount++] = mirror ? corners[k + 2] : corners[k + 1];
|
||||
builder->indices[builder->indexCount++] = mirror ? corners[k + 1] : corners[k + 2];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void AddStrip( MeshBuilder* builder, const b3Vec2* profile, int count, float cellSize, float zCell, bool mirror )
|
||||
{
|
||||
int pointCount = 1;
|
||||
for ( int k = 0; k + 1 < count; ++k )
|
||||
{
|
||||
b3Vec2 a = profile[k];
|
||||
b3Vec2 b = profile[k + 1];
|
||||
float length = sqrtf( ( b.x - a.x ) * ( b.x - a.x ) + ( b.y - a.y ) * ( b.y - a.y ) );
|
||||
pointCount += b3MaxInt( 1, (int)ceilf( length / cellSize - 0.01f ) );
|
||||
}
|
||||
|
||||
b3Vec2* points = malloc( pointCount * sizeof( b3Vec2 ) );
|
||||
int index = 0;
|
||||
points[index++] = profile[0];
|
||||
for ( int k = 0; k + 1 < count; ++k )
|
||||
{
|
||||
b3Vec2 a = profile[k];
|
||||
b3Vec2 b = profile[k + 1];
|
||||
float length = sqrtf( ( b.x - a.x ) * ( b.x - a.x ) + ( b.y - a.y ) * ( b.y - a.y ) );
|
||||
int n = b3MaxInt( 1, (int)ceilf( length / cellSize - 0.01f ) );
|
||||
for ( int s = 1; s <= n; ++s )
|
||||
{
|
||||
float t = (float)s / (float)n;
|
||||
points[index++] = (b3Vec2){ a.x + t * ( b.x - a.x ), a.y + t * ( b.y - a.y ) };
|
||||
}
|
||||
}
|
||||
|
||||
int zCount = b3MaxInt( 1, (int)ceilf( 2.0f * GHOST_HALF_WIDTH / zCell - 0.01f ) );
|
||||
AddGrid( builder, points, pointCount, GHOST_HALF_WIDTH, zCount, true, mirror );
|
||||
free( points );
|
||||
}
|
||||
|
||||
// The rail cross section is a profile in zy extruded along x. Each quad side is its edge direction along
|
||||
// the section crossed with x, which is the outward normal for a section traversed with air on the left.
|
||||
static void AddRail( MeshBuilder* builder, const b3Vec2* section, int count, float halfLength, float cellSize, bool mirror )
|
||||
{
|
||||
float sign = mirror ? -1.0f : 1.0f;
|
||||
int xCount = b3MaxInt( 1, (int)ceilf( 2.0f * halfLength / cellSize - 0.01f ) );
|
||||
int stride = xCount + 1;
|
||||
|
||||
int pointCount = 1;
|
||||
for ( int k = 0; k + 1 < count; ++k )
|
||||
{
|
||||
float dz = section[k + 1].x - section[k].x;
|
||||
float dy = section[k + 1].y - section[k].y;
|
||||
pointCount += b3MaxInt( 1, (int)ceilf( sqrtf( dz * dz + dy * dy ) / cellSize - 0.01f ) );
|
||||
}
|
||||
|
||||
builder->vertices = realloc( builder->vertices, pointCount * stride * sizeof( b3Vec3 ) );
|
||||
int index = 0;
|
||||
for ( int k = 0; k < count; ++k )
|
||||
{
|
||||
int n = 1;
|
||||
if ( k + 1 < count )
|
||||
{
|
||||
float dz = section[k + 1].x - section[k].x;
|
||||
float dy = section[k + 1].y - section[k].y;
|
||||
n = b3MaxInt( 1, (int)ceilf( sqrtf( dz * dz + dy * dy ) / cellSize - 0.01f ) );
|
||||
}
|
||||
|
||||
// The last point only closes the final segment
|
||||
int last = k + 1 < count ? n : 1;
|
||||
for ( int s = 0; s < last; ++s )
|
||||
{
|
||||
float t = k + 1 < count ? (float)s / (float)n : 0.0f;
|
||||
b3Vec2 a = section[k];
|
||||
b3Vec2 b = k + 1 < count ? section[k + 1] : a;
|
||||
float z = a.x + t * ( b.x - a.x );
|
||||
float y = a.y + t * ( b.y - a.y );
|
||||
for ( int j = 0; j <= xCount; ++j )
|
||||
{
|
||||
float x = -halfLength + 2.0f * halfLength * (float)j / (float)xCount;
|
||||
builder->vertices[index++] = (b3Vec3){ sign * x, y, z };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
builder->vertexCount = index;
|
||||
|
||||
int triangleCount = 2 * ( pointCount - 1 ) * xCount;
|
||||
builder->indices = realloc( builder->indices, 3 * triangleCount * sizeof( int32_t ) );
|
||||
builder->indexCount = 0;
|
||||
for ( int i = 0; i + 1 < pointCount; ++i )
|
||||
{
|
||||
for ( int j = 0; j < xCount; ++j )
|
||||
{
|
||||
int a = i * stride + j;
|
||||
int b = a + 1;
|
||||
int c = a + stride + 1;
|
||||
int d = a + stride;
|
||||
|
||||
int corners[6] = { a, d, c, c, b, a };
|
||||
if ( ( i + j ) & 1 )
|
||||
{
|
||||
int flipped[6] = { a, d, b, d, c, b };
|
||||
memcpy( corners, flipped, sizeof( corners ) );
|
||||
}
|
||||
|
||||
for ( int k = 0; k < 6; k += 3 )
|
||||
{
|
||||
builder->indices[builder->indexCount++] = corners[k];
|
||||
builder->indices[builder->indexCount++] = mirror ? corners[k + 2] : corners[k + 1];
|
||||
builder->indices[builder->indexCount++] = mirror ? corners[k + 1] : corners[k + 2];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static float EvaluateRail( float z, float cellZ )
|
||||
{
|
||||
if ( z < -0.5f * cellZ )
|
||||
{
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
return z < 0.5f * cellZ ? GHOST_RAIL_HEIGHT : -GHOST_RAIL_SKIRT;
|
||||
}
|
||||
|
||||
static void AddMesh( GhostCollisionsData* data, MeshBuilder* builder, bool frictionless )
|
||||
{
|
||||
b3MeshDef meshDef = { 0 };
|
||||
meshDef.vertices = builder->vertices;
|
||||
meshDef.indices = builder->indices;
|
||||
meshDef.vertexCount = builder->vertexCount;
|
||||
meshDef.triangleCount = builder->indexCount / 3;
|
||||
meshDef.weldVertices = true;
|
||||
meshDef.weldTolerance = 0.001f;
|
||||
meshDef.identifyEdges = true;
|
||||
|
||||
b3MeshData* mesh = b3CreateMesh( &meshDef, NULL, 0 );
|
||||
data->meshes[data->meshCount++] = mesh;
|
||||
|
||||
b3Vec3 scale = data->settings.mirror ? (b3Vec3){ -1.0f, 1.0f, 1.0f } : b3Vec3_one;
|
||||
b3ShapeDef shapeDef = b3DefaultShapeDef();
|
||||
if ( frictionless )
|
||||
{
|
||||
shapeDef.baseMaterial.friction = 0.0f;
|
||||
}
|
||||
b3CreateMeshShape( data->groundId, &shapeDef, mesh, scale );
|
||||
|
||||
builder->vertexCount = 0;
|
||||
builder->indexCount = 0;
|
||||
}
|
||||
|
||||
// The bodies holding height field shapes must go first
|
||||
static void DestroyGhostGroundData( GhostCollisionsData* data )
|
||||
{
|
||||
for ( int i = 0; i < data->meshCount; ++i )
|
||||
{
|
||||
b3DestroyMesh( data->meshes[i] );
|
||||
data->meshes[i] = NULL;
|
||||
}
|
||||
data->meshCount = 0;
|
||||
|
||||
for ( int i = 0; i < data->heightFieldCount; ++i )
|
||||
{
|
||||
b3DestroyHeightField( data->heightFields[i] );
|
||||
data->heightFields[i] = NULL;
|
||||
}
|
||||
data->heightFieldCount = 0;
|
||||
}
|
||||
|
||||
static void PushProfile( GhostCollisionsData* data, float x, float y )
|
||||
{
|
||||
if ( data->profileCount < GHOST_MAX_PROFILE_POINTS )
|
||||
{
|
||||
data->profile[data->profileCount++] = (b3Vec2){ x, y };
|
||||
}
|
||||
}
|
||||
|
||||
// The profile is a function of x, a vertical step has two points at the same x
|
||||
static float EvaluateProfile( const GhostCollisionsData* data, float x )
|
||||
{
|
||||
const b3Vec2* profile = data->profile;
|
||||
int count = data->profileCount;
|
||||
for ( int k = 0; k + 1 < count; ++k )
|
||||
{
|
||||
if ( x <= profile[k + 1].x )
|
||||
{
|
||||
float dx = profile[k + 1].x - profile[k].x;
|
||||
float t = dx > 0.0f ? b3ClampFloat( ( x - profile[k].x ) / dx, 0.0f, 1.0f ) : 1.0f;
|
||||
return profile[k].y + t * ( profile[k + 1].y - profile[k].y );
|
||||
}
|
||||
}
|
||||
|
||||
return profile[count - 1].y;
|
||||
}
|
||||
|
||||
static int GetCellCount( float length, float cellSize )
|
||||
{
|
||||
return b3MaxInt( 1, (int)ceilf( length / cellSize - 0.01f ) );
|
||||
}
|
||||
|
||||
// Samples the profile on a grid spanning x0 to x1. The mirror samples in reverse and turns the body half
|
||||
// way around y, so the world geometry is the same either way. All tiles of a scene share one height range
|
||||
// so their quantized heights line up at a seam.
|
||||
static void AddHeightField( b3WorldId worldId, GhostCollisionsData* data, float x0, float x1, int cellCountX, float halfWidth,
|
||||
int cellCountZ, bool frictionless )
|
||||
{
|
||||
float minHeight = FLT_MAX;
|
||||
float maxHeight = -FLT_MAX;
|
||||
for ( int k = 0; k < data->profileCount; ++k )
|
||||
{
|
||||
minHeight = b3MinFloat( minHeight, data->profile[k].y );
|
||||
maxHeight = b3MaxFloat( maxHeight, data->profile[k].y );
|
||||
}
|
||||
|
||||
bool mirror = data->settings.mirror;
|
||||
int countX = cellCountX + 1;
|
||||
int countZ = cellCountZ + 1;
|
||||
float cellX = ( x1 - x0 ) / (float)cellCountX;
|
||||
float cellZ = 2.0f * halfWidth / (float)cellCountZ;
|
||||
|
||||
// The mirror turns the body half way around y, which also reverses z
|
||||
bool rail = data->settings.scene == e_ghostRail;
|
||||
float* heights = malloc( countX * countZ * sizeof( float ) );
|
||||
for ( int row = 0; row < countZ; ++row )
|
||||
{
|
||||
float z = mirror ? halfWidth - cellZ * (float)row : -halfWidth + cellZ * (float)row;
|
||||
for ( int column = 0; column < countX; ++column )
|
||||
{
|
||||
float x = mirror ? x1 - cellX * (float)column : x0 + cellX * (float)column;
|
||||
heights[row * countX + column] = rail ? EvaluateRail( z, cellZ ) : EvaluateProfile( data, x );
|
||||
}
|
||||
}
|
||||
|
||||
b3HeightFieldDef def = { 0 };
|
||||
def.heights = heights;
|
||||
def.scale = (b3Vec3){ cellX, 1.0f, cellZ };
|
||||
def.countX = countX;
|
||||
def.countZ = countZ;
|
||||
def.globalMinimumHeight = minHeight;
|
||||
def.globalMaximumHeight = maxHeight;
|
||||
b3HeightFieldData* heightField = b3CreateHeightField( &def );
|
||||
free( heights );
|
||||
|
||||
b3BodyDef bodyDef = b3DefaultBodyDef();
|
||||
if ( mirror )
|
||||
{
|
||||
bodyDef.position = (b3Pos){ x1, 0.0f, halfWidth };
|
||||
bodyDef.rotation = (b3Quat){ { 0.0f, 1.0f, 0.0f }, 0.0f };
|
||||
}
|
||||
else
|
||||
{
|
||||
bodyDef.position = (b3Pos){ x0, 0.0f, -halfWidth };
|
||||
}
|
||||
|
||||
b3BodyId bodyId = b3CreateBody( worldId, &bodyDef );
|
||||
|
||||
b3ShapeDef shapeDef = b3DefaultShapeDef();
|
||||
if ( frictionless )
|
||||
{
|
||||
shapeDef.baseMaterial.friction = 0.0f;
|
||||
}
|
||||
b3CreateHeightFieldShape( bodyId, &shapeDef, heightField );
|
||||
|
||||
data->heightFields[data->heightFieldCount] = heightField;
|
||||
data->heightBodyIds[data->heightFieldCount] = bodyId;
|
||||
data->heightFieldCount += 1;
|
||||
}
|
||||
|
||||
void CreateGhostGround( b3WorldId worldId, GhostCollisionsData* data )
|
||||
{
|
||||
if ( B3_IS_NON_NULL( data->groundId ) )
|
||||
{
|
||||
b3DestroyBody( data->groundId );
|
||||
}
|
||||
|
||||
for ( int i = 0; i < data->heightFieldCount; ++i )
|
||||
{
|
||||
b3DestroyBody( data->heightBodyIds[i] );
|
||||
}
|
||||
|
||||
DestroyGhostGroundData( data );
|
||||
|
||||
b3BodyDef bodyDef = b3DefaultBodyDef();
|
||||
data->groundId = b3CreateBody( worldId, &bodyDef );
|
||||
|
||||
const GhostSettings* settings = &data->settings;
|
||||
bool rail = settings->scene == e_ghostRail;
|
||||
float h = rail ? GHOST_RAIL_HALF_LENGTH : GHOST_HALF_LENGTH;
|
||||
data->profileCount = 0;
|
||||
data->halfLength = h;
|
||||
data->halfWidth = rail ? GHOST_RAIL_HALF_WIDTH : GHOST_HALF_WIDTH;
|
||||
|
||||
switch ( settings->scene )
|
||||
{
|
||||
case e_ghostConcave:
|
||||
{
|
||||
float slope = 8.0f * B3_PI / 180.0f;
|
||||
PushProfile( data, -h, h * tanf( slope ) );
|
||||
PushProfile( data, 0.0f, 0.0f );
|
||||
PushProfile( data, h, 0.0f );
|
||||
}
|
||||
break;
|
||||
|
||||
case e_ghostCliff:
|
||||
// A height field cannot hold a vertical wall, so there the drop takes one cell
|
||||
PushProfile( data, -h, 3.0f );
|
||||
PushProfile( data, 0.0f, 3.0f );
|
||||
PushProfile( data, settings->heightField ? settings->cellSize : 0.0f, 0.0f );
|
||||
PushProfile( data, h, 0.0f );
|
||||
break;
|
||||
|
||||
case e_ghostCrest:
|
||||
PushProfile( data, -h, 0.0f );
|
||||
PushProfile( data, -10.0f, 0.0f );
|
||||
PushProfile( data, 0.0f, 1.0f );
|
||||
PushProfile( data, 10.0f, 0.0f );
|
||||
PushProfile( data, h, 0.0f );
|
||||
break;
|
||||
|
||||
case e_ghostBumps:
|
||||
// Gentle folds of a few degrees, the range that only flat edge suppression misses
|
||||
for ( int i = 0; i <= 80; ++i )
|
||||
{
|
||||
float x = -h + 0.5f * (float)i;
|
||||
float y = x < -10.0f ? 0.0f : 0.05f * ( 1.0f - cosf( B3_PI * x ) );
|
||||
PushProfile( data, x, y );
|
||||
}
|
||||
break;
|
||||
|
||||
case e_ghostInternal:
|
||||
// PEEL's curved mesh: 32 rows 4 m apart, each step up 1.25 times the last, sliding toward +x
|
||||
for ( int i = 31; i >= 0; --i )
|
||||
{
|
||||
PushProfile( data, 62.0f - 4.0f * (float)i, 1.0f + 0.1f * powf( 1.25f, (float)i ) );
|
||||
}
|
||||
break;
|
||||
|
||||
case e_ghostChamfer:
|
||||
// Flat tops at y = 0 with a chamfered notch every meter. A body crossing a notch overhangs both
|
||||
// chamfers while its bottom rests on the convex top edges.
|
||||
PushProfile( data, -h, 0.0f );
|
||||
for ( int i = 0; i < 30; ++i )
|
||||
{
|
||||
float x = -8.0f + (float)i;
|
||||
PushProfile( data, x, 0.0f );
|
||||
PushProfile( data, x + GHOST_CHAMFER_WIDTH, -GHOST_CHAMFER_DROP );
|
||||
PushProfile( data, x + 2.0f * GHOST_CHAMFER_WIDTH, -GHOST_CHAMFER_DROP );
|
||||
PushProfile( data, x + 3.0f * GHOST_CHAMFER_WIDTH, 0.0f );
|
||||
}
|
||||
PushProfile( data, h, 0.0f );
|
||||
break;
|
||||
|
||||
case e_ghostRail:
|
||||
// Cross section in zy, from the floor up the inner wall, over the top and down the outer skirt
|
||||
PushProfile( data, -data->halfWidth, 0.0f );
|
||||
PushProfile( data, 0.0f, 0.0f );
|
||||
PushProfile( data, 0.0f, GHOST_RAIL_HEIGHT );
|
||||
PushProfile( data, GHOST_RAIL_THICKNESS, GHOST_RAIL_HEIGHT );
|
||||
PushProfile( data, GHOST_RAIL_THICKNESS, -GHOST_RAIL_SKIRT );
|
||||
break;
|
||||
|
||||
default:
|
||||
PushProfile( data, -h, 0.0f );
|
||||
PushProfile( data, h, 0.0f );
|
||||
break;
|
||||
}
|
||||
|
||||
MeshBuilder builder = { 0 };
|
||||
float cellSize = settings->cellSize;
|
||||
bool mirror = settings->mirror;
|
||||
float groundHalfWidth = data->halfWidth;
|
||||
int cellCountZ = GetCellCount( 2.0f * groundHalfWidth, cellSize );
|
||||
|
||||
if ( settings->heightField )
|
||||
{
|
||||
if ( settings->scene == e_ghostInternal )
|
||||
{
|
||||
// One grid line per profile row, as in the mesh
|
||||
PeelPreset preset = s_peelPresets[settings->peelPreset];
|
||||
int zCount = preset.columnCount - 1;
|
||||
data->halfWidth = 20.0f * preset.scaleX * (float)zCount;
|
||||
float x0 = data->profile[0].x;
|
||||
float x1 = data->profile[data->profileCount - 1].x;
|
||||
AddHeightField( worldId, data, x0, x1, data->profileCount - 1, data->halfWidth, zCount, true );
|
||||
|
||||
b3BoxHull box = b3MakeOffsetBoxHull( 140.0f, 1.0f, 30.0f, ( b3Vec3 ){ 65.0f, -1.0f, 0.0f } );
|
||||
b3ShapeDef shapeDef = b3DefaultShapeDef();
|
||||
b3CreateHullShape( data->groundId, &shapeDef, &box.base );
|
||||
}
|
||||
else if ( settings->scene == e_ghostChamfer )
|
||||
{
|
||||
// One cell per chamfer puts every notch vertex on the grid
|
||||
AddHeightField( worldId, data, -h, h, GetCellCount( 2.0f * h, GHOST_CHAMFER_WIDTH ), groundHalfWidth, cellCountZ,
|
||||
false );
|
||||
}
|
||||
else
|
||||
{
|
||||
AddHeightField( worldId, data, -h, h, GetCellCount( 2.0f * h, cellSize ), groundHalfWidth, cellCountZ, false );
|
||||
}
|
||||
}
|
||||
else if ( settings->scene == e_ghostRail )
|
||||
{
|
||||
AddRail( &builder, data->profile, data->profileCount, h, cellSize, mirror );
|
||||
AddMesh( data, &builder, false );
|
||||
}
|
||||
else if ( settings->scene == e_ghostInternal )
|
||||
{
|
||||
// The mesh has no friction and the ground plane under it does, as in PEEL
|
||||
PeelPreset preset = s_peelPresets[settings->peelPreset];
|
||||
int zCount = preset.columnCount - 1;
|
||||
float halfWidth = 20.0f * preset.scaleX * (float)zCount;
|
||||
AddGrid( &builder, data->profile, data->profileCount, halfWidth, zCount, false, mirror );
|
||||
data->halfWidth = halfWidth;
|
||||
AddMesh( data, &builder, true );
|
||||
|
||||
b3BoxHull box = b3MakeOffsetBoxHull( 140.0f, 1.0f, 30.0f, ( b3Vec3 ){ 65.0f, -1.0f, 0.0f } );
|
||||
b3ShapeDef shapeDef = b3DefaultShapeDef();
|
||||
b3CreateHullShape( data->groundId, &shapeDef, &box.base );
|
||||
}
|
||||
else
|
||||
{
|
||||
AddStrip( &builder, data->profile, data->profileCount, cellSize, cellSize, mirror );
|
||||
AddMesh( data, &builder, false );
|
||||
}
|
||||
|
||||
free( builder.vertices );
|
||||
free( builder.indices );
|
||||
}
|
||||
|
||||
void LaunchGhostBody( b3WorldId worldId, GhostCollisionsData* data )
|
||||
{
|
||||
if ( B3_IS_NON_NULL( data->bodyId ) )
|
||||
{
|
||||
b3DestroyBody( data->bodyId );
|
||||
}
|
||||
|
||||
const GhostSettings* settings = &data->settings;
|
||||
|
||||
// PEEL drops its bodies from rest, sized in meters rather than tenths
|
||||
bool peel = settings->scene == e_ghostInternal;
|
||||
float boxHalf = peel ? 1.0f : 0.2f;
|
||||
float capsuleRadius = peel ? 1.0f : 0.2f;
|
||||
float capsuleHalf = peel ? 2.0f : 0.4f;
|
||||
float sphereRadius = peel ? 1.0f : 0.25f;
|
||||
|
||||
b3BodyDef bodyDef = b3DefaultBodyDef();
|
||||
bodyDef.type = b3_dynamicBody;
|
||||
bodyDef.enableContactRecycling = false;
|
||||
b3Quat yaw = b3MakeQuatFromAxisAngle( b3Vec3_axisY, settings->yaw * B3_PI / 180.0f );
|
||||
|
||||
if ( peel )
|
||||
{
|
||||
bodyDef.position = (b3Pos){ s_peelPresets[settings->peelPreset].startZ, 80.0f, 0.0f };
|
||||
bodyDef.rotation = yaw;
|
||||
}
|
||||
else if ( settings->scene == e_ghostRail )
|
||||
{
|
||||
// Dropped across the rail top, pitched so a box face sweeps into the rail edge at an angle. The real
|
||||
// contact is edge on edge and perpendicular to the rail, a face normal there leans along the rail
|
||||
// and catches the body. Found in the Conveyor Circuit sample.
|
||||
b3Quat pitch = b3MakeQuatFromAxisAngle( b3Vec3_axisZ, 60.0f * B3_PI / 180.0f );
|
||||
bodyDef.position = (b3Pos){ GHOST_RAIL_START_X, GHOST_RAIL_HEIGHT + 0.45f, -0.15f };
|
||||
bodyDef.rotation = b3MulQuat( pitch, yaw );
|
||||
bodyDef.linearVelocity = (b3Vec3){ settings->speed, 0.0f, 0.0f };
|
||||
}
|
||||
else
|
||||
{
|
||||
int segment = 0;
|
||||
for ( int k = 0; k + 1 < data->profileCount; ++k )
|
||||
{
|
||||
if ( data->profile[k].x <= GHOST_START_X && GHOST_START_X < data->profile[k + 1].x )
|
||||
{
|
||||
segment = k;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
b3Vec2 a = data->profile[segment];
|
||||
b3Vec2 b = data->profile[segment + 1];
|
||||
float length = sqrtf( ( b.x - a.x ) * ( b.x - a.x ) + ( b.y - a.y ) * ( b.y - a.y ) );
|
||||
b3Vec2 d = { ( b.x - a.x ) / length, ( b.y - a.y ) / length };
|
||||
b3Vec2 n = { -d.y, d.x };
|
||||
float y = a.y + ( GHOST_START_X - a.x ) * d.y / d.x;
|
||||
|
||||
float lift = boxHalf;
|
||||
if ( settings->body == e_ghostSphere )
|
||||
{
|
||||
lift = sphereRadius;
|
||||
}
|
||||
else if ( settings->body == e_ghostVCapsule )
|
||||
{
|
||||
lift = capsuleHalf + capsuleRadius;
|
||||
}
|
||||
lift += 0.01f;
|
||||
|
||||
bodyDef.position = (b3Pos){ GHOST_START_X + lift * n.x, y + lift * n.y, 0.0f };
|
||||
b3Quat slope = b3MakeQuatFromAxisAngle( b3Vec3_axisZ, atan2f( d.y, d.x ) );
|
||||
bodyDef.rotation = b3MulQuat( slope, yaw );
|
||||
bodyDef.linearVelocity = (b3Vec3){ settings->speed * d.x, settings->speed * d.y, 0.0f };
|
||||
}
|
||||
|
||||
bodyDef.motionLocks.angularX = settings->fixedRotation;
|
||||
bodyDef.motionLocks.angularY = settings->fixedRotation;
|
||||
bodyDef.motionLocks.angularZ = settings->fixedRotation;
|
||||
bodyDef.enableSleep = false;
|
||||
bodyDef.name = "slider";
|
||||
data->bodyId = b3CreateBody( worldId, &bodyDef );
|
||||
|
||||
b3ShapeDef shapeDef = b3DefaultShapeDef();
|
||||
shapeDef.baseMaterial.friction = settings->friction;
|
||||
shapeDef.enableSpeculativeContact = settings->speculative;
|
||||
|
||||
switch ( settings->body )
|
||||
{
|
||||
case e_ghostBox:
|
||||
{
|
||||
b3BoxHull box = peel ? b3MakeBoxHull( 1.0f, 1.0f, 1.0f ) : b3MakeBoxHull( 0.4f, 0.2f, 0.4f );
|
||||
data->shapeId = b3CreateHullShape( data->bodyId, &shapeDef, &box.base );
|
||||
}
|
||||
break;
|
||||
|
||||
case e_ghostHCapsule:
|
||||
{
|
||||
b3Capsule capsule = { { 0.0f, 0.0f, -capsuleHalf }, { 0.0f, 0.0f, capsuleHalf }, capsuleRadius };
|
||||
data->shapeId = b3CreateCapsuleShape( data->bodyId, &shapeDef, &capsule );
|
||||
}
|
||||
break;
|
||||
|
||||
case e_ghostVCapsule:
|
||||
{
|
||||
b3Capsule capsule = { { 0.0f, -capsuleHalf, 0.0f }, { 0.0f, capsuleHalf, 0.0f }, capsuleRadius };
|
||||
data->shapeId = b3CreateCapsuleShape( data->bodyId, &shapeDef, &capsule );
|
||||
}
|
||||
break;
|
||||
|
||||
case e_ghostSphere:
|
||||
{
|
||||
b3Sphere sphere = { b3Vec3_zero, sphereRadius };
|
||||
data->shapeId = b3CreateSphereShape( data->bodyId, &shapeDef, &sphere );
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
data->shapeId = b3CreateHullShape( data->bodyId, &shapeDef, peel ? data->peelCylinder : data->cylinder );
|
||||
break;
|
||||
}
|
||||
|
||||
data->contactBounds = b3Shape_GetAABB( data->shapeId );
|
||||
data->runGhostCount = 0;
|
||||
data->runSteps = 0;
|
||||
}
|
||||
|
||||
GhostCollisionsData CreateGhostCollisions( b3WorldId worldId, GhostSettings settings )
|
||||
{
|
||||
GhostCollisionsData data = { 0 };
|
||||
data.settings = settings;
|
||||
data.cylinder = b3CreateCylinder( 0.4f, 0.4f, -0.2f, 16 );
|
||||
data.peelCylinder = b3CreateCylinder( 2.0f, 1.0f, -1.0f, 16 );
|
||||
data.groundId = b3_nullBodyId;
|
||||
data.bodyId = b3_nullBodyId;
|
||||
data.shapeId = b3_nullShapeId;
|
||||
|
||||
CreateGhostGround( worldId, &data );
|
||||
LaunchGhostBody( worldId, &data );
|
||||
return data;
|
||||
}
|
||||
|
||||
static float SegmentAngle( const GhostCollisionsData* data, int k )
|
||||
{
|
||||
b3Vec2 a = data->profile[k];
|
||||
b3Vec2 b = data->profile[k + 1];
|
||||
return atan2f( b.x - a.x, a.y - b.y );
|
||||
}
|
||||
|
||||
// The normal points from the ground to the body. A hull face can be the reference face, so any
|
||||
// normal within the span of face normals under the body is valid. At a side edge of the ground the
|
||||
// normal may also lean off that side, perpendicular to the edge.
|
||||
static bool IsGhost( const GhostCollisionsData* data, b3Vec3 normal, float xMin, float xMax, float zMin, float zMax )
|
||||
{
|
||||
float tolerance = 5.0f * B3_PI / 180.0f;
|
||||
float sinTolerance = sinf( tolerance );
|
||||
if ( b3AbsFloat( normal.z ) > sinTolerance )
|
||||
{
|
||||
// The manifold must reach the side it leans off
|
||||
float margin = 0.05f;
|
||||
bool atSide = normal.z < 0.0f ? zMin < -data->halfWidth + margin : zMax > data->halfWidth - margin;
|
||||
if ( atSide == false )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// A normal leaning off a side has a short projection, which leaves little room to lean along the edge
|
||||
float planarLength = sqrtf( normal.x * normal.x + normal.y * normal.y );
|
||||
if ( planarLength < sinTolerance )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
GhostBody body = data->settings.body;
|
||||
bool chamferHull = data->settings.scene == e_ghostChamfer && ( body == e_ghostBox || body == e_ghostCylinder );
|
||||
|
||||
float lower = B3_PI;
|
||||
float upper = -B3_PI;
|
||||
int segmentCount = data->profileCount - 1;
|
||||
for ( int k = 0; k < segmentCount; ++k )
|
||||
{
|
||||
float x0 = b3MinFloat( data->profile[k].x, data->profile[k + 1].x );
|
||||
float x1 = b3MaxFloat( data->profile[k].x, data->profile[k + 1].x );
|
||||
if ( x1 < xMin || xMax < x0 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// A flat hull bottom resting on the top edges must keep its own normal, so for a hull only the tops
|
||||
// count. A round body's normal comes from the closest ground feature, which can be a top edge.
|
||||
if ( chamferHull && ( data->profile[k].y < 0.0f || data->profile[k + 1].y < 0.0f ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
float angle = SegmentAngle( data, k );
|
||||
lower = b3MinFloat( lower, angle );
|
||||
upper = b3MaxFloat( upper, angle );
|
||||
}
|
||||
|
||||
float angle = atan2f( normal.y, normal.x );
|
||||
float deviation = b3MaxFloat( lower - angle, angle - upper );
|
||||
if ( deviation <= 0.0f )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Measure the lean outside the span in 3D so a steep side normal is not over counted
|
||||
return deviation > 0.5f * B3_PI || planarLength * sinf( deviation ) > sinTolerance;
|
||||
}
|
||||
|
||||
int UpdateGhostCollisions( b3WorldId worldId, GhostCollisionsData* data, GhostReport* reports, int capacity )
|
||||
{
|
||||
b3Pos center = b3Body_GetWorldCenter( data->bodyId );
|
||||
bool done = center.x > data->halfLength - 1.0f || center.y < -3.0f;
|
||||
if ( data->settings.scene == e_ghostInternal )
|
||||
{
|
||||
// Run out onto the ground plane, or give up on a body knocked off the side
|
||||
done = center.x > 100.0f || center.y < -3.0f || data->runSteps > 900;
|
||||
}
|
||||
|
||||
if ( done )
|
||||
{
|
||||
data->runCount += 1;
|
||||
LaunchGhostBody( worldId, data );
|
||||
center = b3Body_GetWorldCenter( data->bodyId );
|
||||
}
|
||||
|
||||
data->runSteps += 1;
|
||||
|
||||
b3AABB bounds = data->contactBounds;
|
||||
float xMin = (float)bounds.lowerBound.x - 0.1f;
|
||||
float xMax = (float)bounds.upperBound.x + 0.1f;
|
||||
data->contactBounds = b3Shape_GetAABB( data->shapeId );
|
||||
|
||||
int ghostCount = 0;
|
||||
b3ContactData contacts[8];
|
||||
int contactCount = b3Body_GetContactData( data->bodyId, contacts, 8 );
|
||||
for ( int i = 0; i < contactCount; ++i )
|
||||
{
|
||||
bool bodyIsA = B3_ID_EQUALS( contacts[i].shapeIdA, data->shapeId );
|
||||
b3ShapeId otherId = bodyIsA ? contacts[i].shapeIdB : contacts[i].shapeIdA;
|
||||
b3ShapeType otherType = b3Shape_GetType( otherId );
|
||||
if ( otherType != b3_meshShape && otherType != b3_heightShape )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
for ( int j = 0; j < contacts[i].manifoldCount; ++j )
|
||||
{
|
||||
const b3Manifold* manifold = contacts[i].manifolds + j;
|
||||
|
||||
// Speculative points that never pushed are harmless
|
||||
float impulse = 0.0f;
|
||||
for ( int k = 0; k < manifold->pointCount; ++k )
|
||||
{
|
||||
impulse += manifold->points[k].totalNormalImpulse;
|
||||
}
|
||||
|
||||
if ( manifold->pointCount == 0 || impulse <= 0.0f )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
float zMin = FLT_MAX;
|
||||
float zMax = -FLT_MAX;
|
||||
for ( int k = 0; k < manifold->pointCount; ++k )
|
||||
{
|
||||
b3Vec3 anchor = bodyIsA ? manifold->points[k].anchorA : manifold->points[k].anchorB;
|
||||
float z = (float)center.z + anchor.z;
|
||||
zMin = b3MinFloat( zMin, z );
|
||||
zMax = b3MaxFloat( zMax, z );
|
||||
}
|
||||
|
||||
b3Vec3 normal = bodyIsA ? b3Neg( manifold->normal ) : manifold->normal;
|
||||
if ( data->settings.scene == e_ghostRail )
|
||||
{
|
||||
// The rail is the same all along x, so no valid normal leans along it
|
||||
if ( b3AbsFloat( normal.x ) <= sinf( 5.0f * B3_PI / 180.0f ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if ( IsGhost( data, normal, xMin, xMax, zMin, zMax ) == false )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ghostCount < capacity )
|
||||
{
|
||||
b3Vec3 anchor = bodyIsA ? manifold->points[0].anchorA : manifold->points[0].anchorB;
|
||||
reports[ghostCount] = (GhostReport){
|
||||
.point = b3OffsetPos( center, anchor ),
|
||||
.normal = normal,
|
||||
.separation = manifold->points[0].separation,
|
||||
.impulse = impulse,
|
||||
};
|
||||
}
|
||||
|
||||
ghostCount += 1;
|
||||
}
|
||||
}
|
||||
|
||||
data->runGhostCount += ghostCount;
|
||||
data->ghostCount += ghostCount;
|
||||
return ghostCount;
|
||||
}
|
||||
|
||||
void DestroyGhostCollisions( GhostCollisionsData* data )
|
||||
{
|
||||
DestroyGhostGroundData( data );
|
||||
b3DestroyHull( data->cylinder );
|
||||
b3DestroyHull( data->peelCylinder );
|
||||
data->cylinder = NULL;
|
||||
data->peelCylinder = NULL;
|
||||
}
|
||||
143
shared/ghost_collisions.h
Normal file
143
shared/ghost_collisions.h
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
// SPDX-FileCopyrightText: 2026 Erin Catto
|
||||
// SPDX-License-Identifier: MIT
|
||||
#pragma once
|
||||
|
||||
#include "box3d/collision.h"
|
||||
#include "box3d/id.h"
|
||||
#include "box3d/math_functions.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
// Ghost collision scenes, shared by the Mesh / Ghost Collisions sample and the headless ghost scan.
|
||||
// Each ground is a profile in the xy-plane extruded along z and finely tessellated, so a sliding
|
||||
// body crosses many internal edges. A manifold that pushes on the body is a ghost when its normal
|
||||
// points outside the span of face normals under the body. Those are the ones that block or launch
|
||||
// a body.
|
||||
|
||||
// A conveyor side rail along x, the floor is on the -z side
|
||||
#define GHOST_RAIL_HEIGHT 0.35f
|
||||
#define GHOST_RAIL_THICKNESS 0.08f
|
||||
|
||||
typedef enum GhostScene
|
||||
{
|
||||
e_ghostFlat,
|
||||
e_ghostConcave,
|
||||
e_ghostCliff,
|
||||
e_ghostCrest,
|
||||
e_ghostBumps,
|
||||
e_ghostInternal,
|
||||
e_ghostChamfer,
|
||||
e_ghostRail,
|
||||
e_ghostSceneCount
|
||||
} GhostScene;
|
||||
|
||||
typedef enum GhostBody
|
||||
{
|
||||
e_ghostBox,
|
||||
e_ghostHCapsule,
|
||||
e_ghostVCapsule,
|
||||
e_ghostSphere,
|
||||
e_ghostCylinder,
|
||||
e_ghostBodyCount
|
||||
} GhostBody;
|
||||
|
||||
// Mesh variants of the PEEL InternalEdges presets
|
||||
#define GHOST_PEEL_PRESET_COUNT 4
|
||||
|
||||
// Chamfer has the longest profile
|
||||
#define GHOST_MAX_PROFILE_POINTS 128
|
||||
|
||||
extern const char* g_ghostSceneNames[e_ghostSceneCount];
|
||||
extern const char* g_ghostBodyNames[e_ghostBodyCount];
|
||||
extern const char* g_ghostPeelPresetNames[GHOST_PEEL_PRESET_COUNT];
|
||||
|
||||
typedef struct GhostSettings
|
||||
{
|
||||
GhostScene scene;
|
||||
GhostBody body;
|
||||
int peelPreset;
|
||||
bool mirror;
|
||||
|
||||
// Build the ground from height fields instead of meshes. Each height field is its own shape.
|
||||
bool heightField;
|
||||
|
||||
float cellSize;
|
||||
float speed;
|
||||
|
||||
// Degrees
|
||||
float yaw;
|
||||
|
||||
float friction;
|
||||
bool fixedRotation;
|
||||
bool speculative;
|
||||
} GhostSettings;
|
||||
|
||||
GhostSettings GetDefaultGhostSettings( void );
|
||||
|
||||
typedef struct GhostReport
|
||||
{
|
||||
b3Pos point;
|
||||
b3Vec3 normal;
|
||||
float separation;
|
||||
float impulse;
|
||||
} GhostReport;
|
||||
|
||||
typedef struct GhostCollisionsData
|
||||
{
|
||||
GhostSettings settings;
|
||||
b3Vec2 profile[GHOST_MAX_PROFILE_POINTS];
|
||||
int profileCount;
|
||||
|
||||
// The ground spans x in [-halfLength, halfLength] and z in [-halfWidth, halfWidth]
|
||||
float halfLength;
|
||||
float halfWidth;
|
||||
b3MeshData* meshes[2];
|
||||
int meshCount;
|
||||
|
||||
// A height field shape has no local transform, so each one gets its own static body
|
||||
b3HeightFieldData* heightFields[2];
|
||||
b3BodyId heightBodyIds[2];
|
||||
int heightFieldCount;
|
||||
b3HullData* cylinder;
|
||||
b3HullData* peelCylinder;
|
||||
b3BodyId groundId;
|
||||
b3BodyId bodyId;
|
||||
b3ShapeId shapeId;
|
||||
|
||||
// Body bounds at the start of the step, where the contacts were computed. A fast body can cross a fold
|
||||
// within a step, so the bounds after the step can miss the face a contact came from.
|
||||
b3AABB contactBounds;
|
||||
|
||||
// Steps in the current run
|
||||
int runSteps;
|
||||
|
||||
// Completed runs, each ending when the body reaches the end or falls off
|
||||
int runCount;
|
||||
|
||||
int runGhostCount;
|
||||
int ghostCount;
|
||||
} GhostCollisionsData;
|
||||
|
||||
// Creates the ground and launches the body
|
||||
GhostCollisionsData CreateGhostCollisions( b3WorldId worldId, GhostSettings settings );
|
||||
|
||||
// Rebuild the ground after a scene, preset, mirror, height field or cell size change. Relaunch after this.
|
||||
void CreateGhostGround( b3WorldId worldId, GhostCollisionsData* data );
|
||||
|
||||
// Launch a new body from the start, after a body, speed, yaw, friction or rotation change
|
||||
void LaunchGhostBody( b3WorldId worldId, GhostCollisionsData* data );
|
||||
|
||||
// Call after each world step. Relaunches a body that finished its run, then counts the ghost
|
||||
// manifolds on the body. Returns the ghost count for this step and writes up to capacity reports.
|
||||
int UpdateGhostCollisions( b3WorldId worldId, GhostCollisionsData* data, GhostReport* reports, int capacity );
|
||||
|
||||
void DestroyGhostCollisions( GhostCollisionsData* data );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
779
shared/ghost_oracle.c
Normal file
779
shared/ghost_oracle.c
Normal file
|
|
@ -0,0 +1,779 @@
|
|||
// SPDX-FileCopyrightText: 2026 Erin Catto
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "ghost_oracle.h"
|
||||
|
||||
#include "ghost_collisions.h"
|
||||
|
||||
#include "box3d/box3d.h"
|
||||
#include "box3d/constants.h"
|
||||
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
#include <stddef.h>
|
||||
|
||||
const char* g_oracleSceneNames[e_oracleSceneCount] = {
|
||||
"flat", "fan", "crest", "valley", "ridge", "saddle ridge", "rail", "wave",
|
||||
};
|
||||
|
||||
// The wave scene is the largest, 169 vertices and 288 triangles
|
||||
#define ORACLE_MAX_VERTICES 256
|
||||
#define ORACLE_MAX_INDICES ( 3 * 512 )
|
||||
#define ORACLE_MAX_MANIFOLDS 128
|
||||
|
||||
typedef struct OracleBuilder
|
||||
{
|
||||
b3Vec3 vertices[ORACLE_MAX_VERTICES];
|
||||
int32_t indices[ORACLE_MAX_INDICES];
|
||||
int vertexCount;
|
||||
int indexCount;
|
||||
} OracleBuilder;
|
||||
|
||||
static int AddVertex( OracleBuilder* builder, b3Vec3 vertex )
|
||||
{
|
||||
B3_ASSERT( builder->vertexCount < ORACLE_MAX_VERTICES );
|
||||
if ( builder->vertexCount == ORACLE_MAX_VERTICES )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
builder->vertices[builder->vertexCount] = vertex;
|
||||
return builder->vertexCount++;
|
||||
}
|
||||
|
||||
// Winds the triangle to face the given direction
|
||||
static void AddTriangle( OracleBuilder* builder, int a, int b, int c, b3Vec3 facing )
|
||||
{
|
||||
B3_ASSERT( builder->indexCount + 3 <= ORACLE_MAX_INDICES );
|
||||
if ( builder->indexCount + 3 > ORACLE_MAX_INDICES )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
b3Vec3 va = builder->vertices[a];
|
||||
b3Vec3 normal = b3Cross( b3Sub( builder->vertices[b], va ), b3Sub( builder->vertices[c], va ) );
|
||||
if ( b3Dot( normal, facing ) < 0.0f )
|
||||
{
|
||||
int temp = b;
|
||||
b = c;
|
||||
c = temp;
|
||||
}
|
||||
|
||||
builder->indices[builder->indexCount++] = a;
|
||||
builder->indices[builder->indexCount++] = b;
|
||||
builder->indices[builder->indexCount++] = c;
|
||||
}
|
||||
|
||||
typedef float OracleHeightFcn( float x, float z );
|
||||
|
||||
// Up facing grid with alternating diagonals
|
||||
static void BuildGrid( OracleBuilder* builder, int countX, int countZ, float cellSize, OracleHeightFcn* height )
|
||||
{
|
||||
float x0 = -0.5f * cellSize * countX;
|
||||
float z0 = -0.5f * cellSize * countZ;
|
||||
int base = builder->vertexCount;
|
||||
for ( int k = 0; k <= countZ; ++k )
|
||||
{
|
||||
for ( int i = 0; i <= countX; ++i )
|
||||
{
|
||||
float x = x0 + cellSize * i;
|
||||
float z = z0 + cellSize * k;
|
||||
AddVertex( builder, (b3Vec3){ x, height( x, z ), z } );
|
||||
}
|
||||
}
|
||||
|
||||
int stride = countX + 1;
|
||||
for ( int k = 0; k < countZ; ++k )
|
||||
{
|
||||
for ( int i = 0; i < countX; ++i )
|
||||
{
|
||||
int a = base + k * stride + i;
|
||||
int b = a + 1;
|
||||
int c = a + stride + 1;
|
||||
int d = a + stride;
|
||||
if ( ( i + k ) & 1 )
|
||||
{
|
||||
AddTriangle( builder, a, d, b, b3Vec3_axisY );
|
||||
AddTriangle( builder, b, d, c, b3Vec3_axisY );
|
||||
}
|
||||
else
|
||||
{
|
||||
AddTriangle( builder, a, d, c, b3Vec3_axisY );
|
||||
AddTriangle( builder, a, c, b, b3Vec3_axisY );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static float FlatHeight( float x, float z )
|
||||
{
|
||||
(void)x;
|
||||
(void)z;
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
static float CrestHeight( float x, float z )
|
||||
{
|
||||
(void)z;
|
||||
return -0.26795f * fabsf( x );
|
||||
}
|
||||
|
||||
static float ValleyHeight( float x, float z )
|
||||
{
|
||||
(void)z;
|
||||
return 0.26795f * fabsf( x );
|
||||
}
|
||||
|
||||
static float RidgeHeight( float x, float z )
|
||||
{
|
||||
(void)z;
|
||||
return -fabsf( x );
|
||||
}
|
||||
|
||||
// libm trig differs in the last bit between platforms, which would make each a different mesh
|
||||
static float WaveHeight( float x, float z )
|
||||
{
|
||||
float s1 = b3ComputeCosSin( 2.3f * x + 0.4f ).sine;
|
||||
float c1 = b3ComputeCosSin( 1.7f * z ).cosine;
|
||||
float s2 = b3ComputeCosSin( 4.1f * z - 1.3f * x ).sine;
|
||||
return 0.12f * s1 * c1 + 0.05f * s2;
|
||||
}
|
||||
|
||||
static void BuildFan( OracleBuilder* builder )
|
||||
{
|
||||
int center = AddVertex( builder, b3Vec3_zero );
|
||||
for ( int i = 0; i < 6; ++i )
|
||||
{
|
||||
b3CosSin cs = b3ComputeCosSin( ( i + 0.5f ) * B3_PI / 3.0f );
|
||||
AddVertex( builder, (b3Vec3){ 2.0f * cs.cosine, 0.0f, 2.0f * cs.sine } );
|
||||
}
|
||||
|
||||
for ( int i = 0; i < 6; ++i )
|
||||
{
|
||||
AddTriangle( builder, center, 1 + i, 1 + ( i + 1 ) % 6, b3Vec3_axisY );
|
||||
}
|
||||
}
|
||||
|
||||
// A ridge along x running into a rising wall, so the ridge end is a saddle vertex
|
||||
static void BuildSaddleRidge( OracleBuilder* builder )
|
||||
{
|
||||
float xs[3] = { -2.0f, 0.0f, 1.0f };
|
||||
float crests[3] = { -0.004f, 0.0f, 0.3f };
|
||||
float sides[3] = { -0.7f, -0.7f, -0.4f };
|
||||
for ( int i = 0; i < 3; ++i )
|
||||
{
|
||||
AddVertex( builder, (b3Vec3){ xs[i], sides[i], -1.0f } );
|
||||
AddVertex( builder, (b3Vec3){ xs[i], crests[i], 0.0f } );
|
||||
AddVertex( builder, (b3Vec3){ xs[i], sides[i], 1.0f } );
|
||||
}
|
||||
|
||||
for ( int i = 0; i < 2; ++i )
|
||||
{
|
||||
for ( int k = 0; k < 2; ++k )
|
||||
{
|
||||
int a = 3 * i + k;
|
||||
AddTriangle( builder, a, a + 1, a + 3, b3Vec3_axisY );
|
||||
AddTriangle( builder, a + 3, a + 1, a + 4, b3Vec3_axisY );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A wall facing -z meeting a narrow top at a convex edge, like a conveyor side rail
|
||||
static void BuildRail( OracleBuilder* builder )
|
||||
{
|
||||
float sectionZ[4] = { 0.0f, 0.0f, GHOST_RAIL_THICKNESS, GHOST_RAIL_THICKNESS };
|
||||
float sectionY[4] = { 0.0f, GHOST_RAIL_HEIGHT, GHOST_RAIL_HEIGHT, 0.0f };
|
||||
int columns = 5;
|
||||
for ( int row = 0; row < 4; ++row )
|
||||
{
|
||||
for ( int column = 0; column < columns; ++column )
|
||||
{
|
||||
AddVertex( builder, (b3Vec3){ -0.5f + 0.25f * column, sectionY[row], sectionZ[row] } );
|
||||
}
|
||||
}
|
||||
|
||||
b3Vec3 facings[3] = { { 0.0f, 0.0f, -1.0f }, b3Vec3_axisY, b3Vec3_axisZ };
|
||||
for ( int row = 0; row < 3; ++row )
|
||||
{
|
||||
for ( int column = 0; column < columns - 1; ++column )
|
||||
{
|
||||
int a = columns * row + column;
|
||||
int b = a + 1;
|
||||
int c = a + columns + 1;
|
||||
int d = a + columns;
|
||||
if ( ( row + column ) & 1 )
|
||||
{
|
||||
AddTriangle( builder, a, d, b, facings[row] );
|
||||
AddTriangle( builder, d, c, b, facings[row] );
|
||||
}
|
||||
else
|
||||
{
|
||||
AddTriangle( builder, a, d, c, facings[row] );
|
||||
AddTriangle( builder, c, b, a, facings[row] );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
b3MeshData* CreateOracleMesh( OracleScene scene )
|
||||
{
|
||||
static OracleBuilder builder;
|
||||
builder.vertexCount = 0;
|
||||
builder.indexCount = 0;
|
||||
|
||||
switch ( scene )
|
||||
{
|
||||
case e_oracleFlat:
|
||||
BuildGrid( &builder, 6, 6, 0.5f, FlatHeight );
|
||||
break;
|
||||
case e_oracleFan:
|
||||
BuildFan( &builder );
|
||||
break;
|
||||
case e_oracleCrest:
|
||||
BuildGrid( &builder, 8, 4, 0.5f, CrestHeight );
|
||||
break;
|
||||
case e_oracleValley:
|
||||
BuildGrid( &builder, 8, 4, 0.5f, ValleyHeight );
|
||||
break;
|
||||
case e_oracleRidge:
|
||||
BuildGrid( &builder, 6, 4, 0.5f, RidgeHeight );
|
||||
break;
|
||||
case e_oracleSaddleRidge:
|
||||
BuildSaddleRidge( &builder );
|
||||
break;
|
||||
case e_oracleRail:
|
||||
BuildRail( &builder );
|
||||
break;
|
||||
case e_oracleWave:
|
||||
BuildGrid( &builder, 12, 12, 0.25f, WaveHeight );
|
||||
break;
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
b3MeshDef def = { 0 };
|
||||
def.vertices = builder.vertices;
|
||||
def.stride = sizeof( b3Vec3 );
|
||||
def.vertexCount = builder.vertexCount;
|
||||
def.indices = builder.indices;
|
||||
def.triangleCount = builder.indexCount / 3;
|
||||
def.weldVertices = true;
|
||||
def.weldTolerance = 0.001f;
|
||||
def.identifyEdges = true;
|
||||
return b3CreateMesh( &def, NULL, 0 );
|
||||
}
|
||||
|
||||
// Local state and 24 bits per draw, which the global 15 bit generator in utils.h does not give
|
||||
typedef struct OracleRandom
|
||||
{
|
||||
uint32_t state;
|
||||
} OracleRandom;
|
||||
|
||||
static float RandomUnit( OracleRandom* random )
|
||||
{
|
||||
uint32_t x = random->state;
|
||||
x ^= x << 13;
|
||||
x ^= x >> 17;
|
||||
x ^= x << 5;
|
||||
random->state = x;
|
||||
return (float)( x >> 8 ) / 16777216.0f;
|
||||
}
|
||||
|
||||
static float RandomRange( OracleRandom* random, float lower, float upper )
|
||||
{
|
||||
return lower + ( upper - lower ) * RandomUnit( random );
|
||||
}
|
||||
|
||||
static b3Vec3 RandomDirection( OracleRandom* random )
|
||||
{
|
||||
for ( int i = 0; i < 16; ++i )
|
||||
{
|
||||
b3Vec3 v = { RandomRange( random, -1.0f, 1.0f ), RandomRange( random, -1.0f, 1.0f ),
|
||||
RandomRange( random, -1.0f, 1.0f ) };
|
||||
float lengthSquared = b3LengthSquared( v );
|
||||
if ( 0.01f < lengthSquared && lengthSquared <= 1.0f )
|
||||
{
|
||||
return b3MulSV( 1.0f / sqrtf( lengthSquared ), v );
|
||||
}
|
||||
}
|
||||
|
||||
return b3Vec3_axisY;
|
||||
}
|
||||
|
||||
// Direction within the given angle of the axis
|
||||
static b3Vec3 RandomTilt( OracleRandom* random, b3Vec3 axis, float maxAngle )
|
||||
{
|
||||
b3Vec3 perp = b3Cross( axis, RandomDirection( random ) );
|
||||
float length = b3Length( perp );
|
||||
if ( length < 1.0e-4f )
|
||||
{
|
||||
return axis;
|
||||
}
|
||||
|
||||
perp = b3MulSV( 1.0f / length, perp );
|
||||
b3CosSin cs = b3ComputeCosSin( RandomRange( random, 0.0f, maxAngle ) );
|
||||
return b3Add( b3MulSV( cs.cosine, axis ), b3MulSV( cs.sine, perp ) );
|
||||
}
|
||||
|
||||
static bool CollectPair( b3Vec3 a, b3Vec3 b, b3Vec3 c, int triangleIndex, void* context )
|
||||
{
|
||||
OracleReference* reference = context;
|
||||
|
||||
// A truncated union would misjudge the pose
|
||||
B3_ASSERT( reference->pairCount < ORACLE_MAX_TRIANGLES );
|
||||
if ( reference->pairCount == ORACLE_MAX_TRIANGLES )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
OraclePair* pair = reference->pairs + reference->pairCount;
|
||||
*pair = (OraclePair){ 0 };
|
||||
pair->triangleIndex = triangleIndex;
|
||||
pair->vertices[0] = a;
|
||||
pair->vertices[1] = b;
|
||||
pair->vertices[2] = c;
|
||||
pair->faceNormal = b3Normalize( b3Cross( b3Sub( b, a ), b3Sub( c, a ) ) );
|
||||
pair->owned = true;
|
||||
pair->dominatedBy = -1;
|
||||
reference->pairCount += 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
// From Real-time Collision Detection, p141
|
||||
static b3Vec3 ClosestPointOnTriangle( b3Vec3 p, b3Vec3 a, b3Vec3 b, b3Vec3 c )
|
||||
{
|
||||
b3Vec3 ab = b3Sub( b, a );
|
||||
b3Vec3 ac = b3Sub( c, a );
|
||||
b3Vec3 ap = b3Sub( p, a );
|
||||
float d1 = b3Dot( ab, ap );
|
||||
float d2 = b3Dot( ac, ap );
|
||||
if ( d1 <= 0.0f && d2 <= 0.0f )
|
||||
{
|
||||
return a;
|
||||
}
|
||||
|
||||
b3Vec3 bp = b3Sub( p, b );
|
||||
float d3 = b3Dot( ab, bp );
|
||||
float d4 = b3Dot( ac, bp );
|
||||
if ( d3 >= 0.0f && d4 <= d3 )
|
||||
{
|
||||
return b;
|
||||
}
|
||||
|
||||
float vc = d1 * d4 - d3 * d2;
|
||||
if ( vc <= 0.0f && d1 >= 0.0f && d3 <= 0.0f )
|
||||
{
|
||||
return b3MulAdd( a, d1 / ( d1 - d3 ), ab );
|
||||
}
|
||||
|
||||
b3Vec3 cp = b3Sub( p, c );
|
||||
float d5 = b3Dot( ab, cp );
|
||||
float d6 = b3Dot( ac, cp );
|
||||
if ( d6 >= 0.0f && d5 <= d6 )
|
||||
{
|
||||
return c;
|
||||
}
|
||||
|
||||
float vb = d5 * d2 - d1 * d6;
|
||||
if ( vb <= 0.0f && d2 >= 0.0f && d6 <= 0.0f )
|
||||
{
|
||||
return b3MulAdd( a, d2 / ( d2 - d6 ), ac );
|
||||
}
|
||||
|
||||
float va = d3 * d6 - d5 * d4;
|
||||
if ( va <= 0.0f && ( d4 - d3 ) >= 0.0f && ( d5 - d6 ) >= 0.0f )
|
||||
{
|
||||
float w = ( d4 - d3 ) / ( ( d4 - d3 ) + ( d5 - d6 ) );
|
||||
return b3MulAdd( b, w, b3Sub( c, b ) );
|
||||
}
|
||||
|
||||
float denom = 1.0f / ( va + vb + vc );
|
||||
float v = vb * denom;
|
||||
float w = vc * denom;
|
||||
return b3Add( a, b3Add( b3MulSV( v, ab ), b3MulSV( w, ac ) ) );
|
||||
}
|
||||
|
||||
// The closest pair of each nearby triangle and the union distance
|
||||
static float ComputePairs( OracleReference* reference, const b3MeshData* mesh, const b3HullData* hull, b3Transform transform )
|
||||
{
|
||||
reference->pairCount = 0;
|
||||
|
||||
b3AABB bounds = b3ComputeHullAABB( hull, transform );
|
||||
// Collided points can be well past the speculative distance and the proximal test looks around them
|
||||
float margin = 0.25f;
|
||||
bounds.lowerBound = b3Sub( bounds.lowerBound, (b3Vec3){ margin, margin, margin } );
|
||||
bounds.upperBound = b3Add( bounds.upperBound, (b3Vec3){ margin, margin, margin } );
|
||||
|
||||
b3Mesh meshShape = { .data = (b3MeshData*)mesh, .scale = b3Vec3_one };
|
||||
b3QueryMesh( &meshShape, bounds, CollectPair, reference );
|
||||
|
||||
float minDistance = FLT_MAX;
|
||||
for ( int i = 0; i < reference->pairCount; ++i )
|
||||
{
|
||||
OraclePair* pair = reference->pairs + i;
|
||||
b3DistanceInput input = { 0 };
|
||||
input.proxyA = (b3ShapeProxy){ pair->vertices, 3, 0.0f };
|
||||
input.proxyB = (b3ShapeProxy){ b3GetHullPoints( hull ), hull->vertexCount, 0.0f };
|
||||
input.transform = transform;
|
||||
input.useRadii = false;
|
||||
b3SimplexCache cache = { 0 };
|
||||
b3DistanceOutput output = b3ShapeDistance( &input, &cache, NULL, 0 );
|
||||
pair->meshPoint = output.pointA;
|
||||
pair->hullPoint = output.pointB;
|
||||
pair->normal = output.normal;
|
||||
pair->distance = output.distance;
|
||||
|
||||
if ( output.distance < minDistance )
|
||||
{
|
||||
minDistance = output.distance;
|
||||
reference->closestMeshPoint = output.pointA;
|
||||
reference->closestHullPoint = output.pointB;
|
||||
}
|
||||
}
|
||||
|
||||
reference->distance = minDistance;
|
||||
return minDistance;
|
||||
}
|
||||
|
||||
#define ORACLE_CONTAIN_TOLERANCE 1.0e-4f
|
||||
|
||||
static bool TriangleContains( const OraclePair* pair, b3Vec3 point )
|
||||
{
|
||||
b3Vec3 closest = ClosestPointOnTriangle( point, pair->vertices[0], pair->vertices[1], pair->vertices[2] );
|
||||
return b3DistanceSquared( closest, point ) < ORACLE_CONTAIN_TOLERANCE * ORACLE_CONTAIN_TOLERANCE;
|
||||
}
|
||||
|
||||
// A closest pair is a contact of the union unless a closer triangle also contains its mesh point
|
||||
static void ComputeOwnership( OracleReference* reference )
|
||||
{
|
||||
// Ties along shared features differ only by GJK round off
|
||||
float tieTolerance = 0.02f * B3_LINEAR_SLOP;
|
||||
|
||||
for ( int i = 0; i < reference->pairCount; ++i )
|
||||
{
|
||||
OraclePair* pair = reference->pairs + i;
|
||||
pair->owned = true;
|
||||
pair->dominatedBy = -1;
|
||||
for ( int j = 0; j < reference->pairCount; ++j )
|
||||
{
|
||||
const OraclePair* other = reference->pairs + j;
|
||||
if ( j == i || other->distance >= pair->distance - tieTolerance )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( TriangleContains( other, pair->meshPoint ) )
|
||||
{
|
||||
pair->owned = false;
|
||||
pair->dominatedBy = other->triangleIndex;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// On success the reference holds the closest pairs of the returned pose
|
||||
static bool MakeOraclePose( OracleReference* reference, const b3MeshData* mesh, OracleScene scene, int index, b3BoxHull* box,
|
||||
b3Transform* transform )
|
||||
{
|
||||
OracleRandom random = { 0x9E3779B9u ^ ( 2654435761u * (uint32_t)( index + 1 ) ) ^ ( 40503u * (uint32_t)scene ) };
|
||||
for ( int i = 0; i < 4; ++i )
|
||||
{
|
||||
RandomUnit( &random );
|
||||
}
|
||||
|
||||
const b3Vec3* vertices = b3GetMeshVertices( mesh );
|
||||
const b3MeshTriangle* triangles = b3GetMeshTriangles( mesh );
|
||||
int triangleIndex = (int)( RandomUnit( &random ) * mesh->triangleCount );
|
||||
triangleIndex = triangleIndex < mesh->triangleCount ? triangleIndex : mesh->triangleCount - 1;
|
||||
b3Vec3 a = vertices[triangles[triangleIndex].index1];
|
||||
b3Vec3 b = vertices[triangles[triangleIndex].index2];
|
||||
b3Vec3 c = vertices[triangles[triangleIndex].index3];
|
||||
b3Vec3 faceNormal = b3Normalize( b3Cross( b3Sub( b, a ), b3Sub( c, a ) ) );
|
||||
|
||||
float u = RandomUnit( &random );
|
||||
float v = RandomUnit( &random );
|
||||
if ( u + v > 1.0f )
|
||||
{
|
||||
u = 1.0f - u;
|
||||
v = 1.0f - v;
|
||||
}
|
||||
|
||||
b3Vec3 target = b3Add( a, b3Add( b3MulSV( u, b3Sub( b, a ) ), b3MulSV( v, b3Sub( c, a ) ) ) );
|
||||
|
||||
float hx = RandomRange( &random, 0.05f, 0.4f );
|
||||
float hy = RandomRange( &random, 0.05f, 0.4f );
|
||||
float hz = RandomRange( &random, 0.05f, 0.4f );
|
||||
*box = b3MakeBoxHull( hx, hy, hz );
|
||||
|
||||
// Half the boxes rest nearly flat on the face, where parallel faces make ties
|
||||
b3Quat rotation;
|
||||
if ( RandomUnit( &random ) < 0.5f )
|
||||
{
|
||||
b3Vec3 up = RandomTilt( &random, faceNormal, 0.2f );
|
||||
b3Quat align = b3ComputeQuatBetweenUnitVectors( b3Vec3_axisY, up );
|
||||
b3Quat yaw = b3MakeQuatFromAxisAngle( b3Vec3_axisY, RandomRange( &random, -B3_PI, B3_PI ) );
|
||||
rotation = b3MulQuat( align, yaw );
|
||||
}
|
||||
else
|
||||
{
|
||||
b3Vec3 axis = RandomDirection( &random );
|
||||
rotation = b3MakeQuatFromAxisAngle( axis, RandomRange( &random, -B3_PI, B3_PI ) );
|
||||
}
|
||||
|
||||
b3Vec3 approach = RandomTilt( &random, faceNormal, 1.0f );
|
||||
|
||||
// Put the hull support point against the target
|
||||
const b3Vec3* hullPoints = b3GetHullPoints( &box->base );
|
||||
b3Vec3 localDirection = b3InvRotateVector( rotation, b3Neg( approach ) );
|
||||
b3Vec3 support = hullPoints[0];
|
||||
for ( int i = 1; i < box->base.vertexCount; ++i )
|
||||
{
|
||||
if ( b3Dot( hullPoints[i], localDirection ) > b3Dot( support, localDirection ) )
|
||||
{
|
||||
support = hullPoints[i];
|
||||
}
|
||||
}
|
||||
|
||||
float linearSlop = B3_LINEAR_SLOP;
|
||||
float gap = linearSlop * ( 0.2f + 3.4f * RandomUnit( &random ) * RandomUnit( &random ) );
|
||||
b3Transform pose = { b3Sub( target, b3RotateVector( rotation, support ) ), rotation };
|
||||
pose.p = b3MulAdd( pose.p, gap, approach );
|
||||
|
||||
for ( int iteration = 0; iteration < 20; ++iteration )
|
||||
{
|
||||
*transform = pose;
|
||||
|
||||
float distance = ComputePairs( reference, mesh, &box->base, pose );
|
||||
if ( reference->pairCount == 0 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( distance <= 0.0f )
|
||||
{
|
||||
pose.p = b3MulAdd( pose.p, 2.0f * linearSlop, approach );
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( b3AbsFloat( distance - gap ) < 0.05f * linearSlop )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
b3Vec3 direction = b3Normalize( b3Sub( reference->closestHullPoint, reference->closestMeshPoint ) );
|
||||
pose.p = b3MulAdd( pose.p, gap - distance, direction );
|
||||
}
|
||||
|
||||
*transform = pose;
|
||||
float distance = ComputePairs( reference, mesh, &box->base, pose );
|
||||
return reference->pairCount > 0 && ORACLE_MIN_DISTANCE <= distance && distance <= B3_SPECULATIVE_DISTANCE;
|
||||
}
|
||||
|
||||
// Smallest squared sine between the normal and the face normal of a triangle that contains the mesh
|
||||
// point and faces the normal. FLT_MAX if there is no such triangle.
|
||||
static float FacingSineSquared( const OracleReference* reference, b3Vec3 meshPoint, b3Vec3 normal )
|
||||
{
|
||||
float best = FLT_MAX;
|
||||
for ( int i = 0; i < reference->pairCount; ++i )
|
||||
{
|
||||
const OraclePair* pair = reference->pairs + i;
|
||||
if ( b3Dot( pair->faceNormal, normal ) <= 0.0f || TriangleContains( pair, meshPoint ) == false )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
best = b3MinFloat( best, b3LengthSquared( b3Cross( pair->faceNormal, normal ) ) );
|
||||
}
|
||||
|
||||
return best;
|
||||
}
|
||||
|
||||
// The mesh point is the closest union point to a point a little way out along the normal
|
||||
static bool IsProximalNormal( const OracleReference* reference, b3Vec3 meshPoint, b3Vec3 normal, float sinTolerance )
|
||||
{
|
||||
float probeDistance = 0.01f;
|
||||
b3Vec3 probe = b3MulAdd( meshPoint, probeDistance, normal );
|
||||
float bestDistanceSquared = FLT_MAX;
|
||||
b3Vec3 best = meshPoint;
|
||||
for ( int i = 0; i < reference->pairCount; ++i )
|
||||
{
|
||||
const OraclePair* pair = reference->pairs + i;
|
||||
b3Vec3 closest = ClosestPointOnTriangle( probe, pair->vertices[0], pair->vertices[1], pair->vertices[2] );
|
||||
float distanceSquared = b3DistanceSquared( closest, probe );
|
||||
if ( distanceSquared < bestDistanceSquared )
|
||||
{
|
||||
bestDistanceSquared = distanceSquared;
|
||||
best = closest;
|
||||
}
|
||||
}
|
||||
|
||||
float offset = sinTolerance * probeDistance;
|
||||
return b3DistanceSquared( best, meshPoint ) < offset * offset;
|
||||
}
|
||||
|
||||
// Collides the hull and judges every manifold against the reference
|
||||
static void JudgeCollision( OracleResult* result, const OracleReference* reference, const b3MeshData* mesh,
|
||||
const b3HullData* hull, b3Transform transform, bool handleGhosts )
|
||||
{
|
||||
result->pointCount = 0;
|
||||
result->ghostCount = 0;
|
||||
result->missed = false;
|
||||
|
||||
b3Manifold manifolds[ORACLE_MAX_MANIFOLDS];
|
||||
b3Mesh meshShape = { .data = (b3MeshData*)mesh, .scale = b3Vec3_one };
|
||||
int manifoldCount =
|
||||
b3CollideMeshAndHull( manifolds, ORACLE_MAX_MANIFOLDS, &meshShape, hull, transform, true, handleGhosts );
|
||||
B3_ASSERT( manifoldCount < ORACLE_MAX_MANIFOLDS );
|
||||
|
||||
// Clustering merges manifolds whose normals are within about 5 degrees
|
||||
float sinTolerance = 0.1f;
|
||||
float minSeparation = FLT_MAX;
|
||||
for ( int i = 0; i < manifoldCount; ++i )
|
||||
{
|
||||
const b3Manifold* manifold = manifolds + i;
|
||||
int firstPoint = result->pointCount;
|
||||
for ( int j = 0; j < manifold->pointCount; ++j )
|
||||
{
|
||||
B3_ASSERT( result->pointCount < ORACLE_MAX_POINTS );
|
||||
if ( result->pointCount == ORACLE_MAX_POINTS )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
const b3ManifoldPoint* manifoldPoint = manifold->points + j;
|
||||
OraclePoint* point = result->points + result->pointCount;
|
||||
point->point = manifoldPoint->anchorA;
|
||||
point->meshPoint = manifoldPoint->anchorA;
|
||||
point->normal = manifold->normal;
|
||||
point->separation = manifoldPoint->separation + B3_MESH_REST_OFFSET;
|
||||
point->triangleIndex = manifoldPoint->triangleIndex;
|
||||
point->verdict = e_oracleGhost;
|
||||
result->pointCount += 1;
|
||||
|
||||
minSeparation = b3MinFloat( minSeparation, point->separation );
|
||||
|
||||
const OraclePair* pair = NULL;
|
||||
for ( int k = 0; k < reference->pairCount; ++k )
|
||||
{
|
||||
if ( reference->pairs[k].triangleIndex == point->triangleIndex )
|
||||
{
|
||||
pair = reference->pairs + k;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// The reference bounds contain the collider bounds, so every collided triangle has a pair
|
||||
B3_ASSERT( pair != NULL );
|
||||
if ( pair == NULL )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
b3Vec3 meshPoint =
|
||||
ClosestPointOnTriangle( point->point, pair->vertices[0], pair->vertices[1], pair->vertices[2] );
|
||||
point->meshPoint = meshPoint;
|
||||
|
||||
// A proximal normal also has to be in front of a face here, or an inverted face normal would pass
|
||||
float sineSquared = FacingSineSquared( reference, meshPoint, point->normal );
|
||||
if ( sineSquared < sinTolerance * sinTolerance )
|
||||
{
|
||||
point->verdict = e_oracleFace;
|
||||
}
|
||||
else if ( sineSquared < FLT_MAX && IsProximalNormal( reference, meshPoint, point->normal, sinTolerance ) )
|
||||
{
|
||||
point->verdict = e_oracleFeature;
|
||||
}
|
||||
}
|
||||
|
||||
float deepest = FLT_MAX;
|
||||
for ( int j = firstPoint; j < result->pointCount; ++j )
|
||||
{
|
||||
deepest = b3MinFloat( deepest, result->points[j].separation );
|
||||
}
|
||||
|
||||
bool valid = false;
|
||||
for ( int j = firstPoint; j < result->pointCount; ++j )
|
||||
{
|
||||
const OraclePoint* point = result->points + j;
|
||||
if ( point->separation <= deepest + B3_LINEAR_SLOP && point->verdict != e_oracleGhost )
|
||||
{
|
||||
valid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for ( int j = firstPoint; j < result->pointCount && valid; ++j )
|
||||
{
|
||||
OraclePoint* point = result->points + j;
|
||||
point->verdict = point->verdict == e_oracleGhost ? e_oracleShared : point->verdict;
|
||||
}
|
||||
|
||||
if ( valid == false && result->pointCount > firstPoint )
|
||||
{
|
||||
result->ghostCount += 1;
|
||||
}
|
||||
}
|
||||
|
||||
// The union closest pair has to be represented. SAT separation is a lower bound on distance.
|
||||
float linearSlop = B3_LINEAR_SLOP;
|
||||
float distance = reference->distance;
|
||||
if ( distance < B3_SPECULATIVE_DISTANCE - linearSlop && minSeparation > distance + linearSlop )
|
||||
{
|
||||
result->missed = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool EvaluateOraclePose( OraclePose* pose, const b3MeshData* mesh, OracleScene scene, int index )
|
||||
{
|
||||
if ( MakeOraclePose( &pose->reference, mesh, scene, index, &pose->box, &pose->transform ) == false )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
B3_ASSERT( pose->reference.distance >= ORACLE_MIN_DISTANCE );
|
||||
ComputeOwnership( &pose->reference );
|
||||
|
||||
const b3HullData* hull = &pose->box.base;
|
||||
JudgeCollision( &pose->raw, &pose->reference, mesh, hull, pose->transform, false );
|
||||
JudgeCollision( &pose->handled, &pose->reference, mesh, hull, pose->transform, true );
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IsOracleCullingMiss( const OraclePose* pose )
|
||||
{
|
||||
return pose->handled.missed && pose->raw.missed == false;
|
||||
}
|
||||
|
||||
OracleScan ScanGhostOracle( const b3MeshData* mesh, OracleScene scene, int poseCount )
|
||||
{
|
||||
static OraclePose pose;
|
||||
OracleScan scan = { 0 };
|
||||
scan.firstGhost = -1;
|
||||
scan.firstMissed = -1;
|
||||
|
||||
for ( int i = 0; i < poseCount; ++i )
|
||||
{
|
||||
if ( EvaluateOraclePose( &pose, mesh, scene, i ) == false )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
scan.validCount += 1;
|
||||
scan.rawGhostPoses += pose.raw.ghostCount > 0 ? 1 : 0;
|
||||
|
||||
if ( pose.handled.ghostCount > 0 )
|
||||
{
|
||||
scan.ghostPoses += 1;
|
||||
scan.firstGhost = scan.firstGhost < 0 ? i : scan.firstGhost;
|
||||
}
|
||||
|
||||
if ( IsOracleCullingMiss( &pose ) )
|
||||
{
|
||||
scan.missedPoses += 1;
|
||||
scan.firstMissed = scan.firstMissed < 0 ? i : scan.firstMissed;
|
||||
}
|
||||
}
|
||||
|
||||
return scan;
|
||||
}
|
||||
168
shared/ghost_oracle.h
Normal file
168
shared/ghost_oracle.h
Normal file
|
|
@ -0,0 +1,168 @@
|
|||
// SPDX-FileCopyrightText: 2026 Erin Catto
|
||||
// SPDX-License-Identifier: MIT
|
||||
#pragma once
|
||||
|
||||
#include "box3d/collision.h"
|
||||
#include "box3d/math_functions.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
// Separated-pose oracle for mesh ghost handling. With the hull clear of the mesh the union of the
|
||||
// triangles is the reference surface, and none of the Voronoi logic under test is needed to judge a
|
||||
// contact against it.
|
||||
//
|
||||
// A normal is valid at a mesh location when the union has it there: the face normal of a triangle
|
||||
// containing the location, or a proximal normal, meaning the location is the closest union point to a
|
||||
// point a little way out along the normal. That second test gives the convex edge wedge and the vertex
|
||||
// cone exactly, and nothing at a concave crease beyond the two face normals. A manifold shares one normal
|
||||
// across its points, so it is a ghost when the normal is valid at none of its points within linear slop of
|
||||
// its deepest.
|
||||
//
|
||||
// The contacts the union itself has are the local minima of the distance between the hull and the
|
||||
// union. A triangle's closest pair (GJK) is one unless a triangle that also contains its mesh point is
|
||||
// closer to the hull. The distance to a triangle is convex over the triangle, so that test is exact. The
|
||||
// union closest pair must be represented by a collided point, otherwise the contact was missed.
|
||||
|
||||
typedef enum OracleScene
|
||||
{
|
||||
e_oracleFlat,
|
||||
e_oracleFan,
|
||||
e_oracleCrest,
|
||||
e_oracleValley,
|
||||
e_oracleRidge,
|
||||
e_oracleSaddleRidge,
|
||||
e_oracleRail,
|
||||
e_oracleWave,
|
||||
e_oracleSceneCount
|
||||
} OracleScene;
|
||||
|
||||
extern const char* g_oracleSceneNames[e_oracleSceneCount];
|
||||
|
||||
#define ORACLE_MAX_TRIANGLES 256
|
||||
#define ORACLE_MAX_POINTS 128
|
||||
|
||||
// Poses per scene in the unit test, and in the sample scan so the two report the same counts
|
||||
#define ORACLE_SCAN_POSES 500
|
||||
|
||||
typedef enum OracleVerdict
|
||||
{
|
||||
// Face normal of a triangle containing the point
|
||||
e_oracleFace,
|
||||
|
||||
// Proximal normal at an edge or vertex
|
||||
e_oracleFeature,
|
||||
|
||||
// Not valid here, but valid at a deep point of the same manifold
|
||||
e_oracleShared,
|
||||
|
||||
// Point of a manifold whose normal is valid at none of its deep points
|
||||
e_oracleGhost,
|
||||
} OracleVerdict;
|
||||
|
||||
typedef struct OraclePair
|
||||
{
|
||||
int triangleIndex;
|
||||
b3Vec3 vertices[3];
|
||||
b3Vec3 faceNormal;
|
||||
b3Vec3 meshPoint;
|
||||
b3Vec3 hullPoint;
|
||||
b3Vec3 normal;
|
||||
float distance;
|
||||
bool owned;
|
||||
|
||||
// Triangle index of a closer triangle containing the mesh point, or -1
|
||||
int dominatedBy;
|
||||
} OraclePair;
|
||||
|
||||
// The union of the triangles near the hull. Depends only on the pose, not on the collider.
|
||||
typedef struct OracleReference
|
||||
{
|
||||
// Distance between the hull and the mesh
|
||||
float distance;
|
||||
b3Vec3 closestMeshPoint;
|
||||
b3Vec3 closestHullPoint;
|
||||
|
||||
OraclePair pairs[ORACLE_MAX_TRIANGLES];
|
||||
int pairCount;
|
||||
} OracleReference;
|
||||
|
||||
typedef struct OraclePoint
|
||||
{
|
||||
b3Vec3 point;
|
||||
|
||||
// Closest point on the point's triangle
|
||||
b3Vec3 meshPoint;
|
||||
b3Vec3 normal;
|
||||
|
||||
// Geometric separation, without the mesh rest offset the collider subtracts
|
||||
float separation;
|
||||
int triangleIndex;
|
||||
OracleVerdict verdict;
|
||||
} OraclePoint;
|
||||
|
||||
// The collider output judged against the reference
|
||||
typedef struct OracleResult
|
||||
{
|
||||
OraclePoint points[ORACLE_MAX_POINTS];
|
||||
int pointCount;
|
||||
|
||||
// Ghost manifolds
|
||||
int ghostCount;
|
||||
|
||||
// The union closest pair has no collided point
|
||||
bool missed;
|
||||
} OracleResult;
|
||||
|
||||
typedef struct OraclePose
|
||||
{
|
||||
b3BoxHull box;
|
||||
b3Transform transform;
|
||||
OracleReference reference;
|
||||
|
||||
// Collided without and with ghost handling
|
||||
OracleResult raw;
|
||||
OracleResult handled;
|
||||
} OraclePose;
|
||||
|
||||
typedef struct OracleScan
|
||||
{
|
||||
// Separated poses
|
||||
int validCount;
|
||||
|
||||
// Poses with a ghost manifold, without and with ghost handling
|
||||
int rawGhostPoses;
|
||||
int ghostPoses;
|
||||
|
||||
// Poses where ghost handling lost the closest pair
|
||||
int missedPoses;
|
||||
|
||||
// Pose indices, -1 for none
|
||||
int firstGhost;
|
||||
int firstMissed;
|
||||
} OracleScan;
|
||||
|
||||
// The poses keep the hull separated by at least this much, where the closest direction is well defined
|
||||
#define ORACLE_MIN_DISTANCE ( 0.1f * B3_LINEAR_SLOP )
|
||||
|
||||
// Caller destroys with b3DestroyMesh
|
||||
b3MeshData* CreateOracleMesh( OracleScene scene );
|
||||
|
||||
// Deterministic random box and pose for the scene and index, separated from the mesh by
|
||||
// [ORACLE_MIN_DISTANCE, B3_SPECULATIVE_DISTANCE], collided and judged with and without ghost handling.
|
||||
// Returns false if no separated pose was found, in which case the reference and results mean nothing.
|
||||
bool EvaluateOraclePose( OraclePose* pose, const b3MeshData* mesh, OracleScene scene, int index );
|
||||
|
||||
// A miss counts against ghost handling only when the collider represents the closest pair without it
|
||||
bool IsOracleCullingMiss( const OraclePose* pose );
|
||||
|
||||
// Poses [0, poseCount) of the scene
|
||||
OracleScan ScanGhostOracle( const b3MeshData* mesh, OracleScene scene, int poseCount );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
355
shared/mesh_drop.c
Normal file
355
shared/mesh_drop.c
Normal file
|
|
@ -0,0 +1,355 @@
|
|||
// SPDX-FileCopyrightText: 2026 Erin Catto
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "mesh_drop.h"
|
||||
|
||||
#include "box3d/box3d.h"
|
||||
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
|
||||
#define WAVE_CELL_WIDTH 1.0f
|
||||
#define WAVE_ROW_FREQUENCY 0.1f
|
||||
#define WAVE_COLUMN_FREQUENCY 0.2f
|
||||
#define DROP_SPACING 0.5f
|
||||
#define DROP_HEIGHT 5.0f
|
||||
#define BODY_RADIUS 0.05f
|
||||
#define CAPSULE_HALF_LENGTH 0.2f
|
||||
|
||||
const char* g_meshDropShapeNames[e_meshDropShapeCount] = { "box", "capsule", "cylinder", "sphere" };
|
||||
|
||||
const float g_meshDropDepthLevels[MESH_DROP_DEPTH_LEVEL_COUNT] = { 4.0f, 8.0f, 16.0f, 32.0f };
|
||||
|
||||
// Same XorShift32 and mapping as the samples, but with local state so worlds can run on many threads
|
||||
static float RandomFloatRange( uint32_t* state, float lo, float hi )
|
||||
{
|
||||
uint32_t x = *state;
|
||||
x ^= x << 13;
|
||||
x ^= x >> 17;
|
||||
x ^= x << 5;
|
||||
*state = x;
|
||||
|
||||
int i = (int)( x % 32768 );
|
||||
float r = (float)( i & 32767 ) / 32767.0f;
|
||||
return ( hi - lo ) * r + lo;
|
||||
}
|
||||
|
||||
static b3Vec3 RandomVec3Uniform( uint32_t* state, float lo, float hi )
|
||||
{
|
||||
b3Vec3 v;
|
||||
v.x = RandomFloatRange( state, lo, hi );
|
||||
v.y = RandomFloatRange( state, lo, hi );
|
||||
v.z = RandomFloatRange( state, lo, hi );
|
||||
return v;
|
||||
}
|
||||
|
||||
static uint32_t HashSeed( uint32_t x )
|
||||
{
|
||||
x ^= x >> 16;
|
||||
x *= 0x7feb352du;
|
||||
x ^= x >> 15;
|
||||
x *= 0x846ca68bu;
|
||||
x ^= x >> 16;
|
||||
return x != 0 ? x : 1;
|
||||
}
|
||||
|
||||
static b3BoxHull MakeDropBox( void )
|
||||
{
|
||||
// The soft contact solver cannot always resolve a smaller box at 4 sub-steps, and its size gets
|
||||
// close to the time of impact tolerances
|
||||
return b3MakeBoxHull( 0.02f, 0.2f, 0.04f );
|
||||
}
|
||||
|
||||
MeshDropSettings GetDefaultMeshDropSettings( void )
|
||||
{
|
||||
MeshDropSettings settings = {
|
||||
.shape = e_meshDropBox,
|
||||
.amplitude = 0.5f,
|
||||
.collide = false,
|
||||
.soloIndex = -1,
|
||||
};
|
||||
return settings;
|
||||
}
|
||||
|
||||
uint32_t GetMeshDropSeed( uint32_t baseSeed, int generation )
|
||||
{
|
||||
return HashSeed( HashSeed( baseSeed ) + (uint32_t)generation );
|
||||
}
|
||||
|
||||
int GetMeshDropStepLimit( MeshDropShape shape )
|
||||
{
|
||||
return shape == e_meshDropCapsule ? 3000 : 1000;
|
||||
}
|
||||
|
||||
float GetMeshDropTunnelHeight( void )
|
||||
{
|
||||
return -2.0f;
|
||||
}
|
||||
|
||||
b3MeshData* CreateMeshDropMesh( float amplitude )
|
||||
{
|
||||
return b3CreateWaveMesh( MESH_DROP_WAVE_COUNT, MESH_DROP_WAVE_COUNT, WAVE_CELL_WIDTH, amplitude, WAVE_ROW_FREQUENCY,
|
||||
WAVE_COLUMN_FREQUENCY );
|
||||
}
|
||||
|
||||
b3HullData* CreateMeshDropCylinder( void )
|
||||
{
|
||||
return b3CreateCylinder( 0.4f, BODY_RADIUS, 0.0f, 6 );
|
||||
}
|
||||
|
||||
b3BodyId CreateMeshDropGround( b3WorldId worldId, const b3MeshData* mesh )
|
||||
{
|
||||
b3BodyDef bodyDef = b3DefaultBodyDef();
|
||||
b3BodyId groundId = b3CreateBody( worldId, &bodyDef );
|
||||
|
||||
b3ShapeDef shapeDef = b3DefaultShapeDef();
|
||||
shapeDef.filter.categoryBits = 1;
|
||||
b3CreateMeshShape( groundId, &shapeDef, mesh, b3Vec3_one );
|
||||
|
||||
float extent = 0.5f * MESH_DROP_WAVE_COUNT * WAVE_CELL_WIDTH;
|
||||
float halfHeight = 1.0f;
|
||||
|
||||
b3Transform transforms[4] = {
|
||||
{ { 0.0f, halfHeight, -extent }, b3Quat_identity },
|
||||
{ { 0.0f, halfHeight, extent }, b3Quat_identity },
|
||||
{ { -extent, halfHeight, 0.0f }, b3Quat_identity },
|
||||
{ { extent, halfHeight, 0.0f }, b3Quat_identity },
|
||||
};
|
||||
|
||||
for ( int i = 0; i < 4; ++i )
|
||||
{
|
||||
float hx = i < 2 ? extent : 0.1f;
|
||||
float hz = i < 2 ? 0.1f : extent;
|
||||
b3BoxHull wallBox = b3MakeTransformedBoxHull( hx, halfHeight, hz, transforms[i] );
|
||||
b3CreateHullShape( groundId, &shapeDef, &wallBox.base );
|
||||
}
|
||||
|
||||
return groundId;
|
||||
}
|
||||
|
||||
void CreateMeshDropBodies( b3WorldId worldId, MeshDropSettings settings, uint32_t seed, const b3HullData* cylinder,
|
||||
b3BodyId* bodies )
|
||||
{
|
||||
b3BoxHull box = MakeDropBox();
|
||||
b3Capsule capsule = { { 0.0f, -CAPSULE_HALF_LENGTH, 0.0f }, { 0.0f, CAPSULE_HALF_LENGTH, 0.0f }, BODY_RADIUS };
|
||||
b3Sphere sphere = { b3Vec3_zero, BODY_RADIUS };
|
||||
|
||||
b3BodyDef bodyDef = b3DefaultBodyDef();
|
||||
bodyDef.type = b3_dynamicBody;
|
||||
|
||||
b3ShapeDef shapeDef = b3DefaultShapeDef();
|
||||
bool round = settings.shape == e_meshDropCapsule || settings.shape == e_meshDropSphere;
|
||||
shapeDef.baseMaterial.rollingResistance = round ? 0.4f : 0.1f;
|
||||
|
||||
if ( settings.collide == false )
|
||||
{
|
||||
shapeDef.filter.categoryBits = 2;
|
||||
shapeDef.filter.maskBits = 1;
|
||||
}
|
||||
|
||||
uint32_t state = seed;
|
||||
int index = 0;
|
||||
for ( int i = 0; i < MESH_DROP_GRID_COUNT; ++i )
|
||||
{
|
||||
for ( int j = 0; j < MESH_DROP_GRID_COUNT; ++j )
|
||||
{
|
||||
// Draw for every body so a solo body gets the same velocity it has in the full drop
|
||||
b3Vec3 linearVelocity = RandomVec3Uniform( &state, -1.0f, 1.0f );
|
||||
b3Vec3 angularVelocity = RandomVec3Uniform( &state, -5.0f, 5.0f );
|
||||
|
||||
if ( settings.soloIndex >= 0 && settings.soloIndex != index )
|
||||
{
|
||||
bodies[index] = b3_nullBodyId;
|
||||
index += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
bodyDef.position = (b3Pos){ DROP_SPACING * ( i - 0.5f * MESH_DROP_GRID_COUNT ), DROP_HEIGHT,
|
||||
DROP_SPACING * ( j - 0.5f * MESH_DROP_GRID_COUNT ) };
|
||||
bodyDef.linearVelocity = linearVelocity;
|
||||
bodyDef.angularVelocity = angularVelocity;
|
||||
bodyDef.userData = (void*)(intptr_t)( index + 1 );
|
||||
b3BodyId bodyId = b3CreateBody( worldId, &bodyDef );
|
||||
|
||||
switch ( settings.shape )
|
||||
{
|
||||
case e_meshDropBox:
|
||||
b3CreateHullShape( bodyId, &shapeDef, &box.base );
|
||||
break;
|
||||
case e_meshDropCapsule:
|
||||
b3CreateCapsuleShape( bodyId, &shapeDef, &capsule );
|
||||
break;
|
||||
case e_meshDropCylinder:
|
||||
b3CreateHullShape( bodyId, &shapeDef, cylinder );
|
||||
break;
|
||||
default:
|
||||
b3CreateSphereShape( bodyId, &shapeDef, &sphere );
|
||||
break;
|
||||
}
|
||||
|
||||
bodies[index] = bodyId;
|
||||
index += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int GetMeshDropBodyIndex( void* userData )
|
||||
{
|
||||
intptr_t value = (intptr_t)userData;
|
||||
return 1 <= value && value <= MESH_DROP_BODY_COUNT ? (int)value - 1 : -1;
|
||||
}
|
||||
|
||||
void ResetMeshDropDepth( MeshDropDepth* depth, MeshDropSettings settings, const b3HullData* cylinder )
|
||||
{
|
||||
// Same heights as b3CreateWaveMesh
|
||||
float omegaZ = 2.0f * B3_PI * WAVE_ROW_FREQUENCY * WAVE_CELL_WIDTH;
|
||||
float omegaX = 2.0f * B3_PI * WAVE_COLUMN_FREQUENCY * WAVE_CELL_WIDTH;
|
||||
int index = 0;
|
||||
for ( int ix = 0; ix <= MESH_DROP_WAVE_COUNT; ++ix )
|
||||
{
|
||||
float rowHeight = b3ComputeCosSin( omegaX * ix ).sine;
|
||||
for ( int iz = 0; iz <= MESH_DROP_WAVE_COUNT; ++iz )
|
||||
{
|
||||
float columnHeight = b3ComputeCosSin( omegaZ * iz ).sine;
|
||||
depth->heights[index++] = settings.amplitude * rowHeight * columnHeight;
|
||||
}
|
||||
}
|
||||
|
||||
depth->amplitude = fabsf( settings.amplitude );
|
||||
depth->probeCount = 0;
|
||||
depth->radius = 0.0f;
|
||||
|
||||
switch ( settings.shape )
|
||||
{
|
||||
case e_meshDropBox:
|
||||
case e_meshDropCylinder:
|
||||
{
|
||||
b3BoxHull box = MakeDropBox();
|
||||
const b3HullData* hull = settings.shape == e_meshDropBox ? &box.base : cylinder;
|
||||
const b3Vec3* points = b3GetHullPoints( hull );
|
||||
int count = hull->vertexCount < MESH_DROP_MAX_PROBES ? hull->vertexCount : MESH_DROP_MAX_PROBES;
|
||||
for ( int i = 0; i < count; ++i )
|
||||
{
|
||||
depth->probes[i] = points[i];
|
||||
}
|
||||
depth->probeCount = count;
|
||||
}
|
||||
break;
|
||||
|
||||
case e_meshDropCapsule:
|
||||
depth->probes[0] = (b3Vec3){ 0.0f, -CAPSULE_HALF_LENGTH, 0.0f };
|
||||
depth->probes[1] = (b3Vec3){ 0.0f, CAPSULE_HALF_LENGTH, 0.0f };
|
||||
depth->probeCount = 2;
|
||||
depth->radius = BODY_RADIUS;
|
||||
break;
|
||||
|
||||
default:
|
||||
depth->probes[0] = b3Vec3_zero;
|
||||
depth->probeCount = 1;
|
||||
depth->radius = BODY_RADIUS;
|
||||
break;
|
||||
}
|
||||
|
||||
float maxLength = 0.0f;
|
||||
for ( int i = 0; i < depth->probeCount; ++i )
|
||||
{
|
||||
maxLength = fmaxf( maxLength, b3Length( depth->probes[i] ) );
|
||||
}
|
||||
depth->boundingRadius = maxLength + depth->radius;
|
||||
|
||||
for ( int i = 0; i < MESH_DROP_BODY_COUNT; ++i )
|
||||
{
|
||||
depth->bodyDepths[i] = -FLT_MAX;
|
||||
}
|
||||
|
||||
depth->maxDepth = -FLT_MAX;
|
||||
depth->maxIndex = -1;
|
||||
depth->maxStep = 0;
|
||||
depth->stepCount = 0;
|
||||
}
|
||||
|
||||
// Signed distance to the plane of the wave triangle under the point. Exact away from the folds, where
|
||||
// it reads a little deep on a crest and shallow in a valley.
|
||||
static float GetWaveDistance( const MeshDropDepth* depth, b3Vec3 p )
|
||||
{
|
||||
float origin = -0.5f * MESH_DROP_WAVE_COUNT * WAVE_CELL_WIDTH;
|
||||
float u = ( p.x - origin ) / WAVE_CELL_WIDTH;
|
||||
float v = ( p.z - origin ) / WAVE_CELL_WIDTH;
|
||||
int ix = b3ClampInt( (int)floorf( u ), 0, MESH_DROP_WAVE_COUNT - 1 );
|
||||
int iz = b3ClampInt( (int)floorf( v ), 0, MESH_DROP_WAVE_COUNT - 1 );
|
||||
|
||||
int stride = MESH_DROP_WAVE_COUNT + 1;
|
||||
float ha = depth->heights[ix * stride + iz];
|
||||
float hb = depth->heights[ix * stride + iz + 1];
|
||||
float hc = depth->heights[( ix + 1 ) * stride + iz + 1];
|
||||
float hd = depth->heights[( ix + 1 ) * stride + iz];
|
||||
|
||||
// The cell diagonal runs from a to c, matching b3CreateWaveMesh
|
||||
float w = WAVE_CELL_WIDTH;
|
||||
b3Vec3 a = { origin + ix * w, ha, origin + iz * w };
|
||||
b3Vec3 ac = { w, hc - ha, w };
|
||||
b3Vec3 side = v - iz >= u - ix ? (b3Vec3){ 0.0f, hb - ha, w } : (b3Vec3){ w, hd - ha, 0.0f };
|
||||
b3Vec3 normal = b3Normalize( b3Cross( side, ac ) );
|
||||
if ( normal.y < 0.0f )
|
||||
{
|
||||
normal = b3Neg( normal );
|
||||
}
|
||||
|
||||
return b3Dot( normal, b3Sub( p, a ) );
|
||||
}
|
||||
|
||||
void UpdateMeshDropDepth( b3WorldId worldId, MeshDropDepth* depth )
|
||||
{
|
||||
depth->stepCount += 1;
|
||||
|
||||
b3BodyEvents events = b3World_GetBodyEvents( worldId );
|
||||
for ( int i = 0; i < events.moveCount; ++i )
|
||||
{
|
||||
const b3BodyMoveEvent* event = events.moveEvents + i;
|
||||
int index = GetMeshDropBodyIndex( event->userData );
|
||||
if ( index < 0 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
b3WorldTransform transform = event->transform;
|
||||
if ( (float)transform.p.y - depth->boundingRadius > depth->amplitude )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
float sink = -FLT_MAX;
|
||||
for ( int j = 0; j < depth->probeCount; ++j )
|
||||
{
|
||||
b3Pos point = b3TransformWorldPoint( transform, depth->probes[j] );
|
||||
b3Vec3 p = { (float)point.x, (float)point.y, (float)point.z };
|
||||
sink = fmaxf( sink, depth->radius - GetWaveDistance( depth, p ) );
|
||||
}
|
||||
|
||||
if ( sink > depth->bodyDepths[index] )
|
||||
{
|
||||
depth->bodyDepths[index] = sink;
|
||||
}
|
||||
|
||||
if ( sink > depth->maxDepth )
|
||||
{
|
||||
depth->maxDepth = sink;
|
||||
depth->maxIndex = index;
|
||||
depth->maxStep = depth->stepCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GetMeshDropDepthCounts( const MeshDropDepth* depth, int counts[MESH_DROP_DEPTH_LEVEL_COUNT] )
|
||||
{
|
||||
for ( int level = 0; level < MESH_DROP_DEPTH_LEVEL_COUNT; ++level )
|
||||
{
|
||||
float threshold = g_meshDropDepthLevels[level] * B3_LINEAR_SLOP;
|
||||
int count = 0;
|
||||
for ( int i = 0; i < MESH_DROP_BODY_COUNT; ++i )
|
||||
{
|
||||
count += depth->bodyDepths[i] > threshold ? 1 : 0;
|
||||
}
|
||||
counts[level] = count;
|
||||
}
|
||||
}
|
||||
115
shared/mesh_drop.h
Normal file
115
shared/mesh_drop.h
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
// SPDX-FileCopyrightText: 2026 Erin Catto
|
||||
// SPDX-License-Identifier: MIT
|
||||
#pragma once
|
||||
|
||||
#include "box3d/collision.h"
|
||||
#include "box3d/id.h"
|
||||
#include "box3d/math_functions.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
// Mesh Drop scene, shared by the Continuous / Mesh Drop sample and the headless mesh soak. A generation
|
||||
// drops a grid of small bodies with random velocities on a wave mesh and steps until they sleep. A body
|
||||
// that falls out of the world tunneled. The depth tracker measures how far each body sinks into the
|
||||
// wave, which flags contact trouble far more often than tunnels do.
|
||||
|
||||
typedef enum MeshDropShape
|
||||
{
|
||||
e_meshDropBox,
|
||||
e_meshDropCapsule,
|
||||
e_meshDropCylinder,
|
||||
e_meshDropSphere,
|
||||
e_meshDropShapeCount
|
||||
} MeshDropShape;
|
||||
|
||||
#define MESH_DROP_GRID_COUNT 32
|
||||
#define MESH_DROP_BODY_COUNT ( MESH_DROP_GRID_COUNT * MESH_DROP_GRID_COUNT )
|
||||
#define MESH_DROP_DEPTH_LEVEL_COUNT 4
|
||||
|
||||
// Wave mesh cells along x and z
|
||||
#define MESH_DROP_WAVE_COUNT 40
|
||||
|
||||
// Enough for the cylinder hull
|
||||
#define MESH_DROP_MAX_PROBES 16
|
||||
|
||||
extern const char* g_meshDropShapeNames[e_meshDropShapeCount];
|
||||
|
||||
// Sink depth thresholds in linear slop
|
||||
extern const float g_meshDropDepthLevels[MESH_DROP_DEPTH_LEVEL_COUNT];
|
||||
|
||||
typedef struct MeshDropSettings
|
||||
{
|
||||
MeshDropShape shape;
|
||||
float amplitude;
|
||||
|
||||
// Let the bodies collide with each other. Off isolates mesh collision.
|
||||
bool collide;
|
||||
|
||||
// Create only this grid index, or -1 for all. Without body collision a body moves the same alone.
|
||||
int soloIndex;
|
||||
} MeshDropSettings;
|
||||
|
||||
MeshDropSettings GetDefaultMeshDropSettings( void );
|
||||
|
||||
// Hashes the base before adding the generation, so nearby base seeds share no generations
|
||||
uint32_t GetMeshDropSeed( uint32_t baseSeed, int generation );
|
||||
|
||||
// Steps a generation may take to fall asleep
|
||||
int GetMeshDropStepLimit( MeshDropShape shape );
|
||||
|
||||
// A body below this height tunneled
|
||||
float GetMeshDropTunnelHeight( void );
|
||||
|
||||
b3MeshData* CreateMeshDropMesh( float amplitude );
|
||||
b3HullData* CreateMeshDropCylinder( void );
|
||||
|
||||
// Creates a static body with the wave mesh and four walls
|
||||
b3BodyId CreateMeshDropGround( b3WorldId worldId, const b3MeshData* mesh );
|
||||
|
||||
// Creates the bodies of one generation in grid order. Bodies left out by the solo index are null. The
|
||||
// body user data encodes the grid index, see GetMeshDropBodyIndex.
|
||||
void CreateMeshDropBodies( b3WorldId worldId, MeshDropSettings settings, uint32_t seed, const b3HullData* cylinder,
|
||||
b3BodyId* bodies );
|
||||
|
||||
// Grid index from body user data, or -1 if the body is not part of the drop
|
||||
int GetMeshDropBodyIndex( void* userData );
|
||||
|
||||
typedef struct MeshDropDepth
|
||||
{
|
||||
// Wave heights at the mesh vertices
|
||||
float heights[( MESH_DROP_WAVE_COUNT + 1 ) * ( MESH_DROP_WAVE_COUNT + 1 )];
|
||||
|
||||
// Collision points in the body frame, rounded by the radius
|
||||
b3Vec3 probes[MESH_DROP_MAX_PROBES];
|
||||
int probeCount;
|
||||
float radius;
|
||||
float boundingRadius;
|
||||
float amplitude;
|
||||
|
||||
// Deepest sink of each body so far, positive when inside the wave
|
||||
float bodyDepths[MESH_DROP_BODY_COUNT];
|
||||
|
||||
float maxDepth;
|
||||
int maxIndex;
|
||||
int maxStep;
|
||||
int stepCount;
|
||||
} MeshDropDepth;
|
||||
|
||||
// Starts tracking a new generation
|
||||
void ResetMeshDropDepth( MeshDropDepth* depth, MeshDropSettings settings, const b3HullData* cylinder );
|
||||
|
||||
// Call after each world step
|
||||
void UpdateMeshDropDepth( b3WorldId worldId, MeshDropDepth* depth );
|
||||
|
||||
// Number of bodies that sank deeper than each depth level
|
||||
void GetMeshDropDepthCounts( const MeshDropDepth* depth, int counts[MESH_DROP_DEPTH_LEVEL_COUNT] );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
@ -83,6 +83,10 @@
|
|||
</Expand>
|
||||
</Type>
|
||||
|
||||
<Type Name="b3LocalManifoldPoint">
|
||||
<DisplayString>s: {separation}</DisplayString>
|
||||
</Type>
|
||||
|
||||
<Type Name="b3SeparationFunction">
|
||||
<DisplayString>type: {type}</DisplayString>
|
||||
<Expand>
|
||||
|
|
|
|||
|
|
@ -581,6 +581,8 @@ static bool b3ComputeConvexManifold( b3World* world, int workerIndex, b3Contact*
|
|||
target->separation = source->separation;
|
||||
target->featureId = b3MakeFeatureId( source->pair );
|
||||
target->triangleIndex = B3_NULL_INDEX;
|
||||
target->triangleFeature = b3_featureNone;
|
||||
target->meshFlags = 0;
|
||||
target->normalVelocity = 0.0f;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,8 +9,6 @@
|
|||
#include "box3d/collision.h"
|
||||
#include "box3d/types.h"
|
||||
|
||||
#define B3_FORCE_GHOST_COLLISIONS 0
|
||||
|
||||
typedef struct b3Shape b3Shape;
|
||||
typedef struct b3World b3World;
|
||||
|
||||
|
|
|
|||
|
|
@ -990,7 +990,7 @@ static void b3ReduceManifoldPoints( b3LocalManifold* manifold, int capacity, b3L
|
|||
}
|
||||
|
||||
b3Point2D hull[2 * B3_MAX_CLIP_POINTS];
|
||||
int hullCount = b3Hull2D( pts, count, hull );
|
||||
int hullCount = b3Hull2D( pts, count, hull, 0 );
|
||||
int finalCount = b3SimplifyHull2D( hull, hullCount, target );
|
||||
B3_ASSERT( 0 < finalCount && finalCount <= target );
|
||||
|
||||
|
|
|
|||
|
|
@ -99,6 +99,53 @@
|
|||
21 3 22
|
||||
*/
|
||||
|
||||
static b3Vec3 b3GetGridPoint( const float* heights, int columnCount, b3Vec3 scale, int row, int column )
|
||||
{
|
||||
return b3Mul( scale, (b3Vec3){ (float)column, heights[row * columnCount + column], (float)row } );
|
||||
}
|
||||
|
||||
static b3Vec3 b3GetGridTriangleNormal( const float* heights, int columnCount, b3Vec3 scale, int row, int column, bool odd )
|
||||
{
|
||||
b3Vec3 point11 = b3GetGridPoint( heights, columnCount, scale, row, column );
|
||||
b3Vec3 point12 = b3GetGridPoint( heights, columnCount, scale, row, column + 1 );
|
||||
b3Vec3 point21 = b3GetGridPoint( heights, columnCount, scale, row + 1, column );
|
||||
b3Vec3 point22 = b3GetGridPoint( heights, columnCount, scale, row + 1, column + 1 );
|
||||
|
||||
b3Vec3 v1 = odd ? point22 : point11;
|
||||
b3Vec3 v2 = odd ? point12 : point21;
|
||||
b3Vec3 v3 = odd ? point21 : point12;
|
||||
return b3Normalize( b3Cross( b3Sub( v2, v1 ), b3Sub( v3, v1 ) ) );
|
||||
}
|
||||
|
||||
// Mark vertices as flat or concave.
|
||||
static void b3MarkGridEdge( uint8_t* vertexFlags, int index1, int index2, b3Vec3 point1, b3Vec3 point2, b3Vec3 normal1,
|
||||
b3Vec3 normal2, bool clockwise )
|
||||
{
|
||||
b3Vec3 outward = b3Cross( b3Normalize( b3Sub( point2, point1 ) ), normal1 );
|
||||
float angle = b3Atan2( b3Dot( normal2, outward ), b3Dot( normal2, normal1 ) );
|
||||
|
||||
// Quantize to match the mesh rule.
|
||||
int8_t quantized = b3QuantizeEdgeAngle( clockwise ? -angle : angle );
|
||||
|
||||
if ( quantized != 0 )
|
||||
{
|
||||
vertexFlags[index1] = (uint8_t)( vertexFlags[index1] & ~b3_flatVertex );
|
||||
vertexFlags[index2] = (uint8_t)( vertexFlags[index2] & ~b3_flatVertex );
|
||||
}
|
||||
|
||||
if ( quantized < 0 )
|
||||
{
|
||||
vertexFlags[index1] |= b3_concaveVertex;
|
||||
vertexFlags[index2] |= b3_concaveVertex;
|
||||
}
|
||||
}
|
||||
|
||||
static void b3MarkGridBoundary( uint8_t* vertexFlags, int index1, int index2 )
|
||||
{
|
||||
vertexFlags[index1] = (uint8_t)( vertexFlags[index1] & ~b3_flatVertex );
|
||||
vertexFlags[index2] = (uint8_t)( vertexFlags[index2] & ~b3_flatVertex );
|
||||
}
|
||||
|
||||
b3HeightFieldData* b3CreateHeightField( const b3HeightFieldDef* data )
|
||||
{
|
||||
int columnCount = data->countX;
|
||||
|
|
@ -119,6 +166,8 @@ b3HeightFieldData* b3CreateHeightField( const b3HeightFieldDef* data )
|
|||
byteCount += b3AlignUp8( cellCount * sizeof( uint8_t ) );
|
||||
int flagsOffset = (int)byteCount;
|
||||
byteCount += b3AlignUp8( triangleCount * sizeof( uint8_t ) );
|
||||
int vertexFlagOffset = (int)byteCount;
|
||||
byteCount += b3AlignUp8( (size_t)( ( heightCount + 7 ) / 8 ) );
|
||||
|
||||
// Zero the whole blob so alignment padding is defined. The construction-time hash
|
||||
// sweeps raw bytes and would otherwise pick up uninitialized padding.
|
||||
|
|
@ -133,6 +182,7 @@ b3HeightFieldData* b3CreateHeightField( const b3HeightFieldDef* data )
|
|||
hf->heightsOffset = heightsOffset;
|
||||
hf->materialOffset = materialOffset;
|
||||
hf->flagsOffset = flagsOffset;
|
||||
hf->vertexFlagOffset = vertexFlagOffset;
|
||||
hf->clockwise = data->clockwiseWinding;
|
||||
|
||||
uint16_t* compressedHeights = (uint16_t*)( (intptr_t)hf + heightsOffset );
|
||||
|
|
@ -466,6 +516,79 @@ b3HeightFieldData* b3CreateHeightField( const b3HeightFieldDef* data )
|
|||
|
||||
B3_ASSERT( triangleIndex == triangleCount );
|
||||
|
||||
// b3MeshVertexFlags
|
||||
uint8_t* vertexFlags = (uint8_t*)b3Alloc( heightCount * sizeof( uint8_t ) );
|
||||
memset( vertexFlags, b3_flatVertex, heightCount * sizeof( uint8_t ) );
|
||||
|
||||
bool clockwise = hf->clockwise != 0;
|
||||
int cellColumnCount = columnCount - 1;
|
||||
int cellRowCount = rowCount - 1;
|
||||
|
||||
for ( int row = 0; row < rowCount; ++row )
|
||||
{
|
||||
for ( int column = 0; column < columnCount; ++column )
|
||||
{
|
||||
int index = row * columnCount + column;
|
||||
b3Vec3 point = b3GetGridPoint( heights, columnCount, scale, row, column );
|
||||
|
||||
if ( column < cellColumnCount )
|
||||
{
|
||||
bool below = row < cellRowCount && materialIndices[row * cellColumnCount + column] != B3_HEIGHT_FIELD_HOLE;
|
||||
bool above =
|
||||
row > 0 && materialIndices[( row - 1 ) * cellColumnCount + column] != B3_HEIGHT_FIELD_HOLE;
|
||||
if ( below && above )
|
||||
{
|
||||
b3Vec3 next = b3GetGridPoint( heights, columnCount, scale, row, column + 1 );
|
||||
b3Vec3 normal1 = b3GetGridTriangleNormal( heights, columnCount, scale, row, column, false );
|
||||
b3Vec3 normal2 = b3GetGridTriangleNormal( heights, columnCount, scale, row - 1, column, true );
|
||||
b3MarkGridEdge( vertexFlags, index + 1, index, next, point, normal1, normal2, clockwise );
|
||||
}
|
||||
else if ( below || above )
|
||||
{
|
||||
b3MarkGridBoundary( vertexFlags, index, index + 1 );
|
||||
}
|
||||
}
|
||||
|
||||
if ( row < cellRowCount )
|
||||
{
|
||||
bool right =
|
||||
column < cellColumnCount && materialIndices[row * cellColumnCount + column] != B3_HEIGHT_FIELD_HOLE;
|
||||
bool left = column > 0 && materialIndices[row * cellColumnCount + column - 1] != B3_HEIGHT_FIELD_HOLE;
|
||||
if ( right && left )
|
||||
{
|
||||
b3Vec3 next = b3GetGridPoint( heights, columnCount, scale, row + 1, column );
|
||||
b3Vec3 normal1 = b3GetGridTriangleNormal( heights, columnCount, scale, row, column, false );
|
||||
b3Vec3 normal2 = b3GetGridTriangleNormal( heights, columnCount, scale, row, column - 1, true );
|
||||
b3MarkGridEdge( vertexFlags, index, index + columnCount, point, next, normal1, normal2, clockwise );
|
||||
}
|
||||
else if ( right || left )
|
||||
{
|
||||
b3MarkGridBoundary( vertexFlags, index, index + columnCount );
|
||||
}
|
||||
}
|
||||
|
||||
if ( row < cellRowCount && column < cellColumnCount &&
|
||||
materialIndices[row * cellColumnCount + column] != B3_HEIGHT_FIELD_HOLE )
|
||||
{
|
||||
b3Vec3 point21 = b3GetGridPoint( heights, columnCount, scale, row + 1, column );
|
||||
b3Vec3 point12 = b3GetGridPoint( heights, columnCount, scale, row, column + 1 );
|
||||
b3Vec3 normal1 = b3GetGridTriangleNormal( heights, columnCount, scale, row, column, false );
|
||||
b3Vec3 normal2 = b3GetGridTriangleNormal( heights, columnCount, scale, row, column, true );
|
||||
b3MarkGridEdge( vertexFlags, index + columnCount, index + 1, point21, point12, normal1, normal2, clockwise );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t* vertexBits = (uint8_t*)( (intptr_t)hf + vertexFlagOffset );
|
||||
for ( int i = 0; i < heightCount; ++i )
|
||||
{
|
||||
if ( vertexFlags[i] == 0 )
|
||||
{
|
||||
vertexBits[i >> 3] |= (uint8_t)( 1 << ( i & 7 ) );
|
||||
}
|
||||
}
|
||||
|
||||
b3Free( vertexFlags, heightCount * sizeof( uint8_t ) );
|
||||
b3Free( decompressedHeights, heightCount * sizeof( float ) );
|
||||
|
||||
hf->hash = 0;
|
||||
|
|
@ -474,9 +597,6 @@ b3HeightFieldData* b3CreateHeightField( const b3HeightFieldDef* data )
|
|||
return hf;
|
||||
}
|
||||
|
||||
_Static_assert( b3_concaveEdge3 == 4 * b3_concaveEdge1, "bit math" );
|
||||
_Static_assert( b3_inverseConcaveEdge3 == 4 * b3_inverseConcaveEdge1, "bit math" );
|
||||
|
||||
// Decode the four corner vertices of a height field cell into local space.
|
||||
// Output order matches the index naming used throughout this file:
|
||||
// corners[0] = (column, row), corners[1] = (column + 1, row),
|
||||
|
|
@ -518,8 +638,6 @@ b3Triangle b3GetHeightFieldTriangle( const b3HeightFieldData* heightField, int t
|
|||
B3_ASSERT( triangleIndex < 2 * ( heightField->columnCount - 1 ) * ( heightField->rowCount - 1 ) );
|
||||
|
||||
b3Triangle triangle;
|
||||
triangle.flags = b3GetHeightFieldFlags( heightField )[triangleIndex];
|
||||
|
||||
int columnCount = heightField->columnCount;
|
||||
int quadIndex = triangleIndex >> 1;
|
||||
int row = quadIndex / ( columnCount - 1 );
|
||||
|
|
@ -562,15 +680,6 @@ b3Triangle b3GetHeightFieldTriangle( const b3HeightFieldData* heightField, int t
|
|||
{
|
||||
B3_SWAP( triangle.vertices[1], triangle.vertices[2] );
|
||||
B3_SWAP( triangle.i2, triangle.i3 );
|
||||
|
||||
// Reversing winding swaps edge1 and edge3; edge2 (the diagonal) is preserved.
|
||||
int flags = triangle.flags;
|
||||
int edge1Bits = flags & ( b3_concaveEdge1 | b3_inverseConcaveEdge1 );
|
||||
int edge3Bits = flags & ( b3_concaveEdge3 | b3_inverseConcaveEdge3 );
|
||||
flags &= ~( b3_concaveEdge1 | b3_concaveEdge3 | b3_inverseConcaveEdge1 | b3_inverseConcaveEdge3 );
|
||||
flags |= edge1Bits << 2;
|
||||
flags |= edge3Bits >> 2;
|
||||
triangle.flags = flags;
|
||||
}
|
||||
|
||||
return triangle;
|
||||
|
|
@ -585,6 +694,124 @@ int b3GetHeightFieldMaterial( const b3HeightFieldData* heightField, int triangle
|
|||
return b3GetHeightFieldMaterialIndices( heightField )[cellIndex];
|
||||
}
|
||||
|
||||
bool b3GetHeightFieldNeighborNormal( const b3HeightFieldData* heightField, int triangleIndex, int edgeIndex, b3Vec3* normal )
|
||||
{
|
||||
B3_ASSERT( 0 <= triangleIndex && triangleIndex < b3GetHeightFieldTriangleCount( heightField ) );
|
||||
B3_ASSERT( 0 <= edgeIndex && edgeIndex < 3 );
|
||||
|
||||
if ( heightField->clockwise )
|
||||
{
|
||||
// Reflected
|
||||
edgeIndex = 2 - edgeIndex;
|
||||
}
|
||||
|
||||
int cellColumnCount = heightField->columnCount - 1;
|
||||
int cellRowCount = heightField->rowCount - 1;
|
||||
int cellIndex = triangleIndex >> 1;
|
||||
int row = cellIndex / cellColumnCount;
|
||||
int column = cellIndex - row * cellColumnCount;
|
||||
bool odd = ( triangleIndex & 1 ) == 1;
|
||||
|
||||
// Get the row and column for the neighbor cell.
|
||||
if ( edgeIndex == 0 )
|
||||
{
|
||||
column += odd ? 1 : -1;
|
||||
}
|
||||
else if ( edgeIndex == 2 )
|
||||
{
|
||||
row += odd ? 1 : -1;
|
||||
}
|
||||
|
||||
if ( row < 0 || row >= cellRowCount || column < 0 || column >= cellColumnCount )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int neighborCell = row * cellColumnCount + column;
|
||||
|
||||
const uint8_t* materialIndices = b3GetHeightFieldMaterialIndices( heightField );
|
||||
if ( materialIndices[neighborCell] == B3_HEIGHT_FIELD_HOLE )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
b3Triangle neighbor = b3GetHeightFieldTriangle( heightField, 2 * neighborCell + ( odd ? 0 : 1 ) );
|
||||
b3Vec3 e1 = b3Sub( neighbor.vertices[1], neighbor.vertices[0] );
|
||||
b3Vec3 e2 = b3Sub( neighbor.vertices[2], neighbor.vertices[0] );
|
||||
*normal = b3Normalize( b3Cross( e1, e2 ) );
|
||||
return true;
|
||||
}
|
||||
|
||||
bool b3IsHeightFieldVertexConvex( const b3HeightFieldData* heightField, int triangleIndex, int vertexIndex )
|
||||
{
|
||||
B3_ASSERT( 0 <= triangleIndex && triangleIndex < b3GetHeightFieldTriangleCount( heightField ) );
|
||||
B3_ASSERT( 0 <= vertexIndex && vertexIndex < 3 );
|
||||
|
||||
if ( heightField->vertexFlagOffset == 0 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( heightField->clockwise )
|
||||
{
|
||||
vertexIndex = ( 3 - vertexIndex ) % 3;
|
||||
}
|
||||
|
||||
int columnCount = heightField->columnCount;
|
||||
int cellIndex = triangleIndex >> 1;
|
||||
int row = cellIndex / ( columnCount - 1 );
|
||||
int column = cellIndex - row * ( columnCount - 1 );
|
||||
|
||||
int offsets[2][3] = {
|
||||
{ 0, columnCount, 1 },
|
||||
{ columnCount + 1, 1, columnCount },
|
||||
};
|
||||
|
||||
int index = row * columnCount + column + offsets[triangleIndex & 1][vertexIndex];
|
||||
const uint8_t* vertexBits = (const uint8_t*)( (intptr_t)heightField + heightField->vertexFlagOffset );
|
||||
return ( vertexBits[index >> 3] & ( 1 << ( index & 7 ) ) ) != 0;
|
||||
}
|
||||
|
||||
int b3GetHeightFieldVertexTriangles( const b3HeightFieldData* heightField, int vertex, int triangles[6] )
|
||||
{
|
||||
int columnCount = heightField->columnCount;
|
||||
int cellColumnCount = columnCount - 1;
|
||||
int cellRowCount = heightField->rowCount - 1;
|
||||
int row = vertex / columnCount;
|
||||
int column = vertex - row * columnCount;
|
||||
|
||||
int rowOffsets[4] = { 0, 0, -1, -1 };
|
||||
int columnOffsets[4] = { 0, -1, 0, -1 };
|
||||
int firstParity[4] = { 0, 0, 0, 1 };
|
||||
int lastParity[4] = { 0, 1, 1, 1 };
|
||||
|
||||
const uint8_t* materialIndices = b3GetHeightFieldMaterialIndices( heightField );
|
||||
int count = 0;
|
||||
for ( int i = 0; i < 4; ++i )
|
||||
{
|
||||
int cellRow = row + rowOffsets[i];
|
||||
int cellColumn = column + columnOffsets[i];
|
||||
if ( cellRow < 0 || cellRow >= cellRowCount || cellColumn < 0 || cellColumn >= cellColumnCount )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int cellIndex = cellRow * cellColumnCount + cellColumn;
|
||||
if ( materialIndices[cellIndex] == B3_HEIGHT_FIELD_HOLE )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
for ( int parity = firstParity[i]; parity <= lastParity[i]; ++parity )
|
||||
{
|
||||
triangles[count] = 2 * cellIndex + parity;
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
b3AABB b3ComputeHeightFieldAABB( const b3HeightFieldData* shape, b3Transform transform )
|
||||
{
|
||||
return b3AABB_Transform( transform, shape->aabb );
|
||||
|
|
|
|||
215
src/hull.c
215
src/hull.c
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include "algorithm.h"
|
||||
#include "math_internal.h"
|
||||
#include "qsort.h"
|
||||
#include "shape.h"
|
||||
#include "simd.h"
|
||||
|
||||
|
|
@ -398,7 +399,8 @@ static void b3FindFarthestPointsAlongCardinalAxes( int* index1Out, int* index2Ou
|
|||
}
|
||||
}
|
||||
|
||||
static int b3FindFarthestPointFromLine( int index1, int index2, float tolerance, int vertexCount, const b3Vec3* vertexBase )
|
||||
static int b3FindFarthestPointFromLine( int index1, int index2, float tolerance, int vertexCount,
|
||||
const b3Vec3* vertexBase )
|
||||
{
|
||||
b3Vec3 a = vertexBase[index1];
|
||||
b3Vec3 b = vertexBase[index2];
|
||||
|
|
@ -764,7 +766,8 @@ static void b3HullBuilder_RecacheConflicts( b3QHFace* face, float minOutside )
|
|||
b3QHVertex* maxVertex = NULL;
|
||||
float maxDistance = minOutside;
|
||||
|
||||
for ( b3QHListNode* node = face->conflictListHead.link.next; node != &face->conflictListHead.link; node = node->next )
|
||||
for ( b3QHListNode* node = face->conflictListHead.link.next; node != &face->conflictListHead.link;
|
||||
node = node->next )
|
||||
{
|
||||
b3QHVertex* vertex = (b3QHVertex*)node;
|
||||
float distance = b3PlaneSeparation( face->plane, vertex->position );
|
||||
|
|
@ -784,7 +787,8 @@ static b3QHVertex* b3HullBuilder_NextConflictVertex( const b3HullBuilder* b )
|
|||
b3QHVertex* maxVertex = NULL;
|
||||
float maxDistance = b->minOutside;
|
||||
|
||||
for ( const b3QHListNode* faceNode = b->faceList.link.next; faceNode != &b->faceList.link; faceNode = faceNode->next )
|
||||
for ( const b3QHListNode* faceNode = b->faceList.link.next; faceNode != &b->faceList.link;
|
||||
faceNode = faceNode->next )
|
||||
{
|
||||
const b3QHFace* face = (const b3QHFace*)faceNode;
|
||||
if ( face->maxConflict != NULL && face->maxConflictDistance > maxDistance )
|
||||
|
|
@ -817,7 +821,8 @@ static void b3HullBuilder_DrainConflictList( b3HullBuilder* b, b3QHFace* face )
|
|||
// `entryEdge` is the half-edge in `face` whose twin lies in the just-deleted parent face, or
|
||||
// NULL for the seed. The frame skips `entryEdge` on recursive entries (it would be ignored
|
||||
// anyway since the parent's mark is now DELETE, but skipping saves one iteration).
|
||||
static void b3HullBuilder_EnterHorizonFace( b3HullBuilder* b, b3QHFace* face, b3QHHalfEdge* entryEdge, b3HorizonFrame* frameOut )
|
||||
static void b3HullBuilder_EnterHorizonFace( b3HullBuilder* b, b3QHFace* face, b3QHHalfEdge* entryEdge,
|
||||
b3HorizonFrame* frameOut )
|
||||
{
|
||||
face->mark = B3_MARK_DELETE;
|
||||
b3HullBuilder_DrainConflictList( b, face );
|
||||
|
|
@ -1357,7 +1362,8 @@ static bool b3HullBuilder_IsConsistent( const b3HullBuilder* b )
|
|||
return false;
|
||||
}
|
||||
|
||||
for ( const b3QHListNode* faceNode = b->faceList.link.next; faceNode != &b->faceList.link; faceNode = faceNode->next )
|
||||
for ( const b3QHListNode* faceNode = b->faceList.link.next; faceNode != &b->faceList.link;
|
||||
faceNode = faceNode->next )
|
||||
{
|
||||
const b3QHFace* face = (const b3QHFace*)faceNode;
|
||||
if ( face->edge->face != face )
|
||||
|
|
@ -1427,8 +1433,8 @@ static bool b3HullBuilder_HasHull( const b3HullBuilder* b )
|
|||
}
|
||||
|
||||
// Build the entire hull. Returns true iff the result satisfies Euler's identity.
|
||||
static bool b3HullBuilder_Construct( b3HullBuilder* b, const b3Vec3* points, int pointCount, int maxVertexCount, b3Vec3 origin,
|
||||
b3Vec3* shiftedPoints )
|
||||
static bool b3HullBuilder_Construct( b3HullBuilder* b, const b3Vec3* points, int pointCount, int maxVertexCount,
|
||||
b3Vec3 origin, b3Vec3* shiftedPoints )
|
||||
{
|
||||
if ( pointCount < 4 )
|
||||
{
|
||||
|
|
@ -2195,7 +2201,8 @@ b3HullData* b3CreateHull( const b3Vec3* points, int pointCount, int maxVertexCou
|
|||
int faceCount = 0;
|
||||
int edgeCount = 0;
|
||||
|
||||
for ( b3QHListNode* faceNode = builder.faceList.link.next; faceNode != &builder.faceList.link; faceNode = faceNode->next )
|
||||
for ( b3QHListNode* faceNode = builder.faceList.link.next; faceNode != &builder.faceList.link;
|
||||
faceNode = faceNode->next )
|
||||
{
|
||||
B3_ASSERT( faceCount < B3_HULL_MAX_COUNT );
|
||||
|
||||
|
|
@ -3098,20 +3105,20 @@ int b3SimplifyHull2D( b3Point2D* hull, int count1, int target )
|
|||
return count2;
|
||||
}
|
||||
|
||||
// Sort comparator: by x, then by y. Insertion since n is typically 20 or less.
|
||||
static void b3Sort2D( b3Point2D* pts, int count )
|
||||
// Comparator for sorting points for the 2D hull.
|
||||
static inline bool b3IsPoint2DLess( const b3Point2D* a, const b3Point2D* b )
|
||||
{
|
||||
for ( int i = 1; i < count; ++i )
|
||||
if ( a->p.x != b->p.x )
|
||||
{
|
||||
b3Point2D base = pts[i];
|
||||
int j = i - 1;
|
||||
while ( j >= 0 && ( pts[j].p.x > base.p.x || ( pts[j].p.x == base.p.x && pts[j].p.y > base.p.y ) ) )
|
||||
{
|
||||
pts[j + 1] = pts[j];
|
||||
j -= 1;
|
||||
}
|
||||
pts[j + 1] = base;
|
||||
return a->p.x < b->p.x;
|
||||
}
|
||||
|
||||
if ( a->p.y != b->p.y )
|
||||
{
|
||||
return a->p.y < b->p.y;
|
||||
}
|
||||
|
||||
return a->originalIndex < b->originalIndex;
|
||||
}
|
||||
|
||||
// Welds points that have been sorted O(n) time
|
||||
|
|
@ -3148,79 +3155,151 @@ static int b3Weld2D( b3Point2D* pts, int count1 )
|
|||
return count2;
|
||||
}
|
||||
|
||||
// Only merge points that line up exactly.
|
||||
static int b3MergeExact2D( b3Point2D* pts, int count1 )
|
||||
{
|
||||
float separationTol = B3_LINEAR_SLOP;
|
||||
|
||||
int count2 = 0;
|
||||
for ( int i = 0; i < count1; i++ )
|
||||
{
|
||||
b3Point2D point = pts[i];
|
||||
if ( count2 > 0 && pts[count2 - 1].p.x == point.p.x && pts[count2 - 1].p.y == point.p.y )
|
||||
{
|
||||
if ( point.separation < pts[count2 - 1].separation - separationTol )
|
||||
{
|
||||
pts[count2 - 1] = point;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pts[count2] = point;
|
||||
count2 += 1;
|
||||
}
|
||||
}
|
||||
|
||||
return count2;
|
||||
}
|
||||
|
||||
// Andrew's monotone chain convex hull algorithm
|
||||
// hull must have space for 2 * count1 points
|
||||
int b3Hull2D( b3Point2D* pts, int count, b3Point2D* hull )
|
||||
int b3Hull2D( b3Point2D* pts, int count, b3Point2D* hull, int flags )
|
||||
{
|
||||
int count1 = count;
|
||||
|
||||
if ( count1 <= 0 )
|
||||
if ( count <= 0 )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( count1 == 1 )
|
||||
#define LESS( i, j ) b3IsPoint2DLess( pts + (int)( i ), pts + (int)( j ) )
|
||||
#define SWAP( i, j ) \
|
||||
do \
|
||||
{ \
|
||||
b3Point2D swapPoint = pts[(int)( i )]; \
|
||||
pts[(int)( i )] = pts[(int)( j )]; \
|
||||
pts[(int)( j )] = swapPoint; \
|
||||
} \
|
||||
while ( 0 )
|
||||
|
||||
QSORT( count, LESS, SWAP );
|
||||
|
||||
#undef LESS
|
||||
#undef SWAP
|
||||
|
||||
int count1;
|
||||
if ( flags & b3_hull2DExactMerge )
|
||||
{
|
||||
hull[0] = pts[0];
|
||||
return 1;
|
||||
count1 = b3MergeExact2D( pts, count );
|
||||
}
|
||||
else
|
||||
{
|
||||
count1 = b3Weld2D( pts, count );
|
||||
}
|
||||
|
||||
b3Sort2D( pts, count1 );
|
||||
count1 = b3Weld2D( pts, count1 );
|
||||
|
||||
if ( count1 == 1 )
|
||||
{
|
||||
hull[0] = pts[0];
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ( count1 == 2 )
|
||||
{
|
||||
hull[0] = pts[0];
|
||||
hull[1] = pts[1];
|
||||
return 2;
|
||||
}
|
||||
bool keepCollinear = ( flags & b3_hull2DKeepCollinear ) != 0;
|
||||
|
||||
int count2 = 0;
|
||||
|
||||
for ( int i = 0; i < count1; i++ )
|
||||
if ( count1 <= 2 )
|
||||
{
|
||||
while ( count2 >= 2 )
|
||||
for ( int i = 0; i < count1; i++ )
|
||||
{
|
||||
float area = b3Cross2D( hull[count2 - 2].p, hull[count2 - 1].p, pts[i].p );
|
||||
if ( area > 0.0f )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
count2 -= 1;
|
||||
hull[i] = pts[i];
|
||||
}
|
||||
|
||||
B3_VALIDATE( count2 < 2 * count1 );
|
||||
hull[count2] = pts[i];
|
||||
count2 += 1;
|
||||
count2 = count1;
|
||||
}
|
||||
|
||||
int lowerCount = count2 + 1;
|
||||
|
||||
for ( int i = count1 - 2; i >= 0; i-- )
|
||||
else
|
||||
{
|
||||
while ( count2 >= lowerCount )
|
||||
for ( int i = 0; i < count1; i++ )
|
||||
{
|
||||
float area = b3Cross2D( hull[count2 - 2].p, hull[count2 - 1].p, pts[i].p );
|
||||
if ( area > 0.0f )
|
||||
while ( count2 >= 2 )
|
||||
{
|
||||
break;
|
||||
float area = b3Cross2D( hull[count2 - 2].p, hull[count2 - 1].p, pts[i].p );
|
||||
if ( area > 0.0f || ( keepCollinear && area == 0.0f ) )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
count2 -= 1;
|
||||
}
|
||||
|
||||
count2 -= 1;
|
||||
B3_VALIDATE( count2 < 2 * count1 );
|
||||
hull[count2] = pts[i];
|
||||
count2 += 1;
|
||||
}
|
||||
|
||||
B3_VALIDATE( count2 < 2 * count1 );
|
||||
hull[count2] = pts[i];
|
||||
count2 += 1;
|
||||
int lowerCount = count2 + 1;
|
||||
int lowerIndex = count2 - 2;
|
||||
|
||||
for ( int i = count1 - 2; i >= 0; i-- )
|
||||
{
|
||||
if ( lowerIndex >= 0 && hull[lowerIndex].p.x == pts[i].p.x && hull[lowerIndex].p.y == pts[i].p.y )
|
||||
{
|
||||
lowerIndex -= 1;
|
||||
if ( i > 0 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
while ( count2 >= lowerCount )
|
||||
{
|
||||
float area = b3Cross2D( hull[count2 - 2].p, hull[count2 - 1].p, pts[i].p );
|
||||
if ( area > 0.0f || ( keepCollinear && area == 0.0f ) )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
count2 -= 1;
|
||||
}
|
||||
|
||||
B3_VALIDATE( count2 < 2 * count1 );
|
||||
hull[count2] = pts[i];
|
||||
count2 += 1;
|
||||
}
|
||||
|
||||
B3_VALIDATE( hull[0].originalIndex == hull[count2 - 1].originalIndex );
|
||||
count2 -= 1;
|
||||
}
|
||||
|
||||
B3_VALIDATE( hull[0].originalIndex == hull[count2 - 1].originalIndex );
|
||||
return count2 - 1;
|
||||
B3_VALIDATE( count2 <= count1 );
|
||||
|
||||
if ( flags & b3_hull2DIndexOrder )
|
||||
{
|
||||
#define LESS( i, j ) ( hull[(int)( i )].originalIndex < hull[(int)( j )].originalIndex )
|
||||
#define SWAP( i, j ) \
|
||||
do \
|
||||
{ \
|
||||
b3Point2D swapPoint = hull[(int)( i )]; \
|
||||
hull[(int)( i )] = hull[(int)( j )]; \
|
||||
hull[(int)( j )] = swapPoint; \
|
||||
} \
|
||||
while ( 0 )
|
||||
|
||||
QSORT( count2, LESS, SWAP );
|
||||
|
||||
#undef LESS
|
||||
#undef SWAP
|
||||
}
|
||||
|
||||
return count2;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,6 +51,12 @@ b3AxisQuery b3ComputeSeparatingAxisAtWidth( const b3HullData* hullA, const b3Hul
|
|||
void b3CollideHullsAtWidth( b3LocalManifold* manifold, int capacity, const b3HullData* hullA, const b3HullData* hullB,
|
||||
b3Transform transformBtoA, b3SATCache* cache, int simdWidth );
|
||||
|
||||
void b3BuildTriangleAndCapsuleFaceContact( b3LocalManifold* manifold, const b3Vec3* triangle, b3Plane plane,
|
||||
const b3Capsule* capsule );
|
||||
|
||||
void b3BuildTriangleAndHullFaceContact( b3LocalManifold* manifold, int capacity, const b3Vec3* triangle, const b3HullData* hull,
|
||||
b3SATCache* cache, bool enableSpeculative );
|
||||
|
||||
b3AxisQuery b3ComputeSeparatingAxisW4( const b3HullData* hullA, const b3HullData* hullB, b3Transform xfB, bool earlyReturn );
|
||||
b3AxisQuery b3ComputeSeparatingAxisW8( const b3HullData* hullA, const b3HullData* hullB, b3Transform xfB, bool earlyReturn );
|
||||
|
||||
|
|
|
|||
|
|
@ -166,49 +166,6 @@ bool b3IsValidWorldTransform( b3WorldTransform t )
|
|||
return b3IsValidPosition( t.p ) && b3IsValidQuat( t.q );
|
||||
}
|
||||
|
||||
// https://stackoverflow.com/questions/46210708/atan2-approximation-with-11bits-in-mantissa-on-x86with-sse2-and-armwith-vfpv4
|
||||
float b3Atan2( float y, float x )
|
||||
{
|
||||
// Added check for (0,0) to match atan2f and avoid NaN
|
||||
if ( x == 0.0f && y == 0.0f )
|
||||
{
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
float ax = b3AbsFloat( x );
|
||||
float ay = b3AbsFloat( y );
|
||||
float mx = b3MaxFloat( ay, ax );
|
||||
float mn = b3MinFloat( ay, ax );
|
||||
float a = mn / mx;
|
||||
|
||||
// Minimax polynomial approximation to atan(a) on [0,1]
|
||||
float s = a * a;
|
||||
float c = s * a;
|
||||
float q = s * s;
|
||||
float r = 0.024840285f * q + 0.18681418f;
|
||||
float t = -0.094097948f * q - 0.33213072f;
|
||||
r = r * s + t;
|
||||
r = r * c + a;
|
||||
|
||||
// Map to full circle
|
||||
if ( ay > ax )
|
||||
{
|
||||
r = 1.57079637f - r;
|
||||
}
|
||||
|
||||
if ( x < 0 )
|
||||
{
|
||||
r = 3.14159274f - r;
|
||||
}
|
||||
|
||||
if ( y < 0 )
|
||||
{
|
||||
r = -r;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
// Approximate cosine and sine for determinism. In my testing cosf and sinf produced
|
||||
// the same results on x64 and ARM using MSVC, GCC, and Clang. However, I don't trust
|
||||
// this result.
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ typedef struct b3Triangle
|
|||
{
|
||||
b3Vec3 vertices[3];
|
||||
int i1, i2, i3;
|
||||
int flags;
|
||||
} b3Triangle;
|
||||
|
||||
typedef struct b3TrianglePoint
|
||||
|
|
|
|||
1244
src/mesh.c
1244
src/mesh.c
File diff suppressed because it is too large
Load diff
1671
src/mesh_contact.c
1671
src/mesh_contact.c
File diff suppressed because it is too large
Load diff
42
src/shape.h
42
src/shape.h
|
|
@ -129,6 +129,10 @@ float b3ComputeHullProjectedArea( const b3HullData* hull, b3Vec3 direction );
|
|||
b3Triangle b3GetHeightFieldTriangle( const b3HeightFieldData* heightField, int triangleIndex );
|
||||
int b3GetHeightFieldMaterial( const b3HeightFieldData* heightField, int triangleIndex );
|
||||
|
||||
bool b3GetHeightFieldNeighborNormal( const b3HeightFieldData* heightField, int triangleIndex, int edgeIndex, b3Vec3* normal );
|
||||
bool b3IsHeightFieldVertexConvex( const b3HeightFieldData* heightField, int triangleIndex, int vertexIndex );
|
||||
int b3GetHeightFieldVertexTriangles( const b3HeightFieldData* heightField, int vertex, int triangles[6] );
|
||||
|
||||
static inline int b3GetHeightFieldTriangleCount( const b3HeightFieldData* heightField )
|
||||
{
|
||||
int cellCount = ( heightField->rowCount - 1 ) * ( heightField->columnCount - 1 );
|
||||
|
|
@ -143,12 +147,10 @@ static inline b3Triangle b3GetMeshTriangle( const b3Mesh* mesh, int triangleInde
|
|||
B3_ASSERT( 0 <= triangleIndex && triangleIndex < mesh->data->triangleCount );
|
||||
|
||||
const b3MeshTriangle* triangles = b3GetMeshTriangles( mesh->data );
|
||||
const uint8_t* flags = b3GetMeshFlags( mesh->data );
|
||||
const b3Vec3* vertices = b3GetMeshVertices( mesh->data );
|
||||
|
||||
b3Triangle result;
|
||||
b3MeshTriangle triangle = triangles[triangleIndex];
|
||||
uint8_t triangleFlags = flags[triangleIndex];
|
||||
|
||||
b3Vec3 scale = mesh->scale;
|
||||
|
||||
|
|
@ -163,11 +165,6 @@ static inline b3Triangle b3GetMeshTriangle( const b3Mesh* mesh, int triangleInde
|
|||
result.i2 = triangle.index3;
|
||||
result.i3 = triangle.index2;
|
||||
|
||||
// mesh is inverted, so concave edges are now convex
|
||||
result.flags = 0;
|
||||
result.flags |= ( triangleFlags & b3_inverseConcaveEdge1 ) ? b3_concaveEdge1 : 0;
|
||||
result.flags |= ( triangleFlags & b3_inverseConcaveEdge2 ) ? b3_concaveEdge2 : 0;
|
||||
result.flags |= ( triangleFlags & b3_inverseConcaveEdge3 ) ? b3_concaveEdge3 : 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -176,12 +173,41 @@ static inline b3Triangle b3GetMeshTriangle( const b3Mesh* mesh, int triangleInde
|
|||
|
||||
result.i2 = triangle.index2;
|
||||
result.i3 = triangle.index3;
|
||||
result.flags = triangleFlags;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool b3GetMeshNeighborNormal( const b3Mesh* mesh, int triangleIndex, int edgeIndex, b3Vec3* normal );
|
||||
|
||||
// Returns false if edge is isolated.
|
||||
static inline bool b3GetNeighborNormal( const b3Shape* shape, int triangleIndex, int edgeIndex, b3Vec3* normal )
|
||||
{
|
||||
if ( shape->type == b3_meshShape )
|
||||
{
|
||||
return b3GetMeshNeighborNormal( &shape->mesh, triangleIndex, edgeIndex, normal );
|
||||
}
|
||||
|
||||
B3_ASSERT( shape->type == b3_heightShape );
|
||||
return b3GetHeightFieldNeighborNormal( shape->heightField, triangleIndex, edgeIndex, normal );
|
||||
}
|
||||
|
||||
int b3GetMeshVertexFlag( const b3Mesh* mesh, int triangleIndex, int vertexIndex );
|
||||
bool b3IsInMeshVertexRing( const b3Mesh* mesh, int triangleIndex, int vertexIndex, b3Vec3 normal, float tolerance );
|
||||
int8_t b3QuantizeEdgeAngle( float radians );
|
||||
|
||||
static inline bool b3IsConvexVertex( const b3Shape* shape, int triangleIndex, int vertexIndex )
|
||||
{
|
||||
if ( shape->type == b3_meshShape )
|
||||
{
|
||||
int flags = b3GetMeshVertexFlag( &shape->mesh, triangleIndex, vertexIndex );
|
||||
return ( flags & ( b3_flatVertex | b3_concaveVertex ) ) == 0;
|
||||
}
|
||||
|
||||
B3_ASSERT( shape->type == b3_heightShape );
|
||||
return b3IsHeightFieldVertexConvex( shape->heightField, triangleIndex, vertexIndex );
|
||||
}
|
||||
|
||||
bool b3IsValidMesh( const b3MeshData* meshData );
|
||||
|
||||
static inline bool b3ShouldShapesCollide( b3Filter filterA, b3Filter filterB )
|
||||
|
|
|
|||
24
src/simd.h
24
src/simd.h
|
|
@ -29,6 +29,30 @@
|
|||
|
||||
#endif
|
||||
|
||||
static inline b3FloatW4 b3Atan2W4( b3FloatW4 y, b3FloatW4 x )
|
||||
{
|
||||
b3FloatW4 zero = b3ZeroW4();
|
||||
b3FloatW4 ax = b3AbsW4( x );
|
||||
b3FloatW4 ay = b3AbsW4( y );
|
||||
b3FloatW4 mx = b3MaxW4( ay, ax );
|
||||
b3FloatW4 mn = b3MinW4( ay, ax );
|
||||
b3FloatW4 a = b3DivW4( mn, mx );
|
||||
|
||||
b3FloatW4 s = b3MulW4( a, a );
|
||||
b3FloatW4 c = b3MulW4( s, a );
|
||||
b3FloatW4 q = b3MulW4( s, s );
|
||||
b3FloatW4 r = b3MulAddW4( b3SplatW4( 0.18681418f ), b3SplatW4( 0.024840285f ), q );
|
||||
b3FloatW4 t = b3SubW4( b3MulW4( b3SplatW4( -0.094097948f ), q ), b3SplatW4( 0.33213072f ) );
|
||||
r = b3MulAddW4( t, r, s );
|
||||
r = b3MulAddW4( a, r, c );
|
||||
|
||||
r = b3BlendW4( r, b3SubW4( b3SplatW4( 1.57079637f ), r ), b3GreaterThanW4( ay, ax ) );
|
||||
r = b3BlendW4( r, b3SubW4( b3SplatW4( 3.14159274f ), r ), b3LessThanW4( x, zero ) );
|
||||
r = b3BlendW4( r, b3NegW4( r ), b3LessThanW4( y, zero ) );
|
||||
|
||||
return b3BlendW4( r, zero, b3EqualsW4( b3AddW4( ax, ay ), zero ) );
|
||||
}
|
||||
|
||||
#if !defined( B3_SIMD_SSE2 )
|
||||
|
||||
// I don't expect the use case of b3V32 to benefit from Neon code.
|
||||
|
|
|
|||
|
|
@ -14,12 +14,14 @@
|
|||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
// cosine of hull normal versus edge axis tolerance.
|
||||
#define B3_CROSSING_TOLERANCE 0.1f
|
||||
|
||||
typedef struct b3TriangleData
|
||||
{
|
||||
b3Vec3 v1, v2, v3;
|
||||
b3Vec3 e1, e2, e3;
|
||||
b3Plane plane;
|
||||
int flags;
|
||||
} b3TriangleData;
|
||||
|
||||
// Indexed by the 3-bit vertex mask
|
||||
|
|
@ -104,7 +106,6 @@ void b3CollideTriangleAndSphere( b3LocalManifold* manifold, int capacity, const
|
|||
manifold->normal = normal;
|
||||
manifold->pointCount = 1;
|
||||
manifold->feature = closest.feature;
|
||||
manifold->squaredDistance = squaredDistance;
|
||||
|
||||
b3LocalManifoldPoint* mp = manifold->points + 0;
|
||||
mp->point = contactPoint;
|
||||
|
|
@ -260,8 +261,8 @@ static b3SeparatingAxis b3QueryTriangleAndCapsuleEdges( const b3Vec3* vertices,
|
|||
};
|
||||
}
|
||||
|
||||
static void b3BuildTriangleAndCapsuleFaceContact( b3LocalManifold* manifold, const b3Vec3* triangle, b3Plane plane,
|
||||
const b3Capsule* capsule )
|
||||
void b3BuildTriangleAndCapsuleFaceContact( b3LocalManifold* manifold, const b3Vec3* triangle, b3Plane plane,
|
||||
const b3Capsule* capsule )
|
||||
{
|
||||
B3_ASSERT( manifold->pointCount == 0 );
|
||||
|
||||
|
|
@ -597,15 +598,6 @@ static b3SeparatingAxis b3QueryTriangleAndHullEdges( const b3TriangleData* trian
|
|||
|
||||
b3Vec3 trianglePoints[] = { triangle->v1, triangle->v2, triangle->v3 };
|
||||
b3Vec3 triangleEdges[] = { triangle->e1, triangle->e2, triangle->e3 };
|
||||
// int edgeFlags[] = { b3_concaveEdge1, b3_concaveEdge1, b3_concaveEdge3 };
|
||||
|
||||
#if B3_FORCE_GHOST_COLLISIONS
|
||||
int triangleFlags = 0xFF;
|
||||
#else
|
||||
int triangleFlags = triangle->flags;
|
||||
#endif
|
||||
(void)triangleFlags;
|
||||
|
||||
b3Vec3 triNormal = triangle->plane.normal;
|
||||
|
||||
const b3HullHalfEdge* hullEdges = b3GetHullEdges( hull );
|
||||
|
|
@ -653,7 +645,6 @@ static b3SeparatingAxis b3QueryTriangleAndHullEdges( const b3TriangleData* trian
|
|||
axis = b3Normalize( axis );
|
||||
float separation = b3Dot( axis, b3Sub( trianglePoints[j], hullPoint ) );
|
||||
|
||||
// if ( separation > result.separation && ( edgeFlags[j] & triangleFlags ) == 0 )
|
||||
if ( separation > result.separation )
|
||||
{
|
||||
// Note: We don't exit early if we find a separating axis here since we want to
|
||||
|
|
@ -748,7 +739,7 @@ static float b3CollideHullFace( b3LocalManifold* manifold, int pointCapacity, co
|
|||
b3ClipVertex* clipPoint = input + i;
|
||||
minSeparation = b3MinFloat( minSeparation, clipPoint->separation );
|
||||
|
||||
if ( enableSpeculative == false && clipPoint->separation > 0.0f )
|
||||
if ( enableSpeculative == false && clipPoint->separation > B3_MESH_REST_OFFSET )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
@ -764,7 +755,7 @@ static float b3CollideHullFace( b3LocalManifold* manifold, int pointCapacity, co
|
|||
finalPointCount += 1;
|
||||
}
|
||||
|
||||
float speculativeDistance = enableSpeculative ? B3_SPECULATIVE_DISTANCE : 0.0f;
|
||||
float speculativeDistance = enableSpeculative ? B3_SPECULATIVE_DISTANCE : B3_MESH_REST_OFFSET;
|
||||
if ( minSeparation > speculativeDistance )
|
||||
{
|
||||
// This can occur with a stale SAT cache
|
||||
|
|
@ -864,7 +855,7 @@ static float b3CollideTriangleFace( b3LocalManifold* manifold, int pointCapacity
|
|||
b3ClipVertex* clipPoint = input + i;
|
||||
minSeparation = b3MinFloat( minSeparation, clipPoint->separation );
|
||||
|
||||
if ( enableSpeculative == false && clipPoint->separation > 0.0f )
|
||||
if ( enableSpeculative == false && clipPoint->separation > B3_MESH_REST_OFFSET )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
@ -881,7 +872,7 @@ static float b3CollideTriangleFace( b3LocalManifold* manifold, int pointCapacity
|
|||
finalPointCount += 1;
|
||||
}
|
||||
|
||||
float speculativeDistance = enableSpeculative ? B3_SPECULATIVE_DISTANCE : 0.0f;
|
||||
float speculativeDistance = enableSpeculative ? B3_SPECULATIVE_DISTANCE : B3_MESH_REST_OFFSET;
|
||||
if ( minSeparation >= speculativeDistance )
|
||||
{
|
||||
// This can happens if the objects move a part while re-using a cached axis
|
||||
|
|
@ -954,11 +945,37 @@ static void b3CollideTriangleAndHullEdges( b3LocalManifold* manifold, int capaci
|
|||
manifold->feature = edgesFeatures[query.indexA];
|
||||
}
|
||||
|
||||
// Triangle face contact wrapper.
|
||||
void b3BuildTriangleAndHullFaceContact( b3LocalManifold* manifold, int capacity, const b3Vec3* triangle, const b3HullData* hull,
|
||||
b3SATCache* cache, bool enableSpeculative )
|
||||
{
|
||||
manifold->pointCount = 0;
|
||||
|
||||
b3TriangleData triangleData = {
|
||||
.v1 = triangle[0],
|
||||
.v2 = triangle[1],
|
||||
.v3 = triangle[2],
|
||||
.e1 = b3Sub( triangle[1], triangle[0] ),
|
||||
.e2 = b3Sub( triangle[2], triangle[1] ),
|
||||
.e3 = b3Sub( triangle[0], triangle[2] ),
|
||||
.plane = b3MakePlaneFromPoints( triangle[0], triangle[1], triangle[2] ),
|
||||
};
|
||||
|
||||
b3SeparatingAxis query = b3QueryTriangleFace( &triangleData, hull );
|
||||
b3SATCache faceCache = { 0 };
|
||||
b3CollideTriangleFace( manifold, capacity, &triangleData, hull, query, &faceCache, enableSpeculative );
|
||||
|
||||
if ( manifold->pointCount > 0 )
|
||||
{
|
||||
*cache = faceCache;
|
||||
}
|
||||
}
|
||||
|
||||
b3AtomicInt b3_triangleConvexCalls;
|
||||
b3AtomicInt b3_triangleCacheHits;
|
||||
|
||||
// Triangle is in the local space of the hull for efficiency.
|
||||
void b3CollideTriangleAndHull( b3LocalManifold* manifold, int capacity, b3Vec3 v1, b3Vec3 v2, b3Vec3 v3, int triangleFlags,
|
||||
void b3CollideTriangleAndHull( b3LocalManifold* manifold, int capacity, b3Vec3 v1, b3Vec3 v2, b3Vec3 v3,
|
||||
const b3HullData* hullB, b3SATCache* cache, bool enableSpeculative )
|
||||
{
|
||||
manifold->pointCount = 0;
|
||||
|
|
@ -1003,14 +1020,13 @@ void b3CollideTriangleAndHull( b3LocalManifold* manifold, int capacity, b3Vec3 v
|
|||
.e2 = triangleEdges[1],
|
||||
.e3 = triangleEdges[2],
|
||||
.plane = trianglePlane,
|
||||
.flags = triangleFlags,
|
||||
};
|
||||
|
||||
const b3HullHalfEdge* edges = b3GetHullEdges( hullB );
|
||||
const b3Plane* hullPlanes = b3GetHullPlanes( hullB );
|
||||
const b3Vec3* hullPoints = b3GetHullPoints( hullB );
|
||||
|
||||
float speculativeDistance = enableSpeculative ? B3_SPECULATIVE_DISTANCE : 0.0f;
|
||||
float speculativeDistance = enableSpeculative ? B3_SPECULATIVE_DISTANCE : B3_MESH_REST_OFFSET;
|
||||
cache->hit = 1;
|
||||
|
||||
// Attempt to use the cache to speed up collision
|
||||
|
|
@ -1082,6 +1098,9 @@ void b3CollideTriangleAndHull( b3LocalManifold* manifold, int capacity, b3Vec3 v
|
|||
return;
|
||||
}
|
||||
|
||||
// Note: it is possible for a hull face to lean into an edge direction while mainting
|
||||
// a valid cache. But this has never been observed.
|
||||
|
||||
// Deep overlap may lead to an invalid cache
|
||||
// todo confirm
|
||||
bool isDeep = separation < -2.0f * linearSlop;
|
||||
|
|
@ -1285,14 +1304,29 @@ void b3CollideTriangleAndHull( b3LocalManifold* manifold, int capacity, b3Vec3 v
|
|||
// If a face axis has positive separation there may be no points.
|
||||
float maxFaceSeparation = b3MaxFloat( faceQueryA.separation, faceQueryB.separation );
|
||||
|
||||
// The edge axis can win if the hull face axis is significantly aligned with the edge axis.
|
||||
bool crossesEdge = false;
|
||||
if ( manifold->pointCount >= 1 && manifold->feature == b3_featureHullFace && edgeQuery.separation > clipSeparation )
|
||||
{
|
||||
b3Vec3 edgeAxis = b3Normalize( triangleEdges[edgeQuery.indexA] );
|
||||
|
||||
// Is the angle less than ~84 degrees?
|
||||
crossesEdge = b3AbsFloat( b3Dot( faceQueryB.normal, edgeAxis ) ) > B3_CROSSING_TOLERANCE;
|
||||
}
|
||||
|
||||
if ( ( manifold->pointCount == 0 && edgeQuery.separation > maxFaceSeparation ) ||
|
||||
( manifold->pointCount == 1 && edgeQuery.separation > clipSeparation + linearSlop ) )
|
||||
( manifold->pointCount == 1 && edgeQuery.separation > clipSeparation + linearSlop ) || crossesEdge )
|
||||
{
|
||||
B3_ASSERT( 0 <= edgeQuery.indexA && edgeQuery.indexA < 3 );
|
||||
b3Vec3 trianglePoint = trianglePoints[edgeQuery.indexA];
|
||||
b3Vec3 triangleEdge = triangleEdges[edgeQuery.indexA];
|
||||
manifold->pointCount = 0;
|
||||
b3CollideTriangleAndHullEdges( manifold, capacity, trianglePoint, triangleEdge, hullB, edgeQuery, cache );
|
||||
|
||||
if ( crossesEdge && manifold->pointCount == 0 )
|
||||
{
|
||||
b3CollideHullFace( manifold, capacity, &triangle, hullB, faceQueryB, cache, enableSpeculative );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1314,7 +1348,7 @@ void b3CollideTriangleAndHull( b3LocalManifold* manifold, int capacity, b3Vec3 v
|
|||
b3SimplexCache simplexCache = { 0 };
|
||||
b3DistanceOutput output = b3ShapeDistance( &input, &simplexCache, NULL, 0 );
|
||||
|
||||
if ( output.distance > 0.0f )
|
||||
if ( 0.0f < output.distance && output.distance <= speculativeDistance )
|
||||
{
|
||||
B3_ASSERT( 0 < simplexCache.count && simplexCache.count <= 3 );
|
||||
|
||||
|
|
|
|||
|
|
@ -19,27 +19,27 @@
|
|||
// Double precision accumulates body positions in double, so the settle/sleep step and the
|
||||
// state hash differ from the float build. Both modes are internally deterministic.
|
||||
#if defined( BOX3D_DOUBLE_PRECISION )
|
||||
#define RAGDOLL_SLEEP_STEP 263
|
||||
#define RAGDOLL_HASH 0xA5423F98
|
||||
#define WAVE_PILE_SLEEP_STEP 272
|
||||
#define WAVE_PILE_HASH 0xC8E5F3D6
|
||||
#define RAGDOLL_SLEEP_STEP 282
|
||||
#define RAGDOLL_HASH 0x6E4B13AD
|
||||
#define WAVE_PILE_SLEEP_STEP 315
|
||||
#define WAVE_PILE_HASH 0x15007937
|
||||
#define QUERY_SPAWN_SLEEP_STEP 242
|
||||
#define QUERY_SPAWN_HASH 0x489585E6
|
||||
#define QUERY_SPAWN_HIT_COUNT 59
|
||||
#define QUERY_SPAWN_QUERY_HASH 0x5B4429DC
|
||||
#define MESH_DROP_SLEEP_STEP 218
|
||||
#define MESH_DROP_HASH 0xD378CF04
|
||||
#define MESH_DROP_SLEEP_STEP 197
|
||||
#define MESH_DROP_HASH 0x5DA091C3
|
||||
#else
|
||||
#define RAGDOLL_SLEEP_STEP 291
|
||||
#define RAGDOLL_HASH 0xFF4C605B
|
||||
#define WAVE_PILE_SLEEP_STEP 272
|
||||
#define WAVE_PILE_HASH 0x266F83B0
|
||||
#define RAGDOLL_SLEEP_STEP 277
|
||||
#define RAGDOLL_HASH 0x5E042B6E
|
||||
#define WAVE_PILE_SLEEP_STEP 455
|
||||
#define WAVE_PILE_HASH 0x854F313D
|
||||
#define QUERY_SPAWN_SLEEP_STEP 242
|
||||
#define QUERY_SPAWN_HASH 0xF3AD9BA6
|
||||
#define QUERY_SPAWN_HIT_COUNT 59
|
||||
#define QUERY_SPAWN_QUERY_HASH 0xE3271F3D
|
||||
#define MESH_DROP_SLEEP_STEP 226
|
||||
#define MESH_DROP_HASH 0xD2FF069D
|
||||
#define MESH_DROP_SLEEP_STEP 197
|
||||
#define MESH_DROP_HASH 0x96D47D4F
|
||||
#endif
|
||||
|
||||
// The goldens above pin exact values for the default four point manifold. A build that
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
#include "box3d/math_functions.h"
|
||||
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static int HeightFieldCreate( void )
|
||||
|
|
@ -673,6 +674,146 @@ static int RayCastClockwiseWinding( void )
|
|||
return 0;
|
||||
}
|
||||
|
||||
#define BUMPY_COUNT_X 9
|
||||
#define BUMPY_COUNT_Z 7
|
||||
|
||||
// A bumpy field with holes, so cells have every mix of interior, border and hole neighbors
|
||||
static b3HeightFieldData* MakeBumpyField( bool clockwise )
|
||||
{
|
||||
float heights[BUMPY_COUNT_X * BUMPY_COUNT_Z];
|
||||
for ( int i = 0; i < BUMPY_COUNT_Z; ++i )
|
||||
{
|
||||
for ( int j = 0; j < BUMPY_COUNT_X; ++j )
|
||||
{
|
||||
heights[i * BUMPY_COUNT_X + j] = sinf( 0.9f * (float)i ) * cosf( 0.7f * (float)j ) + 0.1f * (float)( ( i * j ) % 3 );
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t materials[( BUMPY_COUNT_X - 1 ) * ( BUMPY_COUNT_Z - 1 )] = { 0 };
|
||||
materials[9] = B3_HEIGHT_FIELD_HOLE;
|
||||
materials[20] = B3_HEIGHT_FIELD_HOLE;
|
||||
materials[47] = B3_HEIGHT_FIELD_HOLE;
|
||||
|
||||
b3HeightFieldDef def = { 0 };
|
||||
def.heights = heights;
|
||||
def.materialIndices = materials;
|
||||
def.scale = (b3Vec3){ 1.5f, 0.8f, 0.5f };
|
||||
def.countX = BUMPY_COUNT_X;
|
||||
def.countZ = BUMPY_COUNT_Z;
|
||||
def.globalMinimumHeight = -2.0f;
|
||||
def.globalMaximumHeight = 2.0f;
|
||||
def.clockwiseWinding = clockwise;
|
||||
return b3CreateHeightField( &def );
|
||||
}
|
||||
|
||||
static bool IsHole( const b3HeightFieldData* hf, int triangleIndex )
|
||||
{
|
||||
return b3GetHeightFieldMaterial( hf, triangleIndex ) == B3_HEIGHT_FIELD_HOLE;
|
||||
}
|
||||
|
||||
static b3Vec3 TriangleNormal( b3Triangle triangle )
|
||||
{
|
||||
b3Vec3 e1 = b3Sub( triangle.vertices[1], triangle.vertices[0] );
|
||||
b3Vec3 e2 = b3Sub( triangle.vertices[2], triangle.vertices[0] );
|
||||
return b3Normalize( b3Cross( e1, e2 ) );
|
||||
}
|
||||
|
||||
// Neighbors found by brute force over shared grid points must match the grid walk
|
||||
static int HeightFieldNeighborNormals( void )
|
||||
{
|
||||
for ( int pass = 0; pass < 2; ++pass )
|
||||
{
|
||||
b3HeightFieldData* hf = MakeBumpyField( pass == 1 );
|
||||
int triangleCount = b3GetHeightFieldTriangleCount( hf );
|
||||
int interiorCount = 0;
|
||||
int boundaryCount = 0;
|
||||
|
||||
for ( int i = 0; i < triangleCount; ++i )
|
||||
{
|
||||
if ( IsHole( hf, i ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
b3Triangle triangle = b3GetHeightFieldTriangle( hf, i );
|
||||
int indices[3] = { triangle.i1, triangle.i2, triangle.i3 };
|
||||
|
||||
for ( int k = 0; k < 3; ++k )
|
||||
{
|
||||
int a = indices[k];
|
||||
int b = indices[( k + 1 ) % 3];
|
||||
|
||||
int neighbor = B3_NULL_INDEX;
|
||||
for ( int j = 0; j < triangleCount && neighbor == B3_NULL_INDEX; ++j )
|
||||
{
|
||||
if ( j == i || IsHole( hf, j ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
b3Triangle other = b3GetHeightFieldTriangle( hf, j );
|
||||
int otherIndices[3] = { other.i1, other.i2, other.i3 };
|
||||
for ( int m = 0; m < 3; ++m )
|
||||
{
|
||||
if ( otherIndices[m] == b && otherIndices[( m + 1 ) % 3] == a )
|
||||
{
|
||||
neighbor = j;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
b3Vec3 normal;
|
||||
bool found = b3GetHeightFieldNeighborNormal( hf, i, k, &normal );
|
||||
ENSURE( found == ( neighbor != B3_NULL_INDEX ) );
|
||||
|
||||
if ( found == false )
|
||||
{
|
||||
boundaryCount += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
interiorCount += 1;
|
||||
b3Vec3 expected = TriangleNormal( b3GetHeightFieldTriangle( hf, neighbor ) );
|
||||
ENSURE( b3Dot( normal, expected ) > 0.99999f );
|
||||
}
|
||||
}
|
||||
|
||||
ENSURE( interiorCount > 0 );
|
||||
ENSURE( boundaryCount > 0 );
|
||||
b3DestroyHeightField( hf );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// The shape level lookup dispatches to the mesh and height field versions
|
||||
static int NeighborNormalDispatch( void )
|
||||
{
|
||||
b3HeightFieldData* hf = MakeBumpyField( false );
|
||||
b3Shape heightShape = { 0 };
|
||||
heightShape.type = b3_heightShape;
|
||||
heightShape.heightField = hf;
|
||||
|
||||
b3Vec3 normal1, normal2;
|
||||
ENSURE( b3GetNeighborNormal( &heightShape, 1, 1, &normal1 ) );
|
||||
ENSURE( b3GetHeightFieldNeighborNormal( hf, 1, 1, &normal2 ) );
|
||||
ENSURE( normal1.x == normal2.x && normal1.y == normal2.y && normal1.z == normal2.z );
|
||||
b3DestroyHeightField( hf );
|
||||
|
||||
b3MeshData* data = b3CreateWaveMesh( 4, 4, 1.0f, 0.5f, 0.2f, 0.15f );
|
||||
b3Shape meshShape = { 0 };
|
||||
meshShape.type = b3_meshShape;
|
||||
meshShape.mesh = (b3Mesh){ data, { 2.0f, 0.5f, -1.0f } };
|
||||
|
||||
bool found1 = b3GetNeighborNormal( &meshShape, 5, 1, &normal1 );
|
||||
bool found2 = b3GetMeshNeighborNormal( &meshShape.mesh, 5, 1, &normal2 );
|
||||
ENSURE( found1 && found2 );
|
||||
ENSURE( normal1.x == normal2.x && normal1.y == normal2.y && normal1.z == normal2.z );
|
||||
b3DestroyMesh( data );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int HeightFieldTest( void )
|
||||
{
|
||||
RUN_SUBTEST( HeightFieldCreate );
|
||||
|
|
@ -688,6 +829,8 @@ int HeightFieldTest( void )
|
|||
RUN_SUBTEST( ShapeCastClockwiseWinding );
|
||||
RUN_SUBTEST( RayCastBackside );
|
||||
RUN_SUBTEST( RayCastClockwiseWinding );
|
||||
RUN_SUBTEST( HeightFieldNeighborNormals );
|
||||
RUN_SUBTEST( NeighborNormalDispatch );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
155
test/test_hull.c
155
test/test_hull.c
|
|
@ -580,7 +580,7 @@ static int Hull2DSquareTest( void )
|
|||
b3Point2D hull[16];
|
||||
FillPoints2D( pts, input, 8 );
|
||||
|
||||
int count = b3Hull2D( pts, 8, hull );
|
||||
int count = b3Hull2D( pts, 8, hull, 0 );
|
||||
ENSURE( count == 4 );
|
||||
|
||||
// The reduction code assumes counter clockwise winding
|
||||
|
|
@ -616,7 +616,7 @@ static int Hull2DCollinearTest( void )
|
|||
b3Point2D hull[10];
|
||||
FillPoints2D( pts, input, 5 );
|
||||
|
||||
ENSURE( b3Hull2D( pts, 5, hull ) == 2 );
|
||||
ENSURE( b3Hull2D( pts, 5, hull, 0 ) == 2 );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -635,7 +635,7 @@ static int Hull2DWeldTest( void )
|
|||
b3Point2D hull[10];
|
||||
FillPoints2D( pts, input, 5 );
|
||||
|
||||
int count = b3Hull2D( pts, 5, hull );
|
||||
int count = b3Hull2D( pts, 5, hull, 0 );
|
||||
ENSURE( count == 4 );
|
||||
|
||||
for ( int i = 0; i < count; ++i )
|
||||
|
|
@ -659,7 +659,7 @@ static int SimplifyHull2DTargetTest( void )
|
|||
pts[i].originalIndex = i;
|
||||
}
|
||||
|
||||
int hullCount = b3Hull2D( pts, 20, hull );
|
||||
int hullCount = b3Hull2D( pts, 20, hull, 0 );
|
||||
ENSURE( hullCount == 20 );
|
||||
|
||||
int count = b3SimplifyHull2D( hull, hullCount, 6 );
|
||||
|
|
@ -682,7 +682,7 @@ static int SimplifyHull2DNoopTest( void )
|
|||
b3Point2D hull[8];
|
||||
FillPoints2D( pts, input, 4 );
|
||||
|
||||
int hullCount = b3Hull2D( pts, 4, hull );
|
||||
int hullCount = b3Hull2D( pts, 4, hull, 0 );
|
||||
ENSURE( hullCount == 4 );
|
||||
|
||||
ENSURE( b3SimplifyHull2D( hull, hullCount, 8 ) == 4 );
|
||||
|
|
@ -706,7 +706,7 @@ static int Hull2DOrderTest( void )
|
|||
b3Point2D hull[16];
|
||||
FillPoints2D( pts, input, 8 );
|
||||
|
||||
int count1 = b3Hull2D( pts, 8, hull );
|
||||
int count1 = b3Hull2D( pts, 8, hull, 0 );
|
||||
ENSURE( count1 == 7 );
|
||||
|
||||
bool onHull1[8] = { false };
|
||||
|
|
@ -724,7 +724,7 @@ static int Hull2DOrderTest( void )
|
|||
shuffled[i].originalIndex = i;
|
||||
}
|
||||
|
||||
int count2 = b3Hull2D( shuffled, 8, shuffledHull );
|
||||
int count2 = b3Hull2D( shuffled, 8, shuffledHull, 0 );
|
||||
ENSURE( count2 == count1 );
|
||||
|
||||
bool onHull2[8] = { false };
|
||||
|
|
@ -741,6 +741,143 @@ static int Hull2DOrderTest( void )
|
|||
return 0;
|
||||
}
|
||||
|
||||
// Float rounding can call the middle of three nearly collinear points a left turn in both chains.
|
||||
// Listing it twice gave the mesh manifold a duplicate point.
|
||||
static int Hull2DNearCollinearTest( void )
|
||||
{
|
||||
b3Vec2 input[3] = {
|
||||
{ 0.42742428183555603f, -0.9914372563362122f },
|
||||
{ 0.8582707643508911f, -0.7915351390838623f },
|
||||
{ 1.5856003761291504f, -0.45407217741012573f },
|
||||
};
|
||||
|
||||
b3Point2D pts[3];
|
||||
b3Point2D hull[6];
|
||||
FillPoints2D( pts, input, 3 );
|
||||
|
||||
int count = b3Hull2D( pts, 3, hull, 0 );
|
||||
ENSURE( 2 <= count && count <= 3 );
|
||||
|
||||
for ( int i = 0; i < count; ++i )
|
||||
{
|
||||
for ( int j = i + 1; j < count; ++j )
|
||||
{
|
||||
ENSURE( hull[i].originalIndex != hull[j].originalIndex );
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// A 3 by 3 grid has three points on each side. Only the corners are strict hull vertices.
|
||||
static int Hull2DKeepCollinearTest( void )
|
||||
{
|
||||
b3Vec2 input[9];
|
||||
for ( int i = 0; i < 9; ++i )
|
||||
{
|
||||
input[i] = (b3Vec2){ (float)( i % 3 ), (float)( i / 3 ) };
|
||||
}
|
||||
|
||||
b3Point2D pts[9];
|
||||
b3Point2D hull[18];
|
||||
FillPoints2D( pts, input, 9 );
|
||||
ENSURE( b3Hull2D( pts, 9, hull, 0 ) == 4 );
|
||||
|
||||
FillPoints2D( pts, input, 9 );
|
||||
int count = b3Hull2D( pts, 9, hull, b3_hull2DKeepCollinear );
|
||||
ENSURE( count == 8 );
|
||||
ENSURE( Hull2DArea( hull, count ) > 0.0f );
|
||||
|
||||
for ( int i = 0; i < count; ++i )
|
||||
{
|
||||
ENSURE( hull[i].originalIndex != 4 );
|
||||
}
|
||||
|
||||
// All collinear keeps every point
|
||||
b3Vec2 line[4] = { { 0.0f, 0.0f }, { 1.0f, 0.0f }, { 2.0f, 0.0f }, { 3.0f, 0.0f } };
|
||||
FillPoints2D( pts, line, 4 );
|
||||
ENSURE( b3Hull2D( pts, 4, hull, b3_hull2DKeepCollinear ) == 4 );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Coincident points under the exact merge: the earlier point survives unless a later one is deeper by
|
||||
// more than the linear slop. The default weld always keeps the earlier point.
|
||||
static int Hull2DExactMergeTest( void )
|
||||
{
|
||||
b3Vec2 input[5] = {
|
||||
{ -1.0f, -1.0f }, { 1.0f, -1.0f }, { 1.0f, 1.0f }, { -1.0f, 1.0f }, { -1.0f, -1.0f },
|
||||
};
|
||||
|
||||
float depths[2] = { 2.0f * B3_LINEAR_SLOP, 0.5f * B3_LINEAR_SLOP };
|
||||
int expected[2] = { 4, 0 };
|
||||
|
||||
for ( int k = 0; k < 2; ++k )
|
||||
{
|
||||
b3Point2D pts[5];
|
||||
b3Point2D hull[10];
|
||||
FillPoints2D( pts, input, 5 );
|
||||
pts[4].separation = -depths[k];
|
||||
|
||||
int count = b3Hull2D( pts, 5, hull, b3_hull2DExactMerge );
|
||||
ENSURE( count == 4 );
|
||||
|
||||
int survivor = -1;
|
||||
for ( int i = 0; i < count; ++i )
|
||||
{
|
||||
if ( hull[i].originalIndex == 0 || hull[i].originalIndex == 4 )
|
||||
{
|
||||
survivor = hull[i].originalIndex;
|
||||
}
|
||||
}
|
||||
ENSURE( survivor == expected[k] );
|
||||
|
||||
FillPoints2D( pts, input, 5 );
|
||||
pts[4].separation = -depths[k];
|
||||
count = b3Hull2D( pts, 5, hull, 0 );
|
||||
ENSURE( count == 4 );
|
||||
|
||||
for ( int i = 0; i < count; ++i )
|
||||
{
|
||||
ENSURE( hull[i].originalIndex != 4 );
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// The index order flag returns the same points sorted by input index
|
||||
static int Hull2DIndexOrderTest( void )
|
||||
{
|
||||
b3Vec2 input[8] = {
|
||||
{ 1.0f, 2.0f }, { -2.5f, 0.4f }, { 2.0f, -1.0f }, { 0.2f, 0.1f },
|
||||
{ -2.0f, -1.0f }, { 2.5f, 0.5f }, { 0.0f, -1.5f }, { -1.0f, 1.8f },
|
||||
};
|
||||
|
||||
b3Point2D pts[8];
|
||||
b3Point2D hull[16];
|
||||
FillPoints2D( pts, input, 8 );
|
||||
int count1 = b3Hull2D( pts, 8, hull, 0 );
|
||||
|
||||
bool onHull[8] = { false };
|
||||
for ( int i = 0; i < count1; ++i )
|
||||
{
|
||||
onHull[hull[i].originalIndex] = true;
|
||||
}
|
||||
|
||||
FillPoints2D( pts, input, 8 );
|
||||
int count2 = b3Hull2D( pts, 8, hull, b3_hull2DIndexOrder );
|
||||
ENSURE( count2 == count1 );
|
||||
|
||||
for ( int i = 0; i < count2; ++i )
|
||||
{
|
||||
ENSURE( onHull[hull[i].originalIndex] );
|
||||
ENSURE( i == 0 || hull[i - 1].originalIndex < hull[i].originalIndex );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int HullTest( void )
|
||||
{
|
||||
RUN_SUBTEST( CreateHullCubeTest );
|
||||
|
|
@ -759,6 +896,10 @@ int HullTest( void )
|
|||
RUN_SUBTEST( Hull2DCollinearTest );
|
||||
RUN_SUBTEST( Hull2DWeldTest );
|
||||
RUN_SUBTEST( Hull2DOrderTest );
|
||||
RUN_SUBTEST( Hull2DNearCollinearTest );
|
||||
RUN_SUBTEST( Hull2DKeepCollinearTest );
|
||||
RUN_SUBTEST( Hull2DExactMergeTest );
|
||||
RUN_SUBTEST( Hull2DIndexOrderTest );
|
||||
RUN_SUBTEST( SimplifyHull2DTargetTest );
|
||||
RUN_SUBTEST( SimplifyHull2DNoopTest );
|
||||
|
||||
|
|
|
|||
|
|
@ -430,7 +430,7 @@ static int TriangleEdgeTest( void )
|
|||
b3LocalManifold manifold = { 0 };
|
||||
manifold.points = points;
|
||||
b3SATCache cache = { .type = b3_manualEdgePairAxis };
|
||||
b3CollideTriangleAndHull( &manifold, 8, v1, v2, v3, 0, &hull.base, &cache, true );
|
||||
b3CollideTriangleAndHull( &manifold, 8, v1, v2, v3, &hull.base, &cache, true );
|
||||
|
||||
b3Vec3 expectedNormal = b3Neg( axis );
|
||||
b3Vec3 expectedPoint = b3MulAdd( hullPoint, 0.5f * gap, axis );
|
||||
|
|
@ -463,7 +463,7 @@ static int TriangleEdgeTest( void )
|
|||
b3LocalManifold manifold = { 0 };
|
||||
manifold.points = points;
|
||||
b3SATCache cache = { 0 };
|
||||
b3CollideTriangleAndHull( &manifold, 8, v1, v2, v3, 0, &hull.base, &cache, true );
|
||||
b3CollideTriangleAndHull( &manifold, 8, v1, v2, v3, &hull.base, &cache, true );
|
||||
|
||||
ENSURE( manifold.pointCount == 0 );
|
||||
ENSURE( cache.type == b3_edgePairAxis );
|
||||
|
|
@ -496,7 +496,7 @@ static int TriangleParallelEdgeTest( void )
|
|||
b3LocalManifold manifold = { 0 };
|
||||
manifold.points = points;
|
||||
b3SATCache cache = { 0 };
|
||||
b3CollideTriangleAndHull( &manifold, 8, v1, v2, v3, 0, &hull.base, &cache, true );
|
||||
b3CollideTriangleAndHull( &manifold, 8, v1, v2, v3, &hull.base, &cache, true );
|
||||
|
||||
ENSURE_FACE_POINTS( manifold.pointCount );
|
||||
ENSURE( cache.type == b3_faceAxisA );
|
||||
|
|
@ -890,7 +890,7 @@ static int TriangleHullEdgeSweepTest( void )
|
|||
b3LocalManifold manifold = { 0 };
|
||||
manifold.points = points;
|
||||
b3SATCache cache = { .type = b3_manualEdgePairAxis };
|
||||
b3CollideTriangleAndHull( &manifold, 8, v1, v2, v3, 0, &hull.base, &cache, true );
|
||||
b3CollideTriangleAndHull( &manifold, 8, v1, v2, v3, &hull.base, &cache, true );
|
||||
|
||||
if ( cache.type != b3_edgePairAxis || manifold.pointCount != 1 )
|
||||
{
|
||||
|
|
@ -1340,7 +1340,7 @@ static int SpeculativeMarginTest( void )
|
|||
manifold.pointCount = 0;
|
||||
b3BoxHull raised = b3MakeTransformedBoxHull( 0.5f, 0.5f, 0.5f, SlideY( 0.5f + gap ) );
|
||||
b3SATCache cache = { 0 };
|
||||
b3CollideTriangleAndHull( &manifold, B3_MAX_MANIFOLD_POINTS, triangle[0], triangle[1], triangle[2], 0, &raised.base,
|
||||
b3CollideTriangleAndHull( &manifold, B3_MAX_MANIFOLD_POINTS, triangle[0], triangle[1], triangle[2], &raised.base,
|
||||
&cache, true );
|
||||
ENSURE( CheckSpeculativePoints( &manifold, gap ) == 0 );
|
||||
}
|
||||
|
|
|
|||
1017
test/test_mesh.c
1017
test/test_mesh.c
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue