Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

three.js - Duplicate rotation from pattern of blocks in threejs

Let me give you some context: I'm creating a block puzzling vr game. https://twitter.com/CROEWENS/status/1344701671599988738

example picture

I'll be using the following naming for the picture above:
orange => groups (which are grabbable by the player)
green => blocks (combination of these makes a group)
in the middle of the picture => build (puzzle you need to solve by dragging the items in there)

The locking of groups in the build gets done by checking the worldPosition of the blocks of the group. In the build, I check all available positions and check if they're close enough for each other to "lock". If they're close enough, I preview the blocks that will be locked in the build.

Here is the problem. The block that I'm holding and the preview in the build, exist of blocks which have a worldPosition, but no combined rotation. In the past, for the demo and up until recently, I just looped over the children of the group I'm currently holding, and set them to the locked positions. But now I want to rotate the block I'm holding to the "rotation" of the locked blocks.

I've tried some stuff, but to no avail and setup the following test environment: https://codesandbox.io/s/r3f-orbit-controls-forked-hfev5?file=/src/index.js

Picture of the codesandbox: enter image description here

In the example, I have 3 groups of blocks. group 1, is the initial group of blocks. group 2 is a rotated version of group 1 and group 3 is an test rotation that I tried of which the rotation was initially equal to group 1. I only have the positions of the individual blocks within the group, so no "combined" rotation of the group in which the blocks are attached, as I mentioned above.

Idk if this is the right approach, but I calculated a "directional vector", for both group 1 and 2 (represented with the arrow helpers), in which I add all positions together. I create a new quaternion, set it from unit vectors (the calculated "directions"), but when I apply it, it rotates incorrectly.

I want to match the rotations of the patterns of blocks within a group and I basically want group 3 to have the same rotation as group 2 starting from group 1.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...