スライダーで、MeshGeometry3Dの BOX の頂点座標 Positions を直接変更してみる。このぐらいの頂点数なら問題なくスムーズに変形できるが・・・・・
using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Media3D;namespace Morphing_V2
{
public partial class Window1 : System.Windows.Window
{
private void slider1_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
double v = slider1.Value / 10f;
GeometryModel3D gm3d = (GeometryModel3D)this.BoxOR9.Children[0];
MeshGeometry3D mesh3d = (MeshGeometry3D)gm3d.Geometry; for (int i = 0; i < mesh3d.Positions.Count; i++)
{
mesh3d.Positions[i] = new Point3D(
originalMeshGeometry3DPosition[i].X * v,
originalMeshGeometry3DPosition[i].Y * v,
originalMeshGeometry3DPosition[i].Z * v);
}
} Point3DCollection originalMeshGeometry3DPosition = null; private void Window_Loaded(object sender, RoutedEventArgs e)
{
GeometryModel3D gm3d = (GeometryModel3D)this.BoxOR9.Children[0];
MeshGeometry3D mesh3d = (MeshGeometry3D)gm3d.Geometry; originalMeshGeometry3DPosition = new Point3DCollection();
for (int i = 0; i < mesh3d.Positions.Count; i++)
originalMeshGeometry3DPosition.Add(mesh3d.Positions[i]);
}
}
}<Window x:Class=”Morphing_V2.Window1″ Title=”Morphing_V2″ Width=”497″ Height=”450″ 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” Loaded=”Window_Loaded”>
<Grid>
<Viewport3D x:Name=”ZAM3DViewport3D” ClipToBounds=”true” Width=”400″ Height=”300″>
<Viewport3D.Resources>
<ResourceDictionary>
<MaterialGroup x:Key=”ER___Default_MaterialMR1″ >
<DiffuseMaterial>
<DiffuseMaterial.Brush>
<SolidColorBrush Color=”#D3C8AD” Opacity=”1.000000″/>
</DiffuseMaterial.Brush>
</DiffuseMaterial>
<SpecularMaterial SpecularPower=”93.8667″>
<SpecularMaterial.Brush>
<SolidColorBrush Color=”#333333″ Opacity=”1.000000″/>
</SpecularMaterial.Brush>
</SpecularMaterial>
</MaterialGroup>
<Transform3DGroup x:Key=”SceneTR7″ >
<TranslateTransform3D OffsetX=”0″ OffsetY=”0″ OffsetZ=”0″/>
<ScaleTransform3D ScaleX=”1″ ScaleY=”1″ ScaleZ=”1″/>
<RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Angle=”0″ Axis=”0 1 0″/>
</RotateTransform3D.Rotation>
</RotateTransform3D>
<TranslateTransform3D OffsetX=”0″ OffsetY=”0″ OffsetZ=”0″/>
</Transform3DGroup>
<Transform3DGroup x:Key=”BoxOR9TR8″ >
<TranslateTransform3D OffsetX=”0″ OffsetY=”0″ OffsetZ=”0″/>
<ScaleTransform3D ScaleX=”1″ ScaleY=”1″ ScaleZ=”1″/>
<RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Angle=”47.33348273″ Axis=”0.5325566653 -0.8245461129 -0.1910683281″/>
</RotateTransform3D.Rotation>
</RotateTransform3D>
<TranslateTransform3D OffsetX=”0″ OffsetY=”0″ OffsetZ=”0″/>
</Transform3DGroup>
<MeshGeometry3D x:Key=”BoxOR9GR10″
TriangleIndices=”0,1,2 2,3,0 4,5,6 6,7,4 8,9,10 10,11,8 12,13,14 14,15,12 16,17,18 18,19,16 20,21,22 22,23,20 ”
Normals=”0,0,-1 0,0,-1 0,0,-1 0,0,-1 0,0,1 0,0,1 0,0,1 0,0,1 0,-1,0 0,-1,0 0,-1,0 0,-1,0 1,0,0 1,0,0 1,0,0 1,0,0 0,1,0 0,1,0 0,1,0 0,1,0 -1,0,0 -1,0,0 -1,0,0 -1,0,0 ”
Positions=”-0.5,-0.5,-0.5 -0.5,0.5,-0.5 0.5,0.5,-0.5 0.5,-0.5,-0.5 -0.5,-0.5,0.5 0.5,-0.5,0.5 0.5,0.5,0.5 -0.5,0.5,0.5 -0.5,-0.5,-0.5 0.5,-0.5,-0.5 0.5,-0.5,0.5 -0.5,-0.5,0.5 0.5,-0.5,-0.5 0.5,0.5,-0.5 0.5,0.5,0.5 0.5,-0.5,0.5 0.5,0.5,-0.5 -0.5,0.5,-0.5 -0.5,0.5,0.5 0.5,0.5,0.5 -0.5,0.5,-0.5 -0.5,-0.5,-0.5 -0.5,-0.5,0.5 -0.5,0.5,0.5 ”
/>
</ResourceDictionary>
</Viewport3D.Resources> <Viewport3D.Camera>
<PerspectiveCamera x:Name=”FrontOR6″ FarPlaneDistance=”10″ LookDirection=”0,0,-1″ UpDirection=”0,1,0″ NearPlaneDistance=”1″ Position=”0,0,2.38423″ FieldOfView=”39.5978″ />
</Viewport3D.Camera> <ModelVisual3D>
<ModelVisual3D.Content>
<Model3DGroup x:Name=”Scene” Transform=”{DynamicResource SceneTR7}”> <!– Scene (XAML Path = ) –>
<AmbientLight Color=”#333333″ />
<DirectionalLight Color=”#FFFFFF” Direction=”-0.612372,-0.5,-0.612372″ />
<DirectionalLight Color=”#FFFFFF” Direction=”0.612372,-0.5,-0.612372″ />
<Model3DGroup x:Name=”BoxOR9″ Transform=”{DynamicResource BoxOR9TR8}”> <!– Box (XAML Path = (Viewport3D.Children)[0].(ModelVisual3D.Content).(Model3DGroup.Children)[3]) –>
<GeometryModel3D x:Name=”BoxOR9GR10″ Geometry=”{DynamicResource BoxOR9GR10}” Material=”{DynamicResource ER___Default_MaterialMR1}” BackMaterial=”{DynamicResource ER___Default_MaterialMR1}”/>
</Model3DGroup>
</Model3DGroup>
</ModelVisual3D.Content>
</ModelVisual3D>
</Viewport3D>
<Slider Height=”31″ HorizontalAlignment=”Left” Margin=”37.5,0,0,8″ Name=”slider1″ VerticalAlignment=”Bottom” Width=”100″ ValueChanged=”slider1_ValueChanged” />
</Grid>
</Window>