利用HelixToolkit将两个3D模型叠放到一起

wowArthas 2020-04-10 02:16:14
在vs2017中建了个c#的wpf项目,我想将两个.obj模型能放到同一个界面中,两个模型都能单独控制转动,并且能够叠放到一起,这个后台怎么实现,我现在只能在一个界面里分成两部分控制,不知道怎么放到一起
...全文
845 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
wowArthas 2020-04-10
  • 打赏
  • 举报
回复
引用 1 楼 lindexi_gd 的回复:
只要你的坐标叠加就可以,但是需要注意元素所在是在两个不同的空间
我现在是分割成了两个界面,所以光position一样好像不行?我是不是要把两个放一个view里?
desperaso 2020-04-10
  • 打赏
  • 举报
回复
只是举例啊。例如一个3D模型,放到Grid里面,搞2个Grid,每个里面new 一个Preview_Model,Grid位置设一块就重叠。
参考http://bbs.cskin.net/thread-16048-1-1.html

public class Preview_Model
{
public AxisAngleRotation3D axisAngleRotation3D;
public PerspectiveCamera perspectiveCamera;
public Point3DCollection[] positions = new Point3DCollection[6];
public PointCollection[] texturepoints = new PointCollection[6];
public Image[] image = new Image[6];
public System.Drawing.Bitmap[] face_image = new System.Drawing.Bitmap[] { Resource.f4, Resource.f3, Resource.f0, Resource.f2, Resource.f5, Resource.f1 };
public Viewport3D viewport3D;
public MeshGeometry3D[] meshGeometry3D = new MeshGeometry3D[6];
public GeometryModel3D[] geometryModel3D = new GeometryModel3D[6];
public ModelVisual3D modelVisual3D;
public Model3DGroup model3DGroup;
public DoubleAnimation animation;
public Storyboard RotCube;

public void init_draw(Grid obj, double x, double y, double z,double size)
{
Set_Scaling(x, y, z);

texturepoints = new PointCollection[6]
{
new PointCollection {new Point(1,0), new Point(0,0), new Point(0,1), new Point(0,1), new Point(1,1),new Point(1,0) },
new PointCollection { new Point(0,0),new Point(0,1),new Point(1,1), new Point(1,1),new Point(1,0),new Point(0,0) },

new PointCollection { new Point(0,1), new Point(1,1),new Point(1,0), new Point(1,0),new Point(0,0),new Point(0,1) },
new PointCollection { new Point(1,1), new Point(1,0),new Point(0,0), new Point(0,0), new Point(0,1), new Point(1,1) },

new PointCollection { new Point(0,1), new Point(1,1), new Point(1,0),new Point(1,0), new Point(0,0), new Point(0,1)},
new PointCollection{ new Point(1,1), new Point(1,0),new Point(0,0),new Point(0,0), new Point(0,1),new Point(1,1)}
};

viewport3D = new Viewport3D();

perspectiveCamera = new PerspectiveCamera()
{
Position = new Point3D(0, 0, 3),
LookDirection = new Vector3D(0, 0, -3),
FieldOfView = size,
UpDirection = new Vector3D(0, 1, 0),
FarPlaneDistance = 20,
NearPlaneDistance = 0,
};
viewport3D.Camera = perspectiveCamera;

modelVisual3D = new ModelVisual3D();
model3DGroup = new Model3DGroup();

for (int i = 0; i < 6; i++)
{
geometryModel3D[i] = new GeometryModel3D();

DiffuseMaterial diffuse = new DiffuseMaterial();
VisualBrush visualBrush = new VisualBrush();
image[i] = new Image();
image[i].Source = Function.BitmapToImageSource(face_image[i]);
visualBrush.Visual = image[i];
diffuse.Brush = visualBrush;
geometryModel3D[i].Material = diffuse;

meshGeometry3D[i] = new MeshGeometry3D()
{
Positions = positions[i],
TextureCoordinates = texturepoints[i],
};
geometryModel3D[i].Geometry = meshGeometry3D[i];
model3DGroup.Children.Add(geometryModel3D[i]);
}

AmbientLight ambientLight = new AmbientLight();
model3DGroup.Children.Add(ambientLight);

modelVisual3D.Content = model3DGroup;
viewport3D.Children.Add(modelVisual3D);

obj.Children.Add(viewport3D);

axisAngleRotation3D = new AxisAngleRotation3D(new Vector3D(0, 1, 0), 0);
RotateTransform3D rotate = new RotateTransform3D(axisAngleRotation3D);
modelVisual3D.Transform = rotate;
animation = new DoubleAnimation();
animation.From = 0;
animation.To = 360;
animation.Duration = new Duration(TimeSpan.FromSeconds(10.0));
animation.RepeatBehavior = RepeatBehavior.Forever;
NameScope.SetNameScope(obj, new NameScope());
obj.RegisterName("cubeaxis", axisAngleRotation3D);
Storyboard.SetTargetName(animation, "cubeaxis");
Storyboard.SetTargetProperty(animation, new PropertyPath(AxisAngleRotation3D.AngleProperty));
RotCube = new Storyboard();
RotCube.Children.Add(animation);
RotCube.Begin(obj, true);
}

public void Set_Scaling(double x, double y, double z)
{
positions[0] = new Point3DCollection(new Point3D[] {
new Point3D(x, y, -z), new Point3D(-x, y, -z), new Point3D(-x, y, z),
new Point3D(-x, y, z),new Point3D(x, y, z), new Point3D(x, y, -z)
});

positions[1] = new Point3DCollection(new Point3D[] {
new Point3D(-x,y,-z),new Point3D(-x,-y,-z), new Point3D(-x,-y,z),
new Point3D(-x,-y,z),new Point3D(-x,y,z),new Point3D(-x,y,-z)
});

positions[2] = new Point3DCollection(new Point3D[] {
new Point3D(-x,-y,z),new Point3D(x,-y,z),new Point3D(x,y,z),
new Point3D(x,y,z),new Point3D(-x,y,z), new Point3D(-x,-y,z)
});

positions[3] = new Point3DCollection(new Point3D[] {
new Point3D(-x,-y,-z),new Point3D(-x,y,-z),new Point3D(x,y,-z),
new Point3D(x,y,-z), new Point3D(x,-y,-z),new Point3D(-x,-y,-z)
});

positions[4] = new Point3DCollection(new Point3D[] {
new Point3D(-x,-y,-z), new Point3D(x,-y,-z), new Point3D(x,-y,z),
new Point3D(x,-y,z),new Point3D(-x,-y,z), new Point3D(-x,-y,-z)
});

positions[5] = new Point3DCollection(new Point3D[] {
new Point3D(x,-y,-z),new Point3D(x,y,-z),new Point3D(x,y,z),
new Point3D(x,y,z), new Point3D(x,-y,z), new Point3D(x,-y,-z)
});

}
}
lindexi_gd 2020-04-10
  • 打赏
  • 举报
回复
在 Model3DGroup 可以通过 model3DGroup.Children.Add(model); 的方法添加其他的 Model3DGroup 类
lindexi_gd 2020-04-10
  • 打赏
  • 举报
回复
只要你的坐标叠加就可以,但是需要注意元素所在是在两个不同的空间

111,082

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧