简体   繁体   English

将Model3DGroup的多个实例添加到ModelVisual3D

[英]Adding multiple instances of Model3DGroup to ModelVisual3D

I am working on building a graphical model in WPF that should be of a three-dimensional truss eventually. 我正在努力在WPF中构建一个最终应该是三维桁架的图形模型。 I am building a single object as a Model3DGroup. 我正在构建一个单个对象作为Model3DGroup。 I am then adding that Model3DGroup to a ModelVisual3D. 然后我将Model3DGroup添加到ModelVisual3D。

Currently, I am declaring in my *.xaml.cs file private ModelVisual3D mGeometry; 目前,我在我的* .xaml.cs文件中声明private ModelVisual3D mGeometry; at the top. 在顶部。 Then, a new Model3DGroup is created, where several points triangle models are added. 然后,创建一个新的Model3DGroup,其中添加了几个点三角模型。 Then, the following code is used to add this to the ModelVisual3D: 然后,使用以下代码将其添加到ModelVisual3D:

mGeometry.Content = prism; // where prism is the Model3D Group with added triangle points
mGeometry.Transform = new Transform3DGroup();
this.viewport.Children.Add(mGeometry);

My question is: how do I add multiple different instances of Model3DGroup to one ModelVisual3D? 我的问题是:如何将Model3DGroup的多个不同实例添加到一个ModelVisual3D? I eventually want to build a truss composed of multiple different Model3DGroups and display it on the screen. 我最终想要构建一个由多个不同的Model3DGroup组成的桁架并将其显示在屏幕上。

I'm not opposed to changing how I do this, as I'm not sure the best way. 我不反对改变我的做法,因为我不确定最好的方法。 Currently, I can only display one object. 目前,我只能显示一个对象。

Each ModelVisual3D can contain just 1 Model3D but can also contain other Visual3D s. 每个ModelVisual3D只能包含1个Model3D但也可以包含其他Visual3D In this case you can just add more ModelVisual3D s to the Children property of your ModelVisual3D : 在这种情况下,你可以添加更多的ModelVisual3D到S Children的财产ModelVisual3D

mGeometry.Content = prism;
var moreModelVisual3D = new ModelVisual3D();
moreModelVisual3D.Content = prism2; //your other Model3DGroup
mGeometry.Children.Add(moreModelVisual3D);
//create more if you want ...

Also note that each Model3DGroup can contain other Model3DGroup s. 另请注意,每个Model3DGroup都可以包含其他Model3DGroup If you think that can be applied in your case, please consider it instead. 如果您认为可以在您的情况下应用,请改为考虑它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM