Ejemplo n.º 1
0
void
POPGeometryWriterPreprocessor::process(Node::Ptr& node, AssetLibrary::Ptr assetLibrary)
{
    // TODO
    // introduce heuristics based on scene layout
    // * find object instances within scene hierarchy
    //   to dispatch lod scheduling components at correspondings object roots, used as
    //   scene object descriptors specifying type of technique to apply

    // by default whole scene is streamed as a progressive ordered mesh

    if (!node->hasComponent<POPGeometryLodScheduler>())
        node->addComponent(POPGeometryLodScheduler::create());

    auto animatedNodes = collectAnimatedNodes(node);

    markPOPGeometries(node, animatedNodes);
}
Ejemplo n.º 2
0
void
bullet::Collider::initializeFromNode(Node::Ptr node)
{
    if (_graphicsTransform != nullptr && _physicsWorld != nullptr)
        return;

    _physicsTransform->identity(); // matrix automatically updated by physicsWorldTransformChangedHandler

    // get existing transform component or create one if necessary
    if (!node->hasComponent<Transform>())
        node->addComponent(Transform::create());

    _graphicsTransform = node->component<Transform>();

    if (fabsf(_graphicsTransform->modelToWorldMatrix(true)->determinant()) < 1e-4f)
        throw std::logic_error("The node's model-to-world matrix cannot be inverted.");

    // identify physics world
    auto withPhysicsWorld = NodeSet::create(node)
                            ->ancestors(true)
    ->where([](Node::Ptr n) {
        return n->hasComponent<bullet::PhysicsWorld>();
    });

    if (withPhysicsWorld->nodes().size() > 1)
        throw std::logic_error("Scene cannot contain more than one PhysicsWorld component.");

    _physicsWorld = withPhysicsWorld->nodes().empty()
                    ? nullptr
                    : withPhysicsWorld->nodes().front()->component<bullet::PhysicsWorld>();

    if (_physicsWorld)
        _physicsWorld->addChild(std::static_pointer_cast<Collider>(shared_from_this()));

    synchronizePhysicsWithGraphics();
}