Nibba2018's Blog

Weekly Check-in #6

Nibba2018
Published: 07/05/2020

Translation, Reposition, Rotation.

Hello and welcome to my 6th weekly check-in. The first evaluation period officially ends and I am very excited to move on to the second coding period. I will be sharing my progress with handling specific object's properties among various multiple objects rendered by a single actor. I am mainly focusing on making it easier to translate, rotate and reposition a particular object, so that I can use them to render physics simulations more efficiently. The official repository of my sub-org, FURY can always be found here.

What did you do this week?

Last week I worked on physics simulations rendered in FURY with the help of pyBullet. Now the simulations were highly un-optimized, specially the brick wall simulation as each brick was rendered by its own actor. In other words, 1 brick = 1 actor. Now my objective was to render all the bricks using a single actor, but before jumping into the simulation I had to figure out how to modify specific properties of an individual object. Thanks to my mentor's PR, I was able to experiment my implementations quickly.

Translation:

The algorithm behind translation is to first identify the vertices of the object, then bring the vertices to the origin by subtracting their centers and then adding the displacement vector. The said operation can be achieved by the following snippet:

# Update vertices positions
vertices[object_index * sec: object_index * sec + sec] = \
    (vertices[object_index * sec: object_index * sec + sec] -
     centers[object_index]) + transln_vector

Rotation:

The algorithm behind rotation is to first calculate the difference between the vertices and the center of the object. Once we get the resultant matrix, we matrix multiply it with the rotation matrix and then we further add the centers back to it so that we preserve the position of the object. Rotation matrix can be defined as:

where gamma, beta and alpha corresponds to the angle of rotation along Z-axis, Y-axis and X-axis.

def get_R(gamma, beta, alpha):
    """ Returns rotational matrix.
    """
    r = [
        [np.cos(alpha)*np.cos(beta), np.cos(alpha)*np.sin(beta)*np.sin(gamma) - np.sin(alpha)*np.cos(gamma),
        np.cos(alpha)*np.sin(beta)*np.cos(gamma) + np.sin(alpha)*np.sin(gamma)],
        [np.sin(alpha)*np.cos(beta), np.sin(alpha)*np.sin(beta)*np.sin(gamma) + np.cos(alpha)*np.cos(gamma),
        np.sin(alpha)*np.sin(beta)*np.cos(gamma) - np.cos(alpha)*np.sin(gamma)],
        [-np.sin(beta), np.cos(beta)*np.sin(gamma), np.cos(beta)*np.cos(gamma)]
    ]
    r = np.array(r)
    return r

vertices[object_index * sec: object_index * sec + sec] = \
    (vertices[object_index * sec: object_index * sec + sec] -
     centers[object_index])@get_R(0, np.pi/4, np.pi/4) + centers[object_index]

Reposition:

Repositioning is similar to that of translation, except in this case, while repositioning we update centers with the new position value.

new_pos = np.array([1, 2, 3])

# Update vertices positions
vertices[object_index * sec: object_index * sec + sec] = \
    (vertices[object_index * sec: object_index * sec + sec] -
     centers[object_index]) + new_pos

centers[object_index] = new_pos

What is coming up next?

Currently, I am yet to figure out the orientation problem. Once I figure that out I will be ready to implement simulations without any major issues. I am also tasked with creating a wrecking ball simulation and a quadruped robot simulation.

Did you get stuck anywhere?

I did face some problems while rotating objects. My mentors suggested me to implement it via rotation matrix. I still haven't figured out the orientation problem, which I plan to work on next. Apart from these I did not face any major issues.

Thank you for reading, see you next week!!
View Blog Post

Weekly Check-in #5

Nibba2018
Published: 06/28/2020

May the Force be with you!!

Hello and welcome to my 5th weekly check-in, I will be sharing my progress of pyBullet Physics Engine Integration with FURY. The official repository of my sub-org, FURY can always be found here.

What did you do this week?

Last week due to the vtkTextActor sizing issue I was not able to continue my work with ComboBox2D UI element. Thus, I decided to work on the "Physics Engine Integration" part of my project. It took me quite a while to understand the terminology of various methods and algorithms used for detection and physics simulation. Nevertheless, I was able to create a couple of rigid body examples to showcase the integration procedure. For physics calculations we used pyBullet and for rendering we used FURY. In other words, pyBullet will handle the backend part of the simulation and FURY will handle the frontend. I have documented the entire integration process here in detail.

Ball Collision Simulation:

For the first example, I created a simple collision between two balls in which two spheres were created both in FURY and pyBullet world and then both the worlds are connected by syncing the position and orientation of the said bodies. Timer callback is created to update the positions and to simulate Physics for each step.

Brick Wall Simulation:

For the second example I tried to increase the complexity of the simulations by increasing the number of dynamic objects. Here a brick-wall is created using 100 bricks and then a ball is thrown at it. The rest of it is simulated. The same concepts from the first example is used to render the second one. Timer callback is created to update position of all the objects and to simulate Physics for each step.

What is coming up next?

In the above examples I used a separate actor for each object which is highly un-optimized. Thus, my mentor suggested me to render all the bricks using a single actor, so that the simulation is more optimized. I am not very confident in changing the position and orientation of different objects rendered by a single actor. Therefore, I will have to research a bit more about it. Apart from that I will also try to work on Constraint based simulation examples if possible.

Did you get stuck anywhere?

The pyBullet documentation isn't well written for cross rendering, hence it was a bit of a challenge for me to implement the integration. I also faced a problem regarding the offset of actors between the FURY world and pyBullet world. Both use different coordinate systems for rendering and simulation because of which I had a constant offset between the objects during simulations. I was able to fix it by converting one coordinate system to the other. Apart from this I did not have any major issues.

Thank you for reading, see you next week!!
View Blog Post

Weekly Check-in #4

Nibba2018
Published: 06/21/2020

TextBlock2D Progress!!

Hello and welcome to my 4th weekly check-in, I will be sharing my progress with TextBlock2D UI component. The official repository of my sub-org, FURY can always be found here.

What did you do this week?

This week my objective was to work on the TextBlock2D resizing feature and also work on the scrollbar bug in ComboBox2D UI component. The TextBlock2D component makes use of vtkTextActor and its methods available in VTK for handling all Text related properties such as font size, color, background color etc. Now, going through the official docs I figured out that the there were three different scaling modes for the said actor:

  • TEXT_SCALE_MODE_NONE
  • TEXT_SCALE_MODE_PROP
  • TEXT_SCALE_MODE_VIEWPORT

The first scaling mode was currently implemented in FURY's TextBlock2D code base. This was done mainly because the only way for the user to create a text block was by providing the font size as parameter. We couldn't use the third option as the FURY API tries to maintain abstraction by not exposing vtkViewport parameter. Now in order to allow size as a parameter I had to use the second scaling option which is TEXT_SCALE_MODE_PROP. With  this mode one can set the Position2 parameter to the desired value of height and width. But the problem is I cannot use this for the combobox element as the background size will be inconsistent with respect to font size and text length.

Therefore, as a solution we agreed to add a separate Rectangle2D UI component as the background for Text Block along with vtkTextActor. With this implementation one can easily manipulate the background irrespective of the text properties. But this had another issue, the user now had 2 different ways of initializing a TextBlock2D. Therefore, when the user uses size a constructor parameter, then everything works in sync, but the same is not true for the font size parameter. This is mainly because we do not have a specific way of determining the size of the actor based on font size. My mentors have agreed to look into this problem and advised me to focus on something else instead.

What is coming up next week?

Next week I am planning to start with Physics engine integration of FURY with pyBullet. My main focus would be to create simple simulations first before initiating the integration process. If the size issue is solved before I move into Physics engine then I would complete the ComboBox UI and start with Tab UI instead. I have also fixed the scrollbar bug.

Did you get Stuck anywhere?

The main problem that I faced so far was regarding the variable background size of the Text Block component. Also the GetPosition2 method of vtkTextActor would always return the same value irrespective of the font size parameter passed as a constructor argument. Therefore, it was not possible for me to determine the actual size or bounding box of the said text actor.

Thank you for reading, see you next week!!
View Blog Post

Weekly Check-in #3

Nibba2018
Published: 06/14/2020

ComboBox2D Progress!!

Hello and welcome to my third weekly check-in, I will be sharing my progress with the project so far. In case you wondered, the sub-org that I am affiliated to is FURY. Make sure to check out the official repository here.

What did you do this week?

This week my objective was to work on the sizing and positioning issue regarding the sub-components of the ComboBox2D UI element. After countless debugging sessions and my mentor's support, I was successfully able to fix the issue. I also developed helpful methods and callbacks for this element to allow users to interact with them in a user friendly manner. I also wrote tests for the same. So far the said progress can be summarized via this gif:

ComboBox UI gif

What is coming up next week?

Unfortunately, one of the sub-components TextBlock2D, didn't have a resizing feature that I could make use of for this new UI component. Thus, I need to add that feature on a different PR. This feature will also be required while building other UI elements therefore adding this feature is currently my top priority. There's also a bug regarding the scrollbar that needs to be fixed. The scrollbar overshoots the specified combobox area after new items are appended to the combobox's list of items during runtime. Hopefully I will be able to get them done by next week.

Did you get stuck anywhere?

I was really confused with the coordinate system of Panel2D that was the main reason why components were misplaced. I also faced some issues regarding the scrollbar callback as it wasn't scrolling the elements properly, the items were stuck in place. So far I was able to fix them. Apart from these, I didn't face any major issues.

Thank you for reading, see you next week!!
View Blog Post

Weekly Check-in #2

Nibba2018
Published: 06/07/2020

First week of coding!!

Hello and welcome to my second weekly check-in, I will be sharing my progress for the first week of coding.

What did you do this week?

This week my objective was to create the skeleton model for ComboBox2D UI element along with its required sub-components and their respective default callbacks. So far, I have successfully been able to implement them. Apart from some issues that I was facing regarding the sizing and position of the sub-components.

What is coming up next week?

Next week, my main focus will be on fixing the sizing issue and I will also be working on respective default and specialized class methods required by the component and its sub-components for proper functioning. I will also create tests for the same.

Did you get stuck anywhere?

The main problem that I faced while coding the UI element was regarding the sizing and positioning of the sub-components. The sub-components appeared flipped and the TextBlock2D element had no option to resize based on a particular width & height definition.

combobox image

As you can see, the ComboBox UI element doesn't look the way its supposed to. Along with this issue the scrollbars callback doesn't work either. Hopefully, I will be able to get these issues fixed by next week.

Thank you for reading, see you next week!!
View Blog Post