Set Base View Rotation and Position
-
I don't see any code attached. But anyway, you need to get to the BaseDraw (which is a child class of BaseView). There you will find HasCameraLink(), which will tell you whether the editor camera is active, or some camera in the scene. GetEditorCamera() returns you the editor camera, and GetSceneCamera() the camera that is active in the scene, if there is any. These cameras are BaseObjects with all their matrix functions to set rotation, position, scale.
Depending on what you do, you may need to create a scene camera as object in the ObjectTree and set it in your BaseDraw. -
@cairyn Thanks for the answer, unfortunately there is no code yet, I have no idea how to create this code snippet.
I can get position and rotation 3d Viewer use command BaseView.GetMg(), but i cant set position and rotation 3d viewer.
I need change 3d viewer transformation without create new objects or cameras.
My task is the following: I have a matrix with rot, pos, I need to get the rotation and position viewport (3d viewer or warden) from the matrix values.
You can put the camera in this position to display the object, but I need not to have this camera on the scene. if the camera is removed the viewer will move to the begin position. -
You get your current document's BaseDraw with BaseDocument.GetActiveBaseDraw(). If you don't want to add anything to the scene, then you need to force the viewport to use the editor camera by SetSceneCamera(None). Then as mentioned already you can get the editor camera with GetEditorCamera(). This camera is part of the viewport and not the scene.
I assume you have a document, otherwise I'm afraid I do not understand what this script is supposed to do. Or are you actually programming a SceneLoaderData plugin? What is the execution context for this task?
-
@cairyn I have a document.
The main task is to convert 3d max format to c4d using xml file and fbx file. I want the 3d viewer in 3d max to copy the position and rotation to the c4d file. I have the position and rotation of a 3d viewer from 3d max, it remains to set the position and rotation in the c4d file.
I will try your method, but without an example it is not very clear to me -
@cairyn It’s just that the 3D viewer can also move quietly on the work surface, which means it has position and rotation, I want to set this position and rotation somehow, I’m interested in how it can be done only position and rotation.
-
Well, here's a script which shows the steps in connection. The editor camera for the current document is activated and moved 50 units along its x axis (just to have some change of position; rotation is equivalent). Since the editor camera cannot have a parent, its reference system is always world.
import c4d from c4d import gui def main(): bd = doc.GetActiveBaseDraw() # the basedraw of the viewport that shows the document if bd == None: print ("This document does not have an active BaseDraw!") return bd.SetSceneCamera(None) # forces viewport to use editor camera cam = bd.GetEditorCamera() # the editor camera itself camPos = cam.GetAbsPos() camPos[0] += 50 cam.SetAbsPos(camPos) c4d.EventAdd() if __name__=='__main__': main()
-
@cairyn Thank you so much) This is what I was looking for! magic)
-
Hello @Djoneeeee,
welcome to the Plugin Café community and thank you reaching out to us. I would invite you having a look at our Forum Guidelines for future postings. I have marked this topic as a question.
Thank you @Cairyn for providing an answer. We do not have much to add here. The only thing I would point out is that:
bd.SetSceneCamera(None) # forces viewport to use editor camera
is formally not necessary. It is not that this would be wrong what @Cairyn did there, it is only that this will reset the camera of the viewport to the internal one. So, when a user has linked a camera to a viewport, e.g., set a camera as a rendering camera, this line of code will make that camera inactive and default to the internal viewport camera. Which might have a completely different transform. When you do not want this to happen, you can just skip this line and directly call:
cam = bd.GetEditorCamera() # the editor camera itself
Cheers,
Ferdinnand -
@ferdinand said in Set Base View Rotation and Position:
So, when a user has linked a camera to a viewport, e.g., set a camera as a rendering camera, this line of code will make that camera inactive and default to the internal viewport camera.
Yep, that was the intent since the OP said they did not want a camera in the scene ("I need not to have this camera on the scene") but I may have misinterpreted the meaning. Not familiar with how 3dsMax handles its cameras.
-
@cairyn said in Set Base View Rotation and Position:
@ferdinand said in Set Base View Rotation and Position:
So, when a user has linked a camera to a viewport, e.g., set a camera as a rendering camera, this line of code will make that camera inactive and default to the internal viewport camera.
Yep, that was the intent since the OP said they did not want a camera in the scene ("I need not to have this camera on the scene") but I may have misinterpreted the meaning. Not familiar with how 3dsMax handles its cameras.
Yeah, I figured that this was probably intentional, but I just wanted to clarify that it is a bit of an odd thing to do.
Cheers,
Ferdinand