Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transform a Model3DGroup twice

Tags:

c#

wpf

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.

like image 722
Alexander Forbes-Reed Avatar asked Jun 29 '26 18:06

Alexander Forbes-Reed


1 Answers

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;
like image 138
Blablablaster Avatar answered Jul 01 '26 08:07

Blablablaster