Color individual faces on click tool

Have jReality programming problems or questions? Post them here.
Post Reply
fausto
Posts: 5
Joined: Sun 12. Apr 2015, 21:30

Color individual faces on click tool

Post by fausto » Sun 24. Jan 2016, 06:05

Hi

I want to implement a custom tool that lets the user click on individual faces of a polygon and when that happens the clicked face changes its color.

I have done some research on the available tools in jReality and one that could help me achieve what I want is the FaceDragEvent. There you can attach a FaceDragListener that handles the event of actual face dragging, which gives you access to the face's vertices and coordinates via the FaceDragEvent object (as seen in the http://www3.math.tu-berlin.de/jreality/ ... gEventTool tutorial).
For example, in the class de.jreality.tutorial.tool.DragEventTool02 you have this code:

Code: Select all

                      
public void faceDragStart(FaceDragEvent e) {
	faceSet = e.getIndexedFaceSet();
	points=new double[faceSet.getNumPoints()][];
	points = faceSet.getVertexAttributes(Attribute.COORDINATES).toDoubleArrayArray(null);
}
My idea is to develop something similar: Create a FaceClickedEvent and a FaceClickedListener that gives you access to the clicked face so you can change it's color. I want a similar method that gets the face color, something like this:

Code: Select all

                      
public void faceClickedStart(FaceClickedEvent e) {
	faceSet = e.getIndexedFaceSet();
	Color[] colors = faceSet.getFaceAttributes(Attribute.COLORS); // But at runtime this returns null!
}
Any idea on what existing classes in jReality I could use to develop this tool? How can I dinamically change a face color after the clicked event?

Thanks so much!

MarcelP
Posts: 15
Joined: Mon 15. Dec 2014, 12:20

Re: Color individual faces on click tool

Post by MarcelP » Wed 9. Mar 2016, 20:00

That is a good idea. I would use the DragStart and DragEnd to implement this.

Try this:

+++At dragStart store the time with ct = System.currentTimeMillis
+++in dragged wrap the code in an if(System.currentTimeMillis - ct) > treshhold){ run the drag code}
+++at dragEnd check if if(System.currentTimeMillis - ct) < treshhold) { run the click code } else { run endDrag code}.

to dynamically change a face color after a click you need to somehow mark the clicked faces maybe with a list to then make the drag code dependable on the presence of the face in the list.

hope it helps. I would be eager to know how that worked out.

sorry for the late reply

Post Reply