两次转换Model3DGroup

时间:2013-02-17 18:52:33

标签: c# wpf

我需要将Model3DGroup变换两次(一次设置位置,一次设置旋转)。我试过这个:

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);

那是不行的。我在google和SO上搜索过,似乎找不到任何东西。

1 个答案:

答案 0 :(得分:4)

您需要TransformGroup课程。

该课程将结合您的变换。

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;