Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collada model picking? #255

Closed
gerardogc2378 opened this issue Jun 20, 2016 · 11 comments
Closed

Collada model picking? #255

gerardogc2378 opened this issue Jun 20, 2016 · 11 comments
Labels

Comments

@gerardogc2378
Copy link

Hi, reading much of minko code I found picking example to pick only primitive shapes like cube and spheres, what about collada model picking? How to do picking with collada 3d models?

@warrenseine
Copy link
Contributor

It's exactly the same. Just place your model's root node in the PICKING layout. Then catch it with the mouseClick signal.

@gerardogc2378
Copy link
Author

gerardogc2378 commented Jun 20, 2016

Hi @warrenseine, I have this simple code:

auto daeModel = sceneManager->assets()->symbol(DAE_MODEL);
daeModel->layout(scene::BuiltinLayout::DEFAULT | scene::BuiltinLayout::PICKING);
root->addChild(daeModel);

root->addComponent(Picking::create(camera, false, true));
pickingMouseClick = root->component<Picking>()->mouseClick()->connect([=](scene::Node::Ptr node)
{                                                                         
    std::cout << "Mouse Click: " << node->name() << std::endl;
}

Clicking it's not working...

@warrenseine
Copy link
Contributor

Sounds like the right way to do it. Does it work in your code if you replace the Collada model by a simple native shape?

@warrenseine warrenseine reopened this Jun 20, 2016
@gerardogc2378
Copy link
Author

gerardogc2378 commented Jun 20, 2016

Yes working with simple native shapes on branch master

auto ground = scene::Node::create("ground")                               
        ->addComponent(Surface::create(                                         
            geometry::QuadGeometry::create(sceneManager->assets()->context()),  
            material::BasicMaterial::create()->diffuseColor(vec4(1.f, .5f, .5f, 1.f)),
            sceneManager->assets()->effect("effect/Phong.effect")))             
        ->addComponent(Transform::create(scale(vec3(4.f)) * rotate(static_cast<float>(-M_PI_2), vec3(1.f, 0.f, 0.f))))
        ->layout(scene::BuiltinLayout::DEFAULT | scene::BuiltinLayout::PICKING) 
      ;                                                                         
      root->addChild(ground);

@JMLX42
Copy link
Member

JMLX42 commented Jun 21, 2016

auto daeModel = sceneManager->assets()->symbol(DAE_MODEL);
daeModel->layout(scene::BuiltinLayout::DEFAULT | scene::BuiltinLayout::PICKING);

Picking is done using a GPU picking map rendered by a Renderer working on all the Surface components that are in the scene::BuiltinLayout::PICKING layout. So I think you need to add the meshes to the scene::BuiltinLayout::PICKING layout, not just the root of the model.

You can define your own file::Options::nodeFunction that will be called on all node upon loading to make sure the relevant ones are in the right layout:

fileOptions->nodeFunction([](scene::Node::Ptr n)
{
  if (n->hasComponent<component::Surface>())
    n->layout(n->layout() | scene::BuiltinLayout::PICKING);
}
// load the dae with those options

@gerardogc2378
Copy link
Author

Thanks @promethe42 I will try this code and comment later.

@gerardogc2378
Copy link
Author

gerardogc2378 commented Jul 9, 2016

Hi @promethe42 , I have another question, is there a way in minko to set a collision shape like this and make it touchable?

screenshot from 2016-07-08 21-56-20

@JMLX42
Copy link
Member

JMLX42 commented Jul 9, 2016

There are many things on that picture... what's supposed to be the collision shape?
By "touchable", do you mean clickable with the touchscreen?

@gerardogc2378
Copy link
Author

Hi @promethe42 again, collision shape is the blue-light cube, Of course touchable is clickable :-)

@JMLX42
Copy link
Member

JMLX42 commented Jul 10, 2016

Just add the picking component to that shape. What's stopping you?

@gerardogc2378
Copy link
Author

Hi @promethe42 thanks again for your support. One and mainly is my spare time to learn minko (minko is awesome technology) but I have had progress step by step :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants