rename (asset to entity)

This commit is contained in:
Nick Fisher
2024-02-15 15:16:56 +08:00
parent 935b876ce9
commit 2ae3f8c466
15 changed files with 108 additions and 41 deletions

View File

@@ -234,6 +234,9 @@ namespace polyvox
inst->getAnimator()->updateBoneMatrices();
inst->recomputeBoundingBoxes();
auto box = inst->getBoundingBox();
auto verts = box.extent();
Log("AABB extent for %s is %f %f %f", uri, verts.x, verts.y, verts.z);
asset->releaseSourceData();

View File

@@ -639,7 +639,7 @@ namespace polyvox
FilamentViewer::~FilamentViewer()
{
clearAssets();
clearEntities();
delete _assetManager;
for (auto it : _lights)
@@ -725,7 +725,7 @@ namespace polyvox
_engine->flushAndWait();
}
void FilamentViewer::clearAssets()
void FilamentViewer::clearEntities()
{
Log("Clearing all assets");
if (_mainCamera)
@@ -738,7 +738,7 @@ namespace polyvox
Log("Cleared all assets");
}
void FilamentViewer::removeAsset(EntityId asset)
void FilamentViewer::removeEntity(EntityId asset)
{
Log("Removing asset from scene");

View File

@@ -450,14 +450,14 @@ extern "C"
strcpy(outPtr, name.c_str());
}
FLUTTER_PLUGIN_EXPORT void remove_asset(const void *const viewer, EntityId asset)
FLUTTER_PLUGIN_EXPORT void remove_entity(const void *const viewer, EntityId asset)
{
((FilamentViewer *)viewer)->removeAsset(asset);
((FilamentViewer *)viewer)->removeEntity(asset);
}
FLUTTER_PLUGIN_EXPORT void clear_assets(const void *const viewer)
FLUTTER_PLUGIN_EXPORT void clear_entities(const void *const viewer)
{
((FilamentViewer *)viewer)->clearAssets();
((FilamentViewer *)viewer)->clearEntities();
}
bool set_material_color(void *assetManager, EntityId asset, const char *meshName, int materialIndex, const float r, const float g, const float b, const float a)

View File

@@ -366,14 +366,14 @@ FLUTTER_PLUGIN_EXPORT void clear_lights_ffi(void *const viewer) {
fut.wait();
}
FLUTTER_PLUGIN_EXPORT void remove_asset_ffi(void *const viewer,
FLUTTER_PLUGIN_EXPORT void remove_entity_ffi(void *const viewer,
EntityId asset) {
std::packaged_task<void()> lambda([&] { remove_asset(viewer, asset); });
std::packaged_task<void()> lambda([&] { remove_entity(viewer, asset); });
auto fut = _rl->add_task(lambda);
fut.wait();
}
FLUTTER_PLUGIN_EXPORT void clear_assets_ffi(void *const viewer) {
std::packaged_task<void()> lambda([&] { clear_assets(viewer); });
FLUTTER_PLUGIN_EXPORT void clear_entities_ffi(void *const viewer) {
std::packaged_task<void()> lambda([&] { clear_entities(viewer); });
auto fut = _rl->add_task(lambda);
fut.wait();
}

54
ios/src/Untitled-1.cpp Normal file
View File

@@ -0,0 +1,54 @@
// we know there's been a collision, but we want to adjust the direction vector to continue movement in the non-colliding direction
// first, we need to find the AABB plane that we have collided with
auto vertices = targetBox.getCorners().vertices;
// each entry here is a plane from the target bounding box
// (we drop the fourth vertex because it's mathematically not necessary to define the plane)
std::vector<std::vector<filament::math::float3>> planes = {
{
vertices[0],vertices[2],vertices[4] // bottom
},
{
vertices[1],vertices[3],vertices[5] // top
},
{
vertices[0],vertices[1],vertices[4] // back
},
{
vertices[0],vertices[1],vertices[2] // left
},
{
vertices[4],vertices[5],vertices[6] // right
},
{
vertices[2],vertices[3],vertices[6] //front
},
};
// now, iterate over each plane and project the intersecting source vertex onto it
// the smallest value will be the closest plane
auto sourceVertex = sourceCorners.vertices[i];
int planeIndex = -1;
int minDist = 999999.0f;
filament::math::float3 projection;
for(int j = 0; j < 6; j++) {
// translate the plane so the intersecting source vertex is at the origin
auto plane = std::vector<filament::math::float3>{ planes[j][0] - sourceVertex, planes[j][1] - sourceVertex, planes[j][2] - sourceVertex };
// cross product of the two known co-planar vectors to find the normal
auto normal = normalize(cross(plane[1] - plane[0], plane[2] - plane[1]));
// project the normal onto the original (untranslated) plane vector
auto dist = dot(planes[j][0], normal) / norm(planes[j][0]);
Log("Dist : %f", dist);
if(dist < minDist) {
minDist = dist;
planeIndex = j;
}
}
Log("Collision with plane index %d", planeIndex);
auto sourceNormal = normalize(cross(planes[planeIndex][1] - planes[planeIndex][0], planes[planeIndex][2] - planes[planeIndex][1]));
projection = direction - (sourceNormal * dot(sourceNormal, direction));