I have a Viewport3D with a 3D model composed of multiple smaller components centered at the origin. I'm animating the PerspectiveCamera to rotate about the Y-axis using an AnimationClock created from a DoubleAnimation to create a rotating effect on the model. In addition, I have another rotateTransform3D assigned to the camera's transformgroup to enable the user to orbit around and zoom in-out of the model using the mouse.
I want to be able to translate each component as it is being selected to move in front of the rotating camera. However, I don't know how to get the position of the camera relative to the 3D model because the coordinate system of camera is being animated and transformed by the user's input.
Is there a way to get the offset between two coordinate systems?
Any help or suggestions would be appreciated.
Thanks,
Related
I have a model which rotates on the X axis, but the center of the rotation is not on the axis itself. The rotation code is pretty simple:
model.current.rotation.x += 0.016; (axis and speed)
but there seems no way to define the actual axis of rotation to ensure the model just rotates around its own center. At the moment it rotates in a big circle!
Any suggestions appreciated.
:-0
your mesh most likely is not centred, meaning the vertices point way out of the models center of mass. you can either fix this in blender, but even threejs has methods (on the geometry) that recalculate the vertices. a cheaper solution would be to render the mesh, take a box3, set it from the object, then get min/max and use it to shift the object by half of it.
I use OrbitControls to allow the users to rotate and pan the screen. However I want to be able to set the rotation around the Z axis for the OrthographicCamera that the OrbitControls. I am able to change the position and the OrbitControls seem to honor that when I switch to a different view and back. However when I change the rotation around the Z axis for the OrthoGraphic camera, everytime I use the mouse to pan or rotate objects it jumps to 0 rotation and starts from there. How do I fix this?
I have a 3D object that I'm rotating in WPF.
I need to know how to move the point that the object is rotating on. Currently my object rotates from the 0,0,0. I'd like to be able to change the the point of rotation to 50,0,0 (or any other point I set).
The solution was to set the RotateTransform3D CenterX, CenterY, or CenterZ parameter to account for the offset where you want the rotation to happen.
I have a few 3d rectangles on my screen that I want to pivot around the Y axis.
I want to press down with the mouse, and rotate the 3d object to a max rotation, but when the user moves their mouse, I want to slightly rotate it so that it looks like a see-saw (rotating from a range of -13 to 13 degrees on the Y-Axis).
At the moment, I can do this, but my frame rate really really suffers when I move the mouse quickly. So for example, when I click the left side of the rectangle, I generate a storyboard and animation objects, then rotate the 3d object to -13 degrees. Then when I slightly move the mouse to the right, I want to rotate it to -12.5, and so on...
Again, I can do all of this, its just that the performance suffers greatly! It goes down to 5-FPS in some cases... which is not acceptable.
My question is am I doing this the best way? How else could you animate a rotation base on the users position on the screen?
Thanks for any help you can provide!
Mark
I assume you are doing the following:
Using a separate Model3D for the object you are rotating & including it in a Model3DGroup
Giving it a RotateTransform3D containing an AxisAngleRotation3D
Animating the AxisAngle3D's Axis property in the Storyboard
If my assumptions are correct I think we can conclude the problem is efficiency in rendering, since the CPU required to update a single Axis value, recompute the Transform, and update MILCore is negligible.
I can think of several ways that could improve the rendering performance:
If your Model3D being rotated is a GeometryModel3D backed by a MeshGeometry3D, do as much as you can to simplify the mesh and the materials used. It can also help to substitute a different mesh for closeups.
If the Model3D being rotated is a GeometryModel3D that uses VisualBrush brushes, during animation temporarily replace the VisualBrush with an ImageBrush containing a BitmapImage that is a snapshot of the Visual underlying the VisualBrush as of the instant the animation starts. When the animation ends, put backthe VisualBrush. The user probably won't notice that the contents of the object freeze temporarily when it rotates. (Note that this same technique can be used if your Visual3D is a Viewport2DVisual3D.)
If the Model3D being rotated is combined into a Model3DGroup with other objects but lies entirely in front of or behind the other groups, separate the model into its own separate Viewport3DVisual, appropriately layered to get the effect you want.
Simplify lighting or Material types
Monitor the actual frame rate and if it is going too low when using the storyboard, rotate the object immediately to where the mouse indicates without using an animation.
MSDN presents some tips on what impacts in WPF 3D performance. If you didn't stumble on it yet, check the items on "Performance Impact: High" list.
Edit: In march 2009, Josh Smith published an article on CodeProject that involves rotating 3D objetcs. Maybe you want to check his solution.
I have several geometry meshes in my Viewport3D, these have bounds of (w:1800, h:500, d:25).
When a user clicks in the middle of the mesh, I want the Point3D of (900, 500, 25)...
How can I achieve this?
Thanks!
Mark
Just use VisualTreeHelper.HitTest with the callback.
If you have a Viewport3D containing the model, you can just pass in a PointHitTestParameters containing the mouse location.
If you need to operate directly on a Visual3D, pass in a RayHitTestParameters computed from your camera parameters and the mouse location.
In either case your callback will be called with a RayTestHitResult, and if you hit a mesh it will be a RayMeshGeometry3DHitTestResult. This includes a Point3D property telling you the 3D point in space that was hit, and also the mesh and triangle that was hit.
See 3D Hit testing for more details.