Created
June 17, 2019 08:31
-
-
Save lukpazera/b0daa80b351b382ddd07931aae5deda2 to your computer and use it in GitHub Desktop.
This snippet can be used to align vector in world space to a current view. This could be used for something like Align To View in MODO locator shape properties. We could potentially draw a shape that is always facing view.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import lx | |
import lxu | |
import modo | |
scene = modo.Scene() | |
i = scene.item('Locator') | |
# Get current MODO viewport interface | |
vs = lx.service.View3Dport() | |
currentViewIndex = vs.Current() | |
view = lx.object.View3D(vs.View(currentViewIndex)) | |
# Get viewport matrix as modo.Matrix3 | |
# This gets matrix as 3 tuples. | |
# 0 argument value means we want view matrix, 1 would get inverted view matrix | |
viewMtxTuple = view.Matrix(0) | |
# Convert the tuple into modo.Matrix3 object. | |
viewMtx = modo.Matrix3() | |
viewMtx.set(viewMtxTuple) | |
# Transform world space vector by view matrix | |
# So it stays aligned with the view | |
mat4 = modo.Matrix4(viewMtx) | |
pos = modo.Vector3(1.0, 0.0, 0.0) | |
pos.mulByMatrixAsPoint(mat4) | |
# This just applies calculated vector as item position to see the result | |
l = modo.LocatorSuperType(i.internalItem) | |
l.position.set(pos.values) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment