I need to transform a Model3DGroup twice (once to set the position, and once to set the rotation). I 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 that was a no-go. I've searched on google and SO, and can't seem to find anything.
You need TransformGroup class for this.
That 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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With