gpt4 book ai didi

c# - 旋转 3d 模型 XAML c#

转载 作者:行者123 更新时间:2023-11-30 12:13:20 26 4
gpt4 key购买 nike

我写了一个程序,以 XAML 格式导入 3d 模型:

<Viewport3D x:Name="ZAM3DViewport3D" ClipToBounds="true" Width="400" Height="300" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/interactivedesigner/2006" xmlns:c="http://schemas.openxmlformats.org/markup-compatibility/2006" c:Ignorable="d">
<Viewport3D.Resources>
<ResourceDictionary>/**other Elements at the same Level**/
<Transform3DGroup x:Key="root_boneOR13TR12" >
<TranslateTransform3D OffsetX="-0" OffsetY="-0" OffsetZ="-0"/>
<ScaleTransform3D ScaleX="1" ScaleY="1" ScaleZ="1"/>
<RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Angle="90.00000933" Axis="-1 0 0"/>
</RotateTransform3D.Rotation>
</RotateTransform3D>
<TranslateTransform3D OffsetX="-0.00299196" OffsetY="0.00964678" OffsetZ="0.000916864"/>
</Transform3DGroup>
</ResourceDictionary>
</Viewport3D.Resources>

<Viewport3D.Camera>
<PerspectiveCamera x:Name="FrontOR6" FarPlaneDistance="10" LookDirection="0,0,-1" UpDirection="0,1,0" NearPlaneDistance="0.1" Position="0,-0.0439422,0.729628" FieldOfView="39.5978" />
</Viewport3D.Camera>

<ModelVisual3D>
<ModelVisual3D.Content>
<Model3DGroup x:Name="Scene" Transform="{DynamicResource SceneTR7}"> <!-- Scene (XAML Path = ) -->
<AmbientLight Color="#646464" />
<DirectionalLight Color="#FFFFFF" Direction="-0.612372,-0.5,-0.612372" />
<DirectionalLight Color="#FFFFFF" Direction="0.612372,-0.5,-0.612372" />
<Model3DGroup x:Name="rootOR9" Transform="{DynamicResource rootOR9TR8}"> <!-- root (XAML Path = (Viewport3D.Children)[0].(ModelVisual3D.Content).(Model3DGroup.Children)[3]) -->
<Model3DGroup x:Name="glasses_meOR11" Transform="{DynamicResource glasses_meOR11TR10}"> <!-- glasses_me (XAML Path = (Viewport3D.Children)[0].(ModelVisual3D.Content).(Model3DGroup.Children)[3].(Model3DGroup.Children)[0]) -->
<Model3DGroup x:Name="root_boneOR13" Transform="{DynamicResource root_boneOR13TR12}"> <!-- root_bone (XAML Path = (Viewport3D.Children)[0].(ModelVisual3D.Content).(Model3DGroup.Children)[3].(Model3DGroup.Children)[0].(Model3DGroup.Children)[0]) -->
<Model3DGroup x:Name="main_boneOR15" Transform="{DynamicResource main_boneOR15TR14}"> <!-- main_bone (XAML Path = (Viewport3D.Children)[0].(ModelVisual3D.Content).(Model3DGroup.Children)[3].(Model3DGroup.Children)[0].(Model3DGroup.Children)[0].(Model3DGroup.Children)[0]) -->
</Model3DGroup>
<Model3DGroup x:Name="right_boneOR19" Transform="{DynamicResource right_boneOR19TR18}"> <!-- right_bone (XAML Path = (Viewport3D.Children)[0].(ModelVisual3D.Content).(Model3DGroup.Children)[3].(Model3DGroup.Children)[0].(Model3DGroup.Children)[0].(Model3DGroup.Children)[1]) -->
<Model3DGroup x:Name="right_bon0OR21" Transform="{DynamicResource right_bon0OR21TR20}"> <!-- right_bon0 (XAML Path = (Viewport3D.Children)[0].(ModelVisual3D.Content).(Model3DGroup.Children)[3].(Model3DGroup.Children)[0].(Model3DGroup.Children)[0].(Model3DGroup.Children)[1].(Model3DGroup.Children)[0]) -->
</Model3DGroup>
</Model3DGroup>
<Model3DGroup x:Name="left_bone_OR25" Transform="{DynamicResource left_bone_OR25TR24}"> <!-- left_bone_ (XAML Path = (Viewport3D.Children)[0].(ModelVisual3D.Content).(Model3DGroup.Children)[3].(Model3DGroup.Children)[0].(Model3DGroup.Children)[0].(Model3DGroup.Children)[2]) -->
<Model3DGroup x:Name="left_boneOR27" Transform="{DynamicResource left_boneOR27TR26}"> <!-- left_bone (XAML Path = (Viewport3D.Children)[0].(ModelVisual3D.Content).(Model3DGroup.Children)[3].(Model3DGroup.Children)[0].(Model3DGroup.Children)[0].(Model3DGroup.Children)[2].(Model3DGroup.Children)[0]) -->
</Model3DGroup>
</Model3DGroup>
</Model3DGroup>
<GeometryModel3D x:Name="glasses_meOR11GR12" Geometry="{DynamicResource glasses_meOR11GR12}" Material="{DynamicResource ER___Default_MaterialMR1}" BackMaterial="{DynamicResource ER___Default_MaterialMR1}"/>
</Model3DGroup>
<Model3DGroup x:Name="glasses_m0OR32" Transform="{DynamicResource glasses_m0OR32TR31}"> <!-- glasses_m0 (XAML Path = (Viewport3D.Children)[0].(ModelVisual3D.Content).(Model3DGroup.Children)[3].(Model3DGroup.Children)[1]) -->
<Model3DGroup x:Name="root_bone1OR34" Transform="{DynamicResource root_bone1OR34TR33}"> <!-- root_bone1 (XAML Path = (Viewport3D.Children)[0].(ModelVisual3D.Content).(Model3DGroup.Children)[3].(Model3DGroup.Children)[1].(Model3DGroup.Children)[0]) -->
<Model3DGroup x:Name="main_bone1OR36" Transform="{DynamicResource main_bone1OR36TR35}"> <!-- main_bone1 (XAML Path = (Viewport3D.Children)[0].(ModelVisual3D.Content).(Model3DGroup.Children)[3].(Model3DGroup.Children)[1].(Model3DGroup.Children)[0].(Model3DGroup.Children)[0]) -->
<Model3DGroup x:Name="main_eff1OR38" Transform="{DynamicResource main_eff1OR38TR37}"> <!-- main_eff1 (XAML Path = (Viewport3D.Children)[0].(ModelVisual3D.Content).(Model3DGroup.Children)[3].(Model3DGroup.Children)[1].(Model3DGroup.Children)[0].(Model3DGroup.Children)[0].(Model3DGroup.Children)[0]) -->
<Model3DGroup x:Name="right_bon1OR40" Transform="{DynamicResource right_bon1OR40TR39}"> <!-- right_bon1 (XAML Path = (Viewport3D.Children)[0].(ModelVisual3D.Content).(Model3DGroup.Children)[3].(Model3DGroup.Children)[1].(Model3DGroup.Children)[0].(Model3DGroup.Children)[0].(Model3DGroup.Children)[0].(Model3DGroup.Children)[0]) -->
<Model3DGroup x:Name="right_bon2OR42" Transform="{DynamicResource right_bon2OR42TR41}"> <!-- right_bon2 (XAML Path = (Viewport3D.Children)[0].(ModelVisual3D.Content).(Model3DGroup.Children)[3].(Model3DGroup.Children)[1].(Model3DGroup.Children)[0].(Model3DGroup.Children)[0].(Model3DGroup.Children)[0].(Model3DGroup.Children)[0].(Model3DGroup.Children)[0]) -->
</Model3DGroup>
</Model3DGroup>
<Model3DGroup x:Name="left_bone0OR46" Transform="{DynamicResource left_bone0OR46TR45}"> <!-- left_bone0 (XAML Path = (Viewport3D.Children)[0].(ModelVisual3D.Content).(Model3DGroup.Children)[3].(Model3DGroup.Children)[1].(Model3DGroup.Children)[0].(Model3DGroup.Children)[0].(Model3DGroup.Children)[0].(Model3DGroup.Children)[1]) -->
<Model3DGroup x:Name="left_bone1OR48" Transform="{DynamicResource left_bone1OR48TR47}"> <!-- left_bone1 (XAML Path = (Viewport3D.Children)[0].(ModelVisual3D.Content).(Model3DGroup.Children)[3].(Model3DGroup.Children)[1].(Model3DGroup.Children)[0].(Model3DGroup.Children)[0].(Model3DGroup.Children)[0].(Model3DGroup.Children)[1].(Model3DGroup.Children)[0]) -->
</Model3DGroup>
</Model3DGroup>
</Model3DGroup>
</Model3DGroup>
</Model3DGroup>
</Model3DGroup>
</Model3DGroup>
</Model3DGroup>
</ModelVisual3D.Content>
</ModelVisual3D>

我想通过 C# 访问 Transform3DGroup x:Key="root_boneOR13TR12"元素并希望在需要时修改 AxisAngelRotation 属性。

真诚的,bbklol

最佳答案

让我们从定义 Storyboard开始:当您运行它时,它实际上会旋转您的对象!

然后,对于一些动画(DoubleAnimation 效果很好),您可以设置 RotateTransform3D 的 Rotation 属性(见下文)。

在你的情况下,为了回答你的问题,我认为你应该使用非常接近这个的语法(我保留了你的 XAML 路径,用 [ ] 签名......删除它们!!):

Storyboard.TargetProperty="[(Viewport3D.Children)[0].(ModelVisual3D.Content).(Model3DGroup.Children)[3].(Model3DGroup.Children)[0].(Model3DGroup.Children)[0])].(ModelVisual3D.Transform).(Transform3DGroup.Children)[2].(RotateTransform3D.Rotation).(AxisAngleRotation3D.Angle)"

我只是举个例子,也许你可以更简单地理解......

这是 Storyboard,它将在下面的 ViewPort3D 中旋转项目:

<Storyboard x:Key="RotationStoryboard">
<!--This is an horizontal rotation-->
<DoubleAnimation Storyboard.TargetProperty="(Viewport3D.Children)[0].(ModelVisual3D.Transform).(Transform3DGroup.Children)[0].(RotateTransform3D.Rotation).(AxisAngleRotation3D.Angle)"
BeginTime="0:0:0.25"
From="360"
To="0"
Duration="0:0:4.5"
RepeatBehavior="Forever" />
<!--This is an orbital horizontal rotation (I removed the other rotation on first transformation)-->
<DoubleAnimation Storyboard.TargetProperty="(Viewport3D.Children)[1].(ModelVisual3D.Transform).(Transform3DGroup.Children)[3].(RotateTransform3D.Rotation).(AxisAngleRotation3D.Angle)"
From="360"
To="0"
RepeatBehavior="Forever"
Duration="0:0:3.5" />
</Storyboard>

这就是对象的 XAML 代码...

<Viewport3D>
<Viewport3D.Children>
<!--First object-->
<ModelVisual3D>
<ModelVisual3D.Transform>
<Transform3DGroup>
<RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Angle="360"
Axis="0,1,0" />
</RotateTransform3D.Rotation>
</RotateTransform3D>
</Transform3DGroup>
</ModelVisual3D.Transform>
<model3d:Sphere3D />
</ModelVisual3D>
<!--Second object-->
<ModelVisual3D>
<ModelVisual3D.Transform>
<Transform3DGroup>
<RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Angle="360"
Axis="0,1,0" />
</RotateTransform3D.Rotation>
</RotateTransform3D>
<ScaleTransform3D ScaleZ="0"
ScaleY="0"
ScaleX="0"/>
<TranslateTransform3D OffsetX="3.5" />
<RotateTransform3D CenterX="0"
CenterY="0"
CenterZ="0">
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Angle="360"
Axis="0,1,0" />
</RotateTransform3D.Rotation>
</RotateTransform3D>
</Transform3DGroup>
</ModelVisual3D.Transform>
<model3d:Sphere3D x:Name="SatelliteSphere">
<model3d:Sphere3D.Transform>
<RotateTransform3D CenterX="-1"
CenterY="-1"
CenterZ="-1" />
</model3d:Sphere3D.Transform>
</model3d:Sphere3D>
</ModelVisual3D>
</Viewport3D.Children>
</Viewport3D>

关于c# - 旋转 3d 模型 XAML c#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11868823/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com