Coder Social home page Coder Social logo

Explore rotate operation about mcthings HOT 30 CLOSED

voxelers avatar voxelers commented on May 25, 2024
Explore rotate operation

from mcthings.

Comments (30)

acs avatar acs commented on May 25, 2024

I want to rotate the Schematics. For example, in https://github.com/juntosdesdecasa/mcthings/blob/develop/scenes/scene0_20.ipynb the entry door for "schematics/chateau-fairmont.schematic" is at the back of the castle!

from mcthings.

acs avatar acs commented on May 25, 2024

Ok, let's start with this one. I have thought about its implementation and my plan is to rotate things in x,z (y is the height). The rotation will be based on a central column which won't rotate. The thing will be seem as lines that goes from this central column to the border of the Thing. And the idea is to rotate those lines.Let's see how far we go with this approach.

In my first step my idea is to rotate a two joined blocks Thing. The evolution could be something like:

--
 **
--
 *
  *
--
 *
 *
--
 *
*
--
**
--
*
 *
--
 *
 *
--
  *
 *
--
 **
--

8 different positions (the last one is the same than the first one): 0, 45. 90, 135, 180, 225, 270, 315, 360 (== 0).

Let's play with that and then we can add 3 blocks. And after that, use a two height cuboid with different materials in the blocks to see that it is rotated correctly.

from mcthings.

acs avatar acs commented on May 25, 2024

After playing a bit, the idea with the lines is clear. Remove the current line and create a new one with the same start point (the center of the rotation) and with a new end point (which depends in the rotation). So we need to implement a new Line Thing which joins two points. And after that, we just need to compute the end point for each rotation. Easy? Probably not, but it is getting clearer.

from mcthings.

acs avatar acs commented on May 25, 2024

Drawing a line is already support by https://github.com/martinohanlon/minecraft-stuff/blob/master/minecraftstuff/minecraftstuff.py#L159 so probably we can just reuse it.

from mcthings.

acs avatar acs commented on May 25, 2024

I am not sure we can rotate using lines. Maybe we need to do it block by block. Apply a common transformation to move the position of a block depending on the rotation. But, is there a function to compute the new position for any block depending on the rotation?

Probably it depends on the degrees to rotate and also, on the radius from the rotation in which the block is positioned.

from mcthings.

acs avatar acs commented on May 25, 2024

Ok, there are some references that can be useful to check we are going in the right way: https://www.khanacademy.org/computing/computer-programming/programming-games-visualizations/programming-3d-shapes/a/rotating-3d-shapes

x′=x*cos(β)−z*sin(β)
z′=z*cos(β)+x*sin(β)

But we are working with blocks! But it must be valid in this case also. β must be in radians.

math.degrees(x)
    Convert angle x from radians to degrees.
math.radians(x)
    Convert angle x from degrees to radians.

from mcthings.

acs avatar acs commented on May 25, 2024

We need to define also with respect to which we are rotating. To the center of the Thing? To one of the corners? Let's try to cover the simplest case first.

from mcthings.

acs avatar acs commented on May 25, 2024

So let's focus in rotating 45ºC:

>>> math.sin(math.radians(45))
0.7071067811865475
>>> math.cos(math.radians(45))
0.7071067811865476

Let's use 0.71 for both. In our simple two blocks like in positions (x,z): (0,0), (1,0). The result is:

x' = x * 0.71 - z * 0.71
z' = z * 0.71 + x * 0.71

  • First block: (0, 0)
  • Second block: (0.71, 1.42) which rounding is (1, 1). Which is the right position. Let's play a bit to see what Minecraft do when we position things using decimals. Probably it does the rounding to a concrete tile.

from mcthings.

acs avatar acs commented on May 25, 2024

Ok, we have a first version that would work in a float world. But with integers and blocks ... let's see how far we can go!

from mcthings.

acs avatar acs commented on May 25, 2024

Using a 5 blocks like, when it is rotated 45 degrees one block is lost because the rounded position is the same than a previous one. So we need to review the process. Probably inspired in the real solution with floats, but fixing it for our blocks case.

The plan is to implement the rotation for 90 degress. In this case we can support 90, 90+90 and 90+90+90 rotations. And if we implement it, the let's try the 45 degrees step!

from mcthings.

acs avatar acs commented on May 25, 2024

The 90ºC rotations works mostly:

Screenshot from 2020-06-03 22-19-22

from mcthings.

acs avatar acs commented on May 25, 2024

Good feelings with the 90 rotation. We need to fix this bug that make some blocks disappear in the up border of the rotated figure, but it the same bug always (the width of the cuboid rotated), so probably we can find a common solution.

Let's play a with the a Schematic to check the results.

Screenshot from 2020-06-03 22-30-27

from mcthings.

acs avatar acs commented on May 25, 2024

Great results, the process is slow, but for example, if we need a rotated schematics for an scene, we can generate it, save it to a new schematic, and then use the rotated schematic. The possibilities are huge.

Screenshot from 2020-06-03 22-41-19

from mcthings.

acs avatar acs commented on May 25, 2024

And as expected, the 90, 180 and 270 rotations works nicely!

Screenshot from 2020-06-03 22-50-32

from mcthings.

acs avatar acs commented on May 25, 2024

The next step is to fix tthe bug found and we have it. Let's do a quick test with Zanabot.

from mcthings.

acs avatar acs commented on May 25, 2024

Zanabot being reconstructed with in its rotated version and it final version:

Screenshot from 2020-06-03 22-56-21

Screenshot from 2020-06-03 22-57-16

from mcthings.

acs avatar acs commented on May 25, 2024

In order to improve the performance, probably the approach is to do the full rotation process in memory, and once it has finished, draw the results.

from mcthings.

acs avatar acs commented on May 25, 2024

Next steps:

  • Fix bug
  • Improve peformance
  • Create the scene with the castle in the right position: the main entry in the side of the town.

from mcthings.

acs avatar acs commented on May 25, 2024

Bug fixed:

Screenshot from 2020-06-04 05-36-50

And also now the performace is much better (get all blocks in one call, clean all blocks in one call, rotate each block one by one).

from mcthings.

acs avatar acs commented on May 25, 2024

Bug fixed and now the performance for rotating a Schematic is the same than loading it.

Screenshot from 2020-06-04 05-50-19

from mcthings.

acs avatar acs commented on May 25, 2024

Last steps:

  • Check that the rotation is 90, 180 or 270 ok
  • Update the bouding box ok
  • Create the scene with the castle in the right position: the main entry in the side of the town ok
  • Create an animation with rotation ok (done in the animation plugin)
  • Create a new version, video for it and dissemination

from mcthings.

acs avatar acs commented on May 25, 2024

Let's finish this issue!

Also another performance idea:

  • If a Thing is not build already, you can build it rotated directly? You could build it in memory (without showing it) and rotate from data in memory. With that, we avoid one build of the things, important if it is large, and also, because we don't need to remove it. so we avoid two expensive operations and we go directly to showing the rotated version.

  • In Schematics it is pretty relevant. If we start using rotations in Schematics intensively, we must improve it in this way. But something to be done in the future. DONE

from mcthings.

acs avatar acs commented on May 25, 2024

It is going to be nice to rotate a Thing 180ºC and leave it in the same position than the original one. This is the requirement for our Scene 0.41.0! First try:

Screenshot from 2020-06-05 17-11-55

The castle is moved because of the rotation over the rest of the scene!!! So the issues we have:

  • The rotation losses the data from the blocks, so we are loosing colors (like the ones in the flags).
  • The removal of the castle leaves trash: this is because the reaming blocks are like the sand, they go down if the supporting box is removed. So when you try to remove them, they have moved. In this case, it is easier to just remove the cuboid for the castle.
  • The final position of the castle is over our scene. Why? Let' s draw it:
FFFFFFF 
BBBBBBB BBBBBBB
        FFFFFFF

So let's work step by step in fixing this issues if possible. At least, let's fix the position one. The fix is to create the castle having in mind the rotation. So the position for the castle must be:

pos.x = pos.x - castle.width
pos.z = pos.z - castle.length

Let's play with that!

from mcthings.

acs avatar acs commented on May 25, 2024

Implemented the rotation in memory for Schematics. During the testing, a nice finding:

Screenshot from 2020-06-05 18-24-51

from mcthings.

acs avatar acs commented on May 25, 2024

Yes, the entry to the castle is now pretty close to the sphere

Screenshot from 2020-06-05 18-59-10

from mcthings.

acs avatar acs commented on May 25, 2024

All done for the scene with the castle 180 rotated, and including the correct data for all the blocks! The best scenario :)

0 42 0

from mcthings.

acs avatar acs commented on May 25, 2024
  • Create a new version, video for it and dissemination

We have the 0.42.0 version. Now it is time to show in screenshots (the circle of boats) and with a video this new cool feature!

from mcthings.

acs avatar acs commented on May 25, 2024

https://twitter.com/acstw/status/1269042569683533833

All done! Closing!

from mcthings.

acs avatar acs commented on May 25, 2024

MCEdit 2.0 has a free rotation feature:

https://www.youtube.com/watch?v=FgaxGaTm_NY

In WorldEdit they support the 90, 180, 270 approach:

https://www.google.com/search?channel=crow2&client=firefox-b-d&q=worldedit+rotation#kpvalbx=_2SDbXoHELbvCgwfy3JS4Aw33

No it can do also free rotating:

https://www.youtube.com/watch?v=XYlg3vAjzLc

So in the future we should add this free rotating feature to McThings!

from mcthings.

acs avatar acs commented on May 25, 2024

https://minecraft.gamepedia.com/Structure_Block

Rotation (0, 90, 180, 270)
Sets the rotation of the structure to 0° (no rotation), 90° clockwise, 180° clockwise, and 270° clockwise (or 90° counter-clockwise).

from mcthings.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.