AABB shared data (#3655)

This commit is contained in:
GengineJS
2021-06-28 15:31:57 +08:00
committed by GitHub
parent 7b3218e482
commit 979c0d950e
17 changed files with 131 additions and 299 deletions
+32 -219
View File
@@ -645,174 +645,30 @@ bool js_register_scene_Frustum(se::Object* obj) // NOLINT(readability-identifier
se::Object* __jsb_cc_scene_AABB_proto = nullptr;
se::Class* __jsb_cc_scene_AABB_class = nullptr;
static bool js_scene_AABB_set(se::State& s) // NOLINT(readability-identifier-naming, google-runtime-references)
static bool js_scene_AABB_initWithData(se::State& s) // NOLINT(readability-identifier-naming, google-runtime-references)
{
auto* cobj = SE_THIS_OBJECT<cc::scene::AABB>(s);
SE_PRECONDITION2(cobj, false, "js_scene_AABB_set : Invalid Native Object");
SE_PRECONDITION2(cobj, false, "js_scene_AABB_initWithData : Invalid Native Object");
const auto& args = s.args();
size_t argc = args.size();
CC_UNUSED bool ok = true;
if (argc == 2) {
HolderType<cc::Vec3, true> arg0 = {};
HolderType<cc::Vec3, true> arg1 = {};
if (argc == 1) {
HolderType<unsigned char*, false> arg0 = {};
ok &= sevalue_to_native(args[0], &arg0, s.thisObject());
ok &= sevalue_to_native(args[1], &arg1, s.thisObject());
SE_PRECONDITION2(ok, false, "js_scene_AABB_set : Error processing arguments");
cobj->set(arg0.value(), arg1.value());
SE_PRECONDITION2(ok, false, "js_scene_AABB_initWithData : Error processing arguments");
cobj->initWithData(arg0.value());
return true;
}
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 2);
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
return false;
}
SE_BIND_FUNC(js_scene_AABB_set)
static bool js_scene_AABB_fromPoints(se::State& s) // NOLINT(readability-identifier-naming, google-runtime-references)
{
const auto& args = s.args();
size_t argc = args.size();
CC_UNUSED bool ok = true;
if (argc == 3) {
HolderType<cc::Vec3, true> arg0 = {};
HolderType<cc::Vec3, true> arg1 = {};
HolderType<cc::scene::AABB*, false> arg2 = {};
ok &= sevalue_to_native(args[0], &arg0, nullptr);
ok &= sevalue_to_native(args[1], &arg1, nullptr);
ok &= sevalue_to_native(args[2], &arg2, nullptr);
SE_PRECONDITION2(ok, false, "js_scene_AABB_fromPoints : Error processing arguments");
cc::scene::AABB::fromPoints(arg0.value(), arg1.value(), arg2.value());
return true;
}
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 3);
return false;
}
SE_BIND_FUNC(js_scene_AABB_fromPoints)
static bool js_scene_AABB_get_center(se::State& s) // NOLINT(readability-identifier-naming, google-runtime-references)
{
auto* cobj = SE_THIS_OBJECT<cc::scene::AABB>(s);
SE_PRECONDITION2(cobj, false, "js_scene_AABB_get_center : Invalid Native Object");
CC_UNUSED bool ok = true;
se::Value jsret;
ok &= nativevalue_to_se(cobj->center, jsret, s.thisObject() /*ctx*/);
s.rval() = jsret;
SE_HOLD_RETURN_VALUE(cobj->center, s.thisObject(), s.rval());
return true;
}
SE_BIND_PROP_GET(js_scene_AABB_get_center)
static bool js_scene_AABB_set_center(se::State& s) // NOLINT(readability-identifier-naming, google-runtime-references)
{
const auto& args = s.args();
auto* cobj = SE_THIS_OBJECT<cc::scene::AABB>(s);
SE_PRECONDITION2(cobj, false, "js_scene_AABB_set_center : Invalid Native Object");
CC_UNUSED bool ok = true;
ok &= sevalue_to_native(args[0], &cobj->center, s.thisObject());
SE_PRECONDITION2(ok, false, "js_scene_AABB_set_center : Error processing new value");
return true;
}
SE_BIND_PROP_SET(js_scene_AABB_set_center)
static bool js_scene_AABB_get_halfExtents(se::State& s) // NOLINT(readability-identifier-naming, google-runtime-references)
{
auto* cobj = SE_THIS_OBJECT<cc::scene::AABB>(s);
SE_PRECONDITION2(cobj, false, "js_scene_AABB_get_halfExtents : Invalid Native Object");
CC_UNUSED bool ok = true;
se::Value jsret;
ok &= nativevalue_to_se(cobj->halfExtents, jsret, s.thisObject() /*ctx*/);
s.rval() = jsret;
SE_HOLD_RETURN_VALUE(cobj->halfExtents, s.thisObject(), s.rval());
return true;
}
SE_BIND_PROP_GET(js_scene_AABB_get_halfExtents)
static bool js_scene_AABB_set_halfExtents(se::State& s) // NOLINT(readability-identifier-naming, google-runtime-references)
{
const auto& args = s.args();
auto* cobj = SE_THIS_OBJECT<cc::scene::AABB>(s);
SE_PRECONDITION2(cobj, false, "js_scene_AABB_set_halfExtents : Invalid Native Object");
CC_UNUSED bool ok = true;
ok &= sevalue_to_native(args[0], &cobj->halfExtents, s.thisObject());
SE_PRECONDITION2(ok, false, "js_scene_AABB_set_halfExtents : Error processing new value");
return true;
}
SE_BIND_PROP_SET(js_scene_AABB_set_halfExtents)
template<>
bool sevalue_to_native(const se::Value &from, cc::scene::AABB * to, se::Object *ctx)
{
assert(from.isObject());
se::Object *json = from.toObject();
auto* data = reinterpret_cast<cc::scene::AABB*>(json->getPrivateData());
if (data) {
*to = *data;
return true;
}
se::Value field;
bool ok = true;
json->getProperty("center", &field);
if(!field.isNullOrUndefined()) {
ok &= sevalue_to_native(field, &(to->center), ctx);
}
json->getProperty("halfExtents", &field);
if(!field.isNullOrUndefined()) {
ok &= sevalue_to_native(field, &(to->halfExtents), ctx);
}
return ok;
}
SE_BIND_FUNC(js_scene_AABB_initWithData)
SE_DECLARE_FINALIZE_FUNC(js_cc_scene_AABB_finalize)
static bool js_scene_AABB_constructor(se::State& s) // NOLINT(readability-identifier-naming, google-runtime-references)
static bool js_scene_AABB_constructor(se::State& s) // NOLINT(readability-identifier-naming, google-runtime-references) constructor.c
{
CC_UNUSED bool ok = true;
const auto& args = s.args();
size_t argc = args.size();
if(argc == 0)
{
cc::scene::AABB* cobj = JSB_ALLOC(cc::scene::AABB);
s.thisObject()->setPrivateData(cobj);
se::NonRefNativePtrCreatedByCtorMap::emplace(cobj);
return true;
}
if(argc == 1 && args[0].isObject())
{
se::Object *json = args[0].toObject();
se::Value field;
cc::scene::AABB* cobj = JSB_ALLOC(cc::scene::AABB);
ok &= sevalue_to_native(args[0], cobj, s.thisObject());
if(!ok) {
JSB_FREE(cobj);
SE_REPORT_ERROR("argument convertion error");
return false;
}
s.thisObject()->setPrivateData(cobj);
se::NonRefNativePtrCreatedByCtorMap::emplace(cobj);
return true;
}
cc::scene::AABB* cobj = JSB_ALLOC(cc::scene::AABB);
if (argc > 0 && !args[0].isUndefined()) {
ok &= sevalue_to_native(args[0], &(cobj->center), nullptr);
}
if (argc > 1 && !args[1].isUndefined()) {
ok &= sevalue_to_native(args[1], &(cobj->halfExtents), nullptr);
}
if(!ok) {
JSB_FREE(cobj);
SE_REPORT_ERROR("Argument convertion error");
return false;
}
s.thisObject()->setPrivateData(cobj);
se::NonRefNativePtrCreatedByCtorMap::emplace(cobj);
return true;
@@ -838,10 +694,7 @@ bool js_register_scene_AABB(se::Object* obj) // NOLINT(readability-identifier-na
{
auto* cls = se::Class::create("AABB", obj, nullptr, _SE(js_scene_AABB_constructor));
cls->defineProperty("center", _SE(js_scene_AABB_get_center), _SE(js_scene_AABB_set_center));
cls->defineProperty("halfExtents", _SE(js_scene_AABB_get_halfExtents), _SE(js_scene_AABB_set_halfExtents));
cls->defineFunction("set", _SE(js_scene_AABB_set));
cls->defineStaticFunction("fromPoints", _SE(js_scene_AABB_fromPoints));
cls->defineFunction("initWithData", _SE(js_scene_AABB_initWithData));
cls->defineFinalizeFunction(_SE(js_cc_scene_AABB_finalize));
cls->install();
JSBClassType::registerClass<cc::scene::AABB>(cls);
@@ -863,7 +716,7 @@ static bool js_scene_SpotLight_setAABB(se::State& s) // NOLINT(readability-ident
size_t argc = args.size();
CC_UNUSED bool ok = true;
if (argc == 1) {
HolderType<cc::scene::AABB, false> arg0 = {};
HolderType<cc::scene::AABB*, false> arg0 = {};
ok &= sevalue_to_native(args[0], &arg0, s.thisObject());
SE_PRECONDITION2(ok, false, "js_scene_SpotLight_setAABB : Error processing arguments");
cobj->setAABB(arg0.value());
@@ -1106,7 +959,7 @@ static bool js_scene_SphereLight_setAABB(se::State& s) // NOLINT(readability-ide
size_t argc = args.size();
CC_UNUSED bool ok = true;
if (argc == 1) {
HolderType<cc::scene::AABB, false> arg0 = {};
HolderType<cc::scene::AABB*, false> arg0 = {};
ok &= sevalue_to_native(args[0], &arg0, s.thisObject());
SE_PRECONDITION2(ok, false, "js_scene_SphereLight_setAABB : Error processing arguments");
cobj->setAABB(arg0.value());
@@ -1412,25 +1265,6 @@ static bool js_scene_Model_getLocalData(se::State& s) // NOLINT(readability-iden
}
SE_BIND_FUNC(js_scene_Model_getLocalData)
static bool js_scene_Model_getModelBounds(se::State& s) // NOLINT(readability-identifier-naming, google-runtime-references)
{
auto* cobj = SE_THIS_OBJECT<cc::scene::Model>(s);
SE_PRECONDITION2(cobj, false, "js_scene_Model_getModelBounds : Invalid Native Object");
const auto& args = s.args();
size_t argc = args.size();
CC_UNUSED bool ok = true;
if (argc == 0) {
const cc::scene::AABB& result = cobj->getModelBounds();
ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/);
SE_PRECONDITION2(ok, false, "js_scene_Model_getModelBounds : Error processing arguments");
SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval());
return true;
}
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
return false;
}
SE_BIND_FUNC(js_scene_Model_getModelBounds)
static bool js_scene_Model_getNode(se::State& s) // NOLINT(readability-identifier-naming, google-runtime-references)
{
auto* cobj = SE_THIS_OBJECT<cc::scene::Model>(s);
@@ -1564,25 +1398,6 @@ static bool js_scene_Model_getVisFlags(se::State& s) // NOLINT(readability-ident
}
SE_BIND_FUNC(js_scene_Model_getVisFlags)
static bool js_scene_Model_getWorldBounds(se::State& s) // NOLINT(readability-identifier-naming, google-runtime-references)
{
auto* cobj = SE_THIS_OBJECT<cc::scene::Model>(s);
SE_PRECONDITION2(cobj, false, "js_scene_Model_getWorldBounds : Invalid Native Object");
const auto& args = s.args();
size_t argc = args.size();
CC_UNUSED bool ok = true;
if (argc == 0) {
const cc::scene::AABB* result = cobj->getWorldBounds();
ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/);
SE_PRECONDITION2(ok, false, "js_scene_Model_getWorldBounds : Error processing arguments");
SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval());
return true;
}
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
return false;
}
SE_BIND_FUNC(js_scene_Model_getWorldBounds)
static bool js_scene_Model_seVisFlag(se::State& s) // NOLINT(readability-identifier-naming, google-runtime-references)
{
auto* cobj = SE_THIS_OBJECT<cc::scene::Model>(s);
@@ -1602,6 +1417,25 @@ static bool js_scene_Model_seVisFlag(se::State& s) // NOLINT(readability-identif
}
SE_BIND_FUNC(js_scene_Model_seVisFlag)
static bool js_scene_Model_setBounds(se::State& s) // NOLINT(readability-identifier-naming, google-runtime-references)
{
auto* cobj = SE_THIS_OBJECT<cc::scene::Model>(s);
SE_PRECONDITION2(cobj, false, "js_scene_Model_setBounds : Invalid Native Object");
const auto& args = s.args();
size_t argc = args.size();
CC_UNUSED bool ok = true;
if (argc == 1) {
HolderType<cc::scene::AABB*, false> arg0 = {};
ok &= sevalue_to_native(args[0], &arg0, s.thisObject());
SE_PRECONDITION2(ok, false, "js_scene_Model_setBounds : Error processing arguments");
cobj->setBounds(arg0.value());
return true;
}
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
return false;
}
SE_BIND_FUNC(js_scene_Model_setBounds)
static bool js_scene_Model_setCastShadow(se::State& s) // NOLINT(readability-identifier-naming, google-runtime-references)
{
auto* cobj = SE_THIS_OBJECT<cc::scene::Model>(s);
@@ -1735,25 +1569,6 @@ static bool js_scene_Model_setTransform(se::State& s) // NOLINT(readability-iden
}
SE_BIND_FUNC(js_scene_Model_setTransform)
static bool js_scene_Model_setWolrdBounds(se::State& s) // NOLINT(readability-identifier-naming, google-runtime-references)
{
auto* cobj = SE_THIS_OBJECT<cc::scene::Model>(s);
SE_PRECONDITION2(cobj, false, "js_scene_Model_setWolrdBounds : Invalid Native Object");
const auto& args = s.args();
size_t argc = args.size();
CC_UNUSED bool ok = true;
if (argc == 1) {
HolderType<cc::scene::AABB, true> arg0 = {};
ok &= sevalue_to_native(args[0], &arg0, s.thisObject());
SE_PRECONDITION2(ok, false, "js_scene_Model_setWolrdBounds : Error processing arguments");
cobj->setWolrdBounds(arg0.value());
return true;
}
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
return false;
}
SE_BIND_FUNC(js_scene_Model_setWolrdBounds)
static bool js_scene_Model_updateTransform(se::State& s) // NOLINT(readability-identifier-naming, google-runtime-references)
{
auto* cobj = SE_THIS_OBJECT<cc::scene::Model>(s);
@@ -1831,7 +1646,6 @@ bool js_register_scene_Model(se::Object* obj) // NOLINT(readability-identifier-n
cls->defineFunction("getInstancedBuffer", _SE(js_scene_Model_getInstancedBuffer));
cls->defineFunction("getInstancedBufferSize", _SE(js_scene_Model_getInstancedBufferSize));
cls->defineFunction("getLocalData", _SE(js_scene_Model_getLocalData));
cls->defineFunction("getModelBounds", _SE(js_scene_Model_getModelBounds));
cls->defineFunction("getNode", _SE(js_scene_Model_getNode));
cls->defineFunction("getReceiveShadow", _SE(js_scene_Model_getReceiveShadow));
cls->defineFunction("getSubModels", _SE(js_scene_Model_getSubModels));
@@ -1839,8 +1653,8 @@ bool js_register_scene_Model(se::Object* obj) // NOLINT(readability-identifier-n
cls->defineFunction("getTransformUpdated", _SE(js_scene_Model_getTransformUpdated));
cls->defineFunction("getUpdatStamp", _SE(js_scene_Model_getUpdatStamp));
cls->defineFunction("getVisFlags", _SE(js_scene_Model_getVisFlags));
cls->defineFunction("getWorldBounds", _SE(js_scene_Model_getWorldBounds));
cls->defineFunction("seVisFlag", _SE(js_scene_Model_seVisFlag));
cls->defineFunction("setBounds", _SE(js_scene_Model_setBounds));
cls->defineFunction("setCastShadow", _SE(js_scene_Model_setCastShadow));
cls->defineFunction("setEnabled", _SE(js_scene_Model_setEnabled));
cls->defineFunction("setInstMatWorldIdx", _SE(js_scene_Model_setInstMatWorldIdx));
@@ -1848,7 +1662,6 @@ bool js_register_scene_Model(se::Object* obj) // NOLINT(readability-identifier-n
cls->defineFunction("setNode", _SE(js_scene_Model_setNode));
cls->defineFunction("setReceiveShadow", _SE(js_scene_Model_setReceiveShadow));
cls->defineFunction("setTransform", _SE(js_scene_Model_setTransform));
cls->defineFunction("setWolrdBounds", _SE(js_scene_Model_setWolrdBounds));
cls->defineFunction("updateTransform", _SE(js_scene_Model_updateTransform));
cls->defineFunction("updateUBOs", _SE(js_scene_Model_updateUBOs));
cls->defineFinalizeFunction(_SE(js_cc_scene_Model_finalize));
+3 -7
View File
@@ -80,11 +80,9 @@ extern se::Class* __jsb_cc_scene_AABB_class;
bool js_register_cc_scene_AABB(se::Object* obj);
bool register_all_scene(se::Object* obj);
template<>
bool sevalue_to_native(const se::Value &, cc::scene::AABB *, se::Object *ctx);
JSB_REGISTER_OBJECT_TYPE(cc::scene::AABB);
SE_DECLARE_FUNC(js_scene_AABB_set);
SE_DECLARE_FUNC(js_scene_AABB_fromPoints);
SE_DECLARE_FUNC(js_scene_AABB_initWithData);
SE_DECLARE_FUNC(js_scene_AABB_AABB);
extern se::Object* __jsb_cc_scene_SpotLight_proto;
extern se::Class* __jsb_cc_scene_SpotLight_class;
@@ -135,7 +133,6 @@ SE_DECLARE_FUNC(js_scene_Model_getInstancedAttributeBlock);
SE_DECLARE_FUNC(js_scene_Model_getInstancedBuffer);
SE_DECLARE_FUNC(js_scene_Model_getInstancedBufferSize);
SE_DECLARE_FUNC(js_scene_Model_getLocalData);
SE_DECLARE_FUNC(js_scene_Model_getModelBounds);
SE_DECLARE_FUNC(js_scene_Model_getNode);
SE_DECLARE_FUNC(js_scene_Model_getReceiveShadow);
SE_DECLARE_FUNC(js_scene_Model_getSubModels);
@@ -143,8 +140,8 @@ SE_DECLARE_FUNC(js_scene_Model_getTransform);
SE_DECLARE_FUNC(js_scene_Model_getTransformUpdated);
SE_DECLARE_FUNC(js_scene_Model_getUpdatStamp);
SE_DECLARE_FUNC(js_scene_Model_getVisFlags);
SE_DECLARE_FUNC(js_scene_Model_getWorldBounds);
SE_DECLARE_FUNC(js_scene_Model_seVisFlag);
SE_DECLARE_FUNC(js_scene_Model_setBounds);
SE_DECLARE_FUNC(js_scene_Model_setCastShadow);
SE_DECLARE_FUNC(js_scene_Model_setEnabled);
SE_DECLARE_FUNC(js_scene_Model_setInstMatWorldIdx);
@@ -152,7 +149,6 @@ SE_DECLARE_FUNC(js_scene_Model_setLocalBuffer);
SE_DECLARE_FUNC(js_scene_Model_setNode);
SE_DECLARE_FUNC(js_scene_Model_setReceiveShadow);
SE_DECLARE_FUNC(js_scene_Model_setTransform);
SE_DECLARE_FUNC(js_scene_Model_setWolrdBounds);
SE_DECLARE_FUNC(js_scene_Model_updateTransform);
SE_DECLARE_FUNC(js_scene_Model_updateUBOs);
SE_DECLARE_FUNC(js_scene_Model_Model);
@@ -104,8 +104,8 @@ void PhysXShape::updateEventListener(EShapeFilterFlag flag) {
scene::AABB &PhysXShape::getAABB() {
static scene::AABB aabb;
auto bounds = physx::PxShapeExt::getWorldBounds(getShape(), *getSharedBody().getImpl().rigidActor);
pxSetVec3Ext(aabb.center, (bounds.maximum + bounds.minimum) / 2);
pxSetVec3Ext(aabb.halfExtents, (bounds.maximum - bounds.minimum) / 2);
pxSetVec3Ext(aabb.getLayout()->center, (bounds.maximum + bounds.minimum) / 2);
pxSetVec3Ext(aabb.getLayout()->halfExtents, (bounds.maximum - bounds.minimum) / 2);
return aabb;
}
+2 -2
View File
@@ -135,8 +135,8 @@ template <>
inline bool nativevalue_to_se(const cc::scene::AABB &from, se::Value &to, se::Object *ctx) {
se::HandleObject obj(se::Object::createPlainObject());
se::Value tmp;
if (nativevalue_to_se(from.center, tmp, ctx)) obj->setProperty("center", tmp);
if (nativevalue_to_se(from.halfExtents, tmp, ctx)) obj->setProperty("halfExtents", tmp);
if (nativevalue_to_se(from.getCenter(), tmp, ctx)) obj->setProperty("center", tmp);
if (nativevalue_to_se(from.getHalfExtents(), tmp, ctx)) obj->setProperty("halfExtents", tmp);
to.setObject(obj);
return true;
}
@@ -64,7 +64,7 @@ RenderAdditiveLightQueue::RenderAdditiveLightQueue(RenderPipeline *pipeline) : _
_firstLightBufferView = device->createBuffer({_lightBuffer, 0, UBOForwardLight::SIZE});
_lightBufferData.resize(_lightBufferElementCount * _lightBufferCount);
_dynamicOffsets.resize(1, 0);
_phaseID = getPhaseID("forward-add");
_phaseID = getPhaseID("forward-add");
_shadowUBO.fill(0.F);
}
@@ -94,9 +94,9 @@ void RenderAdditiveLightQueue::recordCommandBuffer(gfx::Device *device, gfx::Ren
cmdBuffer->bindInputAssembler(ia);
for (size_t i = 0; i < dynamicOffsets.size(); ++i) {
const auto light = lights[i];
auto * globalDescriptorSet = _pipeline->getGlobalDSManager()->getOrCreateDescriptorSet(light);
_dynamicOffsets[0] = dynamicOffsets[i];
const auto light = lights[i];
auto * globalDescriptorSet = _pipeline->getGlobalDSManager()->getOrCreateDescriptorSet(light);
_dynamicOffsets[0] = dynamicOffsets[i];
cmdBuffer->bindDescriptorSet(globalSet, globalDescriptorSet);
cmdBuffer->bindDescriptorSet(localSet, descriptorSet, _dynamicOffsets);
cmdBuffer->draw(ia);
@@ -317,8 +317,8 @@ void RenderAdditiveLightQueue::updateLightDescriptorSet(const scene::Camera *cam
const scene::Light *mainLight = scene->getMainLight();
for (uint i = 0; i < _validLights.size(); ++i) {
const auto * light = _validLights[i];
auto *descriptorSet = _pipeline->getGlobalDSManager()->getOrCreateDescriptorSet(i);
const auto *light = _validLights[i];
auto * descriptorSet = _pipeline->getGlobalDSManager()->getOrCreateDescriptorSet(i);
if (!descriptorSet) {
continue;
}
@@ -41,14 +41,14 @@
namespace cc {
namespace pipeline {
bool castBoundsInitialized = false;
bool castBoundsInitialized = false;
scene::AABB castWorldBounds;
RenderObject genRenderObject(const scene::Model *model, const scene::Camera *camera) {
float depth = 0;
if (model->getNode()) {
auto *const node = model->getTransform();
cc::Vec3 position;
cc::Vec3 position;
cc::Vec3::subtract(node->getWorldPosition(), camera->position, &position);
depth = position.dot(camera->forward);
}
@@ -107,9 +107,9 @@ void updateSphereLight(scene::Shadow *shadows, const scene::Light *light, std::a
void updateDirLight(scene::Shadow *shadows, const scene::Light *light, std::array<float, UBOShadow::COUNT> *shadowUBO) {
auto *const node = light->getNode();
const auto & rotation = node->getWorldRotation();
Quaternion qt(rotation.x, rotation.y, rotation.z, rotation.w);
Vec3 forward(0, 0, -1.0F);
const auto &rotation = node->getWorldRotation();
Quaternion qt(rotation.x, rotation.y, rotation.z, rotation.w);
Vec3 forward(0, 0, -1.0F);
forward.transformQuat(qt);
const auto &normal = shadows->normal;
const auto distance = shadows->distance + 0.001F; // avoid z-fighting
@@ -194,7 +194,7 @@ void sceneCulling(RenderPipeline *pipeline, scene::Camera *camera) {
const auto *modelWorldBounds = model->getWorldBounds();
if (isShadowMap && model->getCastShadow() && modelWorldBounds) {
if (!castBoundsInitialized) {
castWorldBounds = *modelWorldBounds;
castWorldBounds.set(modelWorldBounds->getCenter(), modelWorldBounds->getHalfExtents());
castBoundsInitialized = true;
}
castWorldBounds.merge(*modelWorldBounds);
+32 -23
View File
@@ -27,25 +27,25 @@
namespace cc {
namespace scene {
bool AABB::aabbAabb(const AABB &aabb) const {
bool AABB::aabbAabb(AABB *aabb) const {
Vec3 aMin;
Vec3 aMax;
Vec3 bMin;
Vec3 bMax;
Vec3::subtract(center, halfExtents, &aMin);
Vec3::add(center, halfExtents, &aMax);
Vec3::subtract(center, aabb.halfExtents, &bMin);
Vec3::add(aabb.center, aabb.halfExtents, &bMax);
Vec3::subtract(getCenter(), getHalfExtents(), &aMin);
Vec3::add(getCenter(), getHalfExtents(), &aMax);
Vec3::subtract(getCenter(), aabb->getHalfExtents(), &bMin);
Vec3::add(aabb->getCenter(), aabb->getHalfExtents(), &bMax);
return (aMin.x <= bMax.x && aMax.x >= bMin.x) &&
(aMin.y <= bMax.y && aMax.y >= bMin.y) &&
(aMin.z <= bMax.z && aMax.z >= bMin.z);
}
int AABB::aabbPlane(const Plane &plane) const {
auto r = halfExtents.x * std::abs(plane.n.x) +
halfExtents.y * std::abs(plane.n.y) +
halfExtents.z * std::abs(plane.n.z);
auto dot = Vec3::dot(plane.n, center);
auto r = getHalfExtents().x * std::abs(plane.n.x) +
getHalfExtents().y * std::abs(plane.n.y) +
getHalfExtents().z * std::abs(plane.n.z);
auto dot = Vec3::dot(plane.n, getCenter());
if (dot + r < plane.d) {
return -1;
}
@@ -55,6 +55,10 @@ int AABB::aabbPlane(const Plane &plane) const {
return 1;
}
void AABB::initWithData(uint8_t *data) {
_aabbLayout = reinterpret_cast<AABBLayout *>(data);
}
bool AABB::aabbFrustum(const Frustum &frustum) const {
const auto &planes = frustum.planes;
const auto *self = this;
@@ -65,15 +69,15 @@ bool AABB::aabbFrustum(const Frustum &frustum) const {
}
void AABB::getBoundary(cc::Vec3 *minPos, cc::Vec3 *maxPos) const {
Vec3::subtract(center, halfExtents, minPos);
Vec3::add(center, halfExtents, maxPos);
Vec3::subtract(getCenter(), getHalfExtents(), minPos);
Vec3::add(getCenter(), getHalfExtents(), maxPos);
}
void AABB::merge(const AABB &aabb) {
cc::Vec3 minA = center - halfExtents;
cc::Vec3 minB = aabb.center - aabb.halfExtents;
cc::Vec3 maxA = center + halfExtents;
cc::Vec3 maxB = aabb.center + aabb.halfExtents;
cc::Vec3 minA = getCenter() - getHalfExtents();
cc::Vec3 minB = aabb.getCenter() - aabb.getHalfExtents();
cc::Vec3 maxA = getCenter() + getHalfExtents();
cc::Vec3 maxB = aabb.getCenter() + aabb.getHalfExtents();
cc::Vec3 maxP;
cc::Vec3 minP;
cc::Vec3::max(maxA, maxB, &maxP);
@@ -81,18 +85,19 @@ void AABB::merge(const AABB &aabb) {
cc::Vec3 addP = maxP + minP;
cc::Vec3 subP = maxP - minP;
center = addP * 0.5F;
halfExtents = subP * 0.5F;
setCenter(addP * 0.5F);
setHalfExtents(subP * 0.5F);
}
void AABB::set(const cc::Vec3 &centerVal, const cc::Vec3 &halfExtentVal) {
center = centerVal;
halfExtents = halfExtentVal;
setCenter(centerVal);
setHalfExtents(halfExtentVal);
}
void AABB::transform(const Mat4 &m, AABB *out) const {
out->center.transformMat4(center, m);
transformExtentM4(&out->halfExtents, halfExtents, m);
AABBLayout *layout = out->_aabbLayout;
layout->center.transformMat4(getCenter(), m);
transformExtentM4(&layout->halfExtents, getHalfExtents(), m);
}
void AABB::transformExtentM4(Vec3 *out, const Vec3 &extent, const Mat4 &m4) {
@@ -109,12 +114,16 @@ void AABB::transformExtentM4(Vec3 *out, const Vec3 &extent, const Mat4 &m4) {
out->transformMat3(extent, m3Tmp);
}
AABB::AABB() {
_aabbLayout = &_embedLayout;
}
void AABB::fromPoints(const Vec3 &minPos, const Vec3 &maxPos, AABB *dst) {
Vec3 v3Tmp;
Vec3::add(maxPos, minPos, &v3Tmp);
dst->center.set(v3Tmp * 0.5);
dst->setCenter(v3Tmp * 0.5);
Vec3::subtract(maxPos, minPos, &v3Tmp);
dst->halfExtents.set(v3Tmp * 0.5);
dst->setHalfExtents(v3Tmp * 0.5);
}
} // namespace scene
+32 -11
View File
@@ -34,19 +34,40 @@
namespace cc {
namespace scene {
struct AABB final {
Vec3 center;
Vec3 halfExtents{1, 1, 1};
struct AABBLayout {
cc::Vec3 center;
cc::Vec3 halfExtents{1, 1, 1};
};
class AABB final {
public:
static void fromPoints(const Vec3 &minPos, const Vec3 &maxPos, AABB *dst);
static void transformExtentM4(Vec3 *out, const Vec3 &extent, const Mat4 &m4);
bool aabbAabb(const AABB &aabb) const;
bool aabbFrustum(const Frustum &) const;
int aabbPlane(const Plane &) const;
void getBoundary(cc::Vec3 *minPos, cc::Vec3 *maxPos) const;
void merge(const AABB &aabb);
void set(const cc::Vec3 &centerVal, const cc::Vec3 &halfExtentVal);
void transform(const Mat4 &m, AABB *out) const;
AABB();
AABB(const AABB &) = delete;
AABB(AABB &&) = delete;
~AABB() = default;
AABB &operator=(const AABB &) = delete;
AABB &operator=(AABB &&) = delete;
void initWithData(uint8_t *data);
bool aabbAabb(AABB *aabb) const;
bool aabbFrustum(const Frustum &) const;
int aabbPlane(const Plane &) const;
void getBoundary(cc::Vec3 *minPos, cc::Vec3 *maxPos) const;
void merge(const AABB &aabb);
void set(const cc::Vec3 &centerVal, const cc::Vec3 &halfExtentVal);
void transform(const Mat4 &m, AABB *out) const;
inline void setCenter(float x, float y, float z) { _aabbLayout->center.set(x, y, z); }
inline void setCenter(const Vec3 &center) { _aabbLayout->center.set(center); }
inline const Vec3 &getCenter() const { return _aabbLayout->center; }
inline void setHalfExtents(float x, float y, float z) { _aabbLayout->halfExtents.set(x, y, z); }
inline void setHalfExtents(const Vec3 &halfExtents) { _aabbLayout->halfExtents.set(halfExtents); }
inline const Vec3 &getHalfExtents() const { return _aabbLayout->halfExtents; }
inline AABBLayout *getLayout() { return _aabbLayout; }
private:
AABBLayout _embedLayout;
AABBLayout *_aabbLayout{nullptr};
};
} // namespace scene
-4
View File
@@ -28,10 +28,6 @@
namespace cc {
namespace scene {
Model::~Model() {
delete _worldBounds;
}
void Model::uploadMat4AsVec4x3(const Mat4 &mat, float *v1, float *v2, float *v3) {
uint size = sizeof(float) * 4;
memcpy(v1, mat.m, size);
+4 -7
View File
@@ -56,7 +56,7 @@ public:
Model() = default;
Model(const Model &) = delete;
Model(Model &&) = delete;
virtual ~Model();
virtual ~Model() = default;
Model &operator=(const Model &) = delete;
Model &operator=(Model &&) = delete;
@@ -73,11 +73,8 @@ public:
inline void setReceiveShadow(bool value) { _receiveShadow = value; }
inline void setTransform(Node *node) { _transform = node; }
inline void seVisFlag(uint32_t flags) { _visFlags = flags; }
inline void setWolrdBounds(const AABB &aabb) {
if (!_worldBounds) {
_worldBounds = new AABB();
}
*_worldBounds = aabb;
inline void setBounds(AABB *world) {
_worldBounds = world;
}
inline void setInstancedAttrBlock(uint8_t *buffer, uint32_t size, InstancedAttributeBlock &&block, const std::vector<gfx::Attribute> &attributes) {
_instancedBuffer = {buffer, size};
@@ -102,7 +99,7 @@ public:
inline bool getTransformUpdated() const { return _transformUpdated; }
inline int32_t getUpdatStamp() const { return _updateStamp; }
inline uint32_t getVisFlags() const { return _visFlags; }
inline const AABB * getWorldBounds() const { return _worldBounds; }
inline AABB * getWorldBounds() const { return _worldBounds; }
inline ModelType getType() const { return _type; };
protected:
+1 -1
View File
@@ -111,7 +111,7 @@ void SkinningModel::updateTransform(uint32_t stamp) {
Vec3 v32;
for (JointInfo& jointInfo : _joints) {
updateWorldMatrix(&jointInfo, stamp);
jointInfo.bound.transform(_worldMatrix, &ab1);
jointInfo.bound->transform(_worldMatrix, &ab1);
ab1.getBoundary(&v31, &v32);
Vec3::min(v3Min, v31, &v3Min);
Vec3::max(v3Max, v32, &v3Max);
+1 -1
View File
@@ -43,7 +43,7 @@ struct JointTransform {
};
struct JointInfo {
AABB bound;
AABB * bound{nullptr};
Node * target{nullptr};
Mat4 bindpose;
JointTransform transform;
+1 -1
View File
@@ -32,7 +32,7 @@ void SphereLight::update() {
if (_node && (_node->getFlagsChanged() || _needUpdate)) {
_node->updateWorldTransform();
_pos = _node->getWorldPosition();
_aabb.set(_pos, {_range, _range, _range});
_aabb->set(_pos, {_range, _range, _range});
_needUpdate = false;
}
}
+3 -3
View File
@@ -43,7 +43,7 @@ public:
void update() override;
inline void setAABB(AABB aabb) { _aabb = std::move(aabb); }
inline void setAABB(AABB *aabb) { _aabb = aabb; }
inline void setIlluminance(float illum) { _illuminance = illum; }
inline void setPosition(const Vec3 &pos) { _pos = pos; }
inline void setRange(float range) {
@@ -52,7 +52,7 @@ public:
}
inline void setSize(float size) { _size = size; }
inline const AABB &getAABB() const { return _aabb; }
inline AABB * getAABB() const { return _aabb; }
inline float getIlluminance() const { return _illuminance; }
inline const Vec3 &getPosition() const { return _pos; }
inline float getRange() const { return _range; }
@@ -64,7 +64,7 @@ private:
float _range{0.F};
float _size{0.F};
Vec3 _pos;
AABB _aabb;
AABB *_aabb{nullptr};
};
} // namespace scene
+1 -1
View File
@@ -38,7 +38,7 @@ void SpotLight::update() {
_dir = _forward;
_dir.transformQuat(_node->getWorldRotation());
_dir.normalize();
_aabb.set(_pos, {_range, _range, _range});
_aabb->set(_pos, {_range, _range, _range});
matView = _node->getWorldRTMatrix();
matView.inverse();
+3 -3
View File
@@ -43,7 +43,7 @@ public:
void update() override;
inline void setAABB(AABB aabb) { _aabb = std::move(aabb); }
inline void setAABB(AABB *aabb) { _aabb = aabb; }
inline void setAngle(float angle) {
_spotAngle = angle;
_angle = acos(_spotAngle) * 2;
@@ -64,7 +64,7 @@ public:
inline void setPosition(const Vec3 &pos) { _pos = pos; }
inline void setSize(float size) { _size = size; }
inline const AABB & getAABB() const { return _aabb; }
inline AABB * getAABB() const { return _aabb; }
inline float getAngle() const { return _angle; }
inline float getSpotAngle() const { return _spotAngle; }
inline float getAspect() const { return _aspect; }
@@ -86,7 +86,7 @@ private:
float _aspect{0.F};
Vec3 _dir;
Vec3 _pos;
AABB _aabb;
AABB * _aabb{nullptr};
Frustum _frustum;
};
+2 -2
View File
@@ -40,7 +40,7 @@ classes = Light Node DirectionalLight SpotLight SphereLight Model SubModel Pass
# add a single "*" as functions. See bellow for several examples. A special class name is "*", which
# will apply to all class names. This is a convenience wildcard to be able to skip similar named
# functions from all classes.
skip = Model::[setInstancedAttrBlock getType getLocalBuffer],
skip = Model::[setInstancedAttrBlock getType getLocalBuffer getModelBounds getWorldBounds],
SubModel::[getDescriptorSet getInputAssembler getSubMesh setSubMeshBuffers],
Light::[getColor getColorTemperatureRGB getNode getType getUseColorTemperature],
Node::[getFlagsChanged getLayer getWorldMatrix getWorldPosition getWorldRotation getWorldScale initWithData setFlagsChanged setDirtyFlag setLayer setWorldMatrix setWorldPosition setWorldRotation setWorldScale setLocalPosition setLocalRotation setLocalScale getNodeLayout getWorldRT updateWorldTransform updateWorldRTMatrix getDirtyFlag getPosition getScale getRotation getParent],
@@ -48,7 +48,7 @@ skip = Model::[setInstancedAttrBlock getType getLocalBuffer],
SpotLight::[getAABB getAngle getAspect getSpotAngle getDirection getFrustum getIlluminance getNeedUpdate getRange getPosition getSize],
SphereLight::[getAABB getIlluminance getPosition getRange getSize],
Pass::[initWithData setRootBufferAndBlock],
AABB::[getBoundary aabbAabb aabbFrustum aabbPlan merge transform transformExtentM4],
AABB::[getBoundary aabbAabb aabbFrustum aabbPlan merge transform transformExtentM4 setCenter getCenter setHalfExtents getHalfExtents set fromPoints],
SkinningModel::[updateTransform updateUBOs uploadJointData updateWorldMatrix],
Frustum::[update type],
JointTransform::[node world local stamp],