Transforming 3DGroup Model Twice
I need to transform Model3DGroup twice (set position once and set rotation once). I've tried this:
var model = ModelImporter.Load(gameAssetPath);
model.Transform = new TranslateTransform3D(
placedObject.SpawnCoordinates.X,
placedObject.SpawnCoordinates.Y,
placedObject.SpawnCoordinates.Z);
var modelRotation = new Model3DGroup();
modelRotation.Children.Add(model);
modelRotation.Transform = new RotateTransform3D(new AxisAngleRotation3D(), placedObject.SpawnCoordinates.Roll, placedObject.SpawnCoordinates.Pitch, placedObject.SpawnCoordinates.Yaw);
And it was not good. I've searched google and SO and can't find anything.
+3
source to share
1 answer
For this you need the TransformGroup class.
This class will combine your transforms.
var model = ModelImporter.Load(gameAssetPath);
var modelRotation = new Model3DGroup();
modelRotation.Children.Add(model);
var t1 = new TranslateTransform3D(
placedObject.SpawnCoordinates.X,
placedObject.SpawnCoordinates.Y,
placedObject.SpawnCoordinates.Z);
var t2 = new RotateTransform3D(
new AxisAngleRotation3D(),
placedObject.SpawnCoordinates.Roll,
placedObject.SpawnCoordinates.Pitch,
placedObject.SpawnCoordinates.Yaw);
var tg = new TransformGroup();
tg.Children.Add(t1);
tg.Children.Add(t2);
modelRotation.Transform = tg;
+4
source to share