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

get coordinates from the .obj #12

Open
ggichure opened this issue Dec 27, 2019 · 8 comments
Open

get coordinates from the .obj #12

ggichure opened this issue Dec 27, 2019 · 8 comments

Comments

@ggichure
Copy link

is there a way i can get coordinates of a click point from the 3d object

@klaszlo8207
Copy link

Yes it is not so hard. U can wrap to a gesturedetector, and on x and y coordinates u just run your method on the mesh vertices. When the click x y pos is near on a coordinate u can set it to a list. After u just select the one whats z coordinate is the nearest to the camera. Thats all

@ggichure
Copy link
Author

ggichure commented Jan 6, 2020

@klaszlo8207 I'm not that familiar with gesture detector. An example would be great.Thanks

@klaszlo8207
Copy link

klaszlo8207 commented Jan 6, 2020

return new GestureDetector(
      onTapDown: (TapDownDetails details) => onTapDown(context, details),
      child: new Stack(fit: StackFit.expand, children: <Widget>[
        new Container(color: Colors.white),
        new Positioned(
          child: new Text('hello'),
          left: posx,
          top: posy,
        )
      ]),
    );
void onTapDown(BuildContext context, TapDownDetails details) {
    print('${details.globalPosition}');
    final RenderBox box = context.findRenderObject();
    final Offset localOffset = box.globalToLocal(details.globalPosition);
    setState(() {
      posx = localOffset.dx;
      posy = localOffset.dy;
    });
  }

here

@ggichure
Copy link
Author

ggichure commented Jan 7, 2020

@klaszlo8207 works great

return new GestureDetector(
      onTapDown: (TapDownDetails details) => onTapDown(context, details),
      child: new Stack(fit: StackFit.expand, children: <Widget>[
        new Container(color: Colors.white),
        new Positioned(
          child: new Text('hello'),
          left: posx,
          top: posy,
        )
      ]),
    );
void onTapDown(BuildContext context, TapDownDetails details) {
    print('${details.globalPosition}');
    final RenderBox box = context.findRenderObject();
    final Offset localOffset = box.globalToLocal(details.globalPosition);
    setState(() {
      posx = localOffset.dx;
      posy = localOffset.dy;
    });
  }

here

@klaszlo8207 works perfectly.assuming one had predetermined points how would one go about it .Thanks.

@klaszlo8207
Copy link

Sorry I dont understand what you wrote. What do u want?

@ggichure
Copy link
Author

ggichure commented Jan 7, 2020

I have an obj file i have all the vertices coordinates in xyz ...
example points
v 0.822220 0.216242 -0.025730 v -0.822220 0.216242 -0.025730 v 0.811726 0.220845 0.029668 v -0.811726 0.220845 0.029668 v 0.777874 0.214472 0.075458 v -0.777874 0.214472 0.075458 v 0.724172 0.189587 0.073470 v -0.724172 0.189587 0.073470 v 0.704111 0.180226 0.027508

how would i go about selecting say a point v -0.777874 0.214472 0.075458. in 2d

@klaszlo8207
Copy link

klaszlo8207 commented Jan 7, 2020

v 0.822220 0.216242 -0.025730 this is a vertex (Vect3) have x,y,z value
x: 0.822220
y: 0.216242

but when You draw the triangle on a 2D surface it has a value like: 200, 250 (x, y)

so First you want to those vertices convert to 2d ints (in this library you can see how the programmer do that)

create a new List and XYZ values that is int

After you have the gesturedetector touched point, you just loop throug on that list and lets say you select the first one that is nearest to the camera (Z), and nearest to that XY touched value (lets say distance is 5)

@ggichure
Copy link
Author

ggichure commented Jan 9, 2020

@klaszlo8207 i have been trying to wrap my head about converting the points to 2d and ended up confused.an example would be really helpful.thanks. I'm trying to get a point in a 3d obj and place a Container(color:Colors.red) on the position.

Assuming i have a 3d car object I want to be able to select the door and move the select container to other parts within the door.
Thanks

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

No branches or pull requests

2 participants