I tried this
xxxx.pivot = SCNMatrix4MakeTranslation(0.5, 0.5, 0.5)
But it does not make it centered. What is the best way of doing that with code?
Center the pivot to the center of the object, and the object to the center of the world, in Blender, Cheeatah 3D, 3D studio Max or any other suitable software and then re-export it with the pivot in the proper position. Changing the pivot in code does not have the same effect and will quite likely lead to other issues once you want to translate, rotate, scale etc. Offsetting the pivot through code is not really meant as a fix for an incorrectly placed pivot which is actually the result of the vertices having the wrong positions. Rather than trying to patch that in code, fix it properly in a 3D modeling package.
A little confused about the question. Are you trying to center the couch on the coordinate origin? Why are you using pivot instead of translation? The pivot property moves the local coordinate system origin relative to the object itself (i.e. setting the upper left corner of the couch to be 0,0, instead of the center). Whereas translation moves the object in the scene but maintains the object's position relative to its own coordinate system. Which are you trying to accomplish?
https://developer.apple.com/documentation/scenekit/scnnode/1408044-pivot
Related
How can I find submesh under my mouse NOT using Raycasting? Is any way to do it? I know how to do it clicking on object and using raycast but completely haven't idea how to id it without it. I need it because of bug in Unity - I can't update version of Unity, so I need to find any solution.
You can see if your mesh contains the mouse.
You get the position and the size of the mesh which allows you to create a square or a cube (whichever you need) and then you just see if your mouse fits within that square or a cube. If so, then you want to select that mesh.
https://tutorialedge.net/gamedev/aabb-collision-detection-tutorial/
or
If your object was a circle/sphere then you can perform a simple distance check between mesh's origin and mouse, if the distance is <= than the radius of the object, then you want to select that mesh.
http://cgp.wikidot.com/circle-to-circle-collision-detection
It is similar, just instead of using 2nd object, you are using a mouse.
I have tried to find any information on how the Unity assigns pivot points to object but all I keep finding is threads on how to move pivot points and that it can't be done. I am creating a 2D game with a background that is randomly created with meshes that are wrapped in empty GameObjects. These objects are organically shaped but they have a property that returns a rectangle that bounds the object so that they can be placed in a way that they are not overlapping. The trouble is that the algorithm assumes that the pivot point is going to be the center of the object. What I would like to know is how does Unity decide where the pivot point will be set to so that I can predict how much I will need to move my mesh inside the parent object so that the pivot point will be in the center of the bounding rectangle.
Possible fix:
Try create the meshes during runtime and see if it always places the pivot points at a certain corner or at least relatively speaking the same location.
If it does that you would know where the pivot point is and could take it into account in your code, if you also know the size of the mesh you spawn.
So I think most general and correct answer that I can come up with is that unity assigns the pivot point to the center of the GameObject that you apply the Mesh to. The local coordinates of the vertices of the mesh depending on how you create them mighht place your mesh so that its logical center is not the same as the that of the empty GameObject that it is attached to. What I did to fix the issue was to make a vector from local point (0,0,0) to the center of bounding rectangle and translate the vertices I use to make my mesh by that vector inverted. It wasn't perfect but by far close enough to ensure that I won't have any overlapping meshes.
I was trying to set up steering wheel pivot for my spaceship so it rotates correctly. In order to do this I created empty object in the position where I want the pivot(img 1) to be and then parented the steering wheel(img 2) to this pivot. I thought all pivots would stay in the same place in global space and only changes would happen to the steering wheel in local space. I'm confused because it actually changed the position of the pivot as well(img 3), although the only thing I did was parenting the steering wheel to it. Pivot was moved to where steering wheel transform previously was.
img 1
img 2
img 3
Have you tried changing the tool handle location from Center to Pivot?
(The switch is located in the top left of the screen near the tool selector)
Also note you can change the location of the tool from Global to Local.
Hope this helps,
I have a GameObject sphere in my program that represents the Earth.
So I apply a material to it like so:
Using data and a positioning script, I position markers on the globe that represent locations (by longitude and latitude).
Everything seems to work, except that the texture does not line up with the points plotted.
How can I shift the texture so that my data points are on top of the actual locations?
You can see this in the following figure, where South America points are clearly plotted over the ocean between Antarctica and South America in the wrong orientation.
EDIT:
After playing a lot, I found that X offset works, but Y offset does not work. The combination will help me accomplish the task, but it's not wrapping correctly...
To create a new Material, use Assets->Create->Material from the main menu or the Project View context menu.
Drag your texture into the inspector field and change the Offset variables until you get the desired offset result.
You should consider using modeling programs such as Blender for creating textured models or circles but keep in mind if you have textured models it needs to be in .fbx format.
I'm playing with OpenGL ES on iPhone and I'm trying to rotate a model by panning with the finger. I discovered the open source app Molecules that let's you do that and I'm looking at that code, but when it comes to rotate a model of mine I'm able to rotate it only around a point distant in the space (like it was in orbit as a satellite and I am the fixed planet).
Any suggestion on what can be wrong?
I can post the code later , maybe on demand (many lines)
For the most part refer to Molecules you can find it here MOLECULES
If my memory serves me correctly, I think you need to translate the model to the origin, rotate, and then translate back to starting position to get the effect you are after.
I think there is a glTranslate() function, Say the object is at 1,0,0. You should then translate by -1,0,0 to go to origin. That is translate by a vector going from the center of the object to the origin.
The draw code probably looks roughly like this:
glLoadIdentity();
glTranslate(0, 0, -10);
glRotate(...);
drawMolecule();
Now it's important to realize that these transformations are applied in reverse order. If, in drawMolecule, we specify a vertex, then this vertex will first be rotated about the axis given to glRotate (which by definition passes through the local origin of the molecule), and then be translated 10 units in the −z direction.
This makes sense, because glTranslate essentially means: "translate everything that comes after this". This includes the glRotate call itself, so the result of the rotation also gets translated. Had the calls been reversed, then the result of the translation would have been rotated, which results in a rotation about an axis that does not pass through the origin anymore.
Bottom line: to rotate an object about its local origin, put the glRotate call last.