3d shape inside 3d shape

hi,
it's amazing...
can i (with the WPF) create a outer shape and inside it an inner shape that "move" inside the 3D space in the outer shap?

thanks,
omri

[190 byte] By [omrivm] at [2007-12-22]
# 1
no one?
omrivm at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 2

Can you describe in more detail what you're trying to accomplish? Perhaps a picture or a .XAML sample of what you've been able to produce so far?

Thanks,

-Adam Smith [MS]

AdamSmithMS at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 3

hi,

my main goal is to create 3d shape (transparent or half-transparent ) that contain another 3d shaps (so when the "big" shape in moving the "small" shaps will move to), of course i'm talking about simple shaps like square and triangle that i can craete in C# only in runtime dynamicly.

for example: 3d box, transparent , that contain 3d column chat, so you can move each column in separate (each side contain another information in about this column. and i can move my big 3d box and show the entire 3d column chat from different angle.

thanks,

omri

omrivm at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 4

(from some reason i cant edit the post so...)

hi,

my main goal is to create 3d shape (transparent or half-transparent ) that contain another 3d shaps (so when the "big" shape in moving the "small" shaps will move to), of course i'm talking about simple shaps like square and triangle that i can craete in C# only in runtime dynamicly.

for example: 3d box, transparent , that contain 3d column chart, so you can move each column in separate (each side contain another information about this column) and you can move the "big" 3d box and show the entire 3d column chart from different angle (that contain another information about the entire column chart).

thanks,

omri

omrivm at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 5

I think there is a WPF sample that shows this exact thing in action. I believe this sample in the WPF gallery is what you are looking for. It is a translucent cube with another translucent cube inside.

I believe the code is included in the download showing how it is done. Hope this helps.

ivolved_Mike_Brown at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 6

maybe,

every time i press "Click to launch" i get: "An error occurred in the application you were using"

"System.InvalidOperationException: Version mismatch. BAML stream has version number '0.80' but parser can read only version '0.94'."

how it can be solved?

when i try to download the code and run it i get: "Cannot create instance of 'Page1' defined in assembly 'CubeApp, Version=1.0.2410.31577, Culture=neutral, PublicKeyToken=null'. Exception has been thrown by the target of an invocation."

In one of the inner eceptions i can see that: "{"'RotateStoryboard' attribute in 'http://schemas.microsoft.com/winfx/2006/xaml' namespace is valid only when used with an IDictionary property. Cannot add element to property 'Resources', because the property can have only one child element if it uses an explicit collection tag. Error at object 'System.Windows.Media.Animation.Storyboard'. Error at object 'System.Windows.Media.Animation.Storyboard'."}" --(inner )--> "{"Cannot add element to property 'Resources', because the property can have only one child element if it uses an explicit collection tag. Error at object 'System.Windows.Media.Animation.Storyboard'."}"

so i can't see the sample... any solution?

omrivm at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 7

Replace the code in Page1.Xaml with this



<Page x:Class="CubeApp.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="3D Cube Animation Demo"
WindowTitle="3D Cube Animation Demo"
Loaded="OnLoaded"
ShowsNavigationUI="False"
>
<Page.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources\Shared.xaml" />
<ResourceDictionary Source="Resources\Button.xaml" />
</ResourceDictionary.MergedDictionaries>
<Storyboard x:Key="RotateStoryboard">
<ParallelTimeline RepeatBehavior="Forever" Storyboard.TargetName="myRotate" Storyboard.TargetProperty="Angle" >
<DoubleAnimation From="0" To="360" Duration="0:0:30"/>
</ParallelTimeline>
</Storyboard>
<MeshGeometry3D x:Key="PlaneMesh"
Positions="-1 -1 0 1 -1 0 -1 1 0 1 1 0"
Normals="0 0 1 0 0 1 0 0 1 0 0 1"
TextureCoordinates="0 1 1 1 0 0 1 0 "
TriangleIndices="0 1 2 1 3 2" />
<MeshGeometry3D x:Key="CubeMesh"
TriangleIndices="0,1,2 3,4,5 6,7,8 9,10,11 12,13,14 15,16,17 18,19,20 21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34,35 "
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,0,-1 0,0,-1 0,0,-1 0,0,-1 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,0 -1,0,0 -1,0,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,0 1,0,0 1,0,0 "
TextureCoordinates="0,1 1,1 1,0 1,0 0,0 0,1 1,1 1,0 0,0 0,0 0,1 1,1 1,1 1,0 0,0 0,0 0,1 1,1 0,1 1,1 1,0 1,0 0,0 0,1 0,0 0,1 1,1 1,1 1,0 0,0 1,0 0,0 0,1 0,1 1,1 1,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 -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 "
/>
<Transform3DGroup x:Key="CubeMeshTransform">
<Transform3DGroup.Children>
<ScaleTransform3D ScaleX="10" ScaleY="10" ScaleZ="10" />
</Transform3DGroup.Children>
</Transform3DGroup>
<Transform3DGroup x:Key="CubeMeshTransform2">
<Transform3DGroup.Children>
<ScaleTransform3D ScaleX="12" ScaleY="12" ScaleZ="12" />
</Transform3DGroup.Children>
</Transform3DGroup>
</ResourceDictionary>

</Page.Resources>
<Grid x:Name="MyGrid" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button Click="OnImage1Animate" Height="50" Grid.Column="0" Grid.Row="0" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="4" >animate</Button>
<Viewport3D Focusable="true" Name="myViewport3D" ClipToBounds="true" Grid.Column="1" Grid.Row="0" >
<Viewport3D.Camera>
<PerspectiveCamera
Position="0,0,3.0"
LookDirection="0,0,-1"
UpDirection="0,1,0"
NearPlaneDistance="0.25"
FarPlaneDistance="20"
FieldOfView="60" />
</Viewport3D.Camera>
<ModelVisual3D>
<ModelVisual3D.Transform>
<Transform3DGroup>
<Transform3DGroup.Children>
<Transform3DCollection >
<ScaleTransform3D ScaleX="1" ScaleY="1" ScaleZ="1" />
<RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Axis="0 1 0" Angle="0" />
</RotateTransform3D.Rotation>
</RotateTransform3D>
<TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0" />
</Transform3DCollection>
</Transform3DGroup.Children>
</Transform3DGroup>
</ModelVisual3D.Transform>
<ModelVisual3D.Content>
<Model3DGroup >
<Model3DGroup.Transform>
<Transform3DGroup>
<Transform3DGroup.Children>
<Transform3DCollection >
<ScaleTransform3D ScaleX="0.1" ScaleY="0.1" ScaleZ="0.1" />
<RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Axis="0 1 0" Angle="0" />
</RotateTransform3D.Rotation>
</RotateTransform3D>
<TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0" />
</Transform3DCollection>
</Transform3DGroup.Children>
</Transform3DGroup>
</Model3DGroup.Transform>
<Model3DGroup.Children>
<!-- Group Child 0 -->
<Model3DGroup >
<Model3DGroup.Transform>
<Transform3DGroup>
<Transform3DGroup.Children>
<Transform3DCollection >
<ScaleTransform3D ScaleX="1" ScaleY="1" ScaleZ="1" />
<RotateTransform3D >
<RotateTransform3D.Rotation >
<AxisAngleRotation3D x:Name="myRotate" Axis="1 0 0" Angle="0" />
</RotateTransform3D.Rotation>
</RotateTransform3D>
<TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0" />
</Transform3DCollection>
</Transform3DGroup.Children>
</Transform3DGroup>
</Model3DGroup.Transform>
<Model3DGroup.Children>
<!-- Child 0 -->
<GeometryModel3D Transform="{StaticResource CubeMeshTransform}" Geometry="{StaticResource CubeMesh}" >
<GeometryModel3D.Material>
<MaterialGroup>
<MaterialGroup.Children>
<EmissiveMaterial>
<EmissiveMaterial.Brush>
<ImageBrush ImageSource="images\roundcornersheet.png">
<ImageBrush.Transform>
<TransformGroup>
<TransformGroup.Children>
<RotateTransform CenterX="0.5" CenterY="0.5" Angle="0" />
</TransformGroup.Children>
</TransformGroup>
</ImageBrush.Transform>
</ImageBrush>
</EmissiveMaterial.Brush>
</EmissiveMaterial>
</MaterialGroup.Children>
</MaterialGroup>
</GeometryModel3D.Material>
<GeometryModel3D.BackMaterial>
<MaterialGroup>
<MaterialGroup.Children>
<EmissiveMaterial>
<EmissiveMaterial.Brush>
<ImageBrush ImageSource="images\roundcornersheet.png">
<ImageBrush.Transform>
<TransformGroup>
<TransformGroup.Children>
<RotateTransform CenterX="0.5" CenterY="0.5" Angle="0" />
</TransformGroup.Children>
</TransformGroup>
</ImageBrush.Transform>
</ImageBrush>
</EmissiveMaterial.Brush>
</EmissiveMaterial>
</MaterialGroup.Children>
</MaterialGroup>
</GeometryModel3D.BackMaterial>
</GeometryModel3D>
<GeometryModel3D Transform="{StaticResource CubeMeshTransform2}" Geometry="{StaticResource CubeMesh}" >
<GeometryModel3D.Material>
<MaterialGroup>
<MaterialGroup.Children>
<EmissiveMaterial>
<EmissiveMaterial.Brush>
<ImageBrush ImageSource="images\roundcornersheet.png">
<ImageBrush.Transform>
<TransformGroup>
<TransformGroup.Children>
<RotateTransform CenterX="0.5" CenterY="0.5" Angle="0" />
</TransformGroup.Children>
</TransformGroup>
</ImageBrush.Transform>
</ImageBrush>
</EmissiveMaterial.Brush>
</EmissiveMaterial>
</MaterialGroup.Children>
</MaterialGroup>
</GeometryModel3D.Material>
<GeometryModel3D.BackMaterial>
<MaterialGroup>
<MaterialGroup.Children>
<EmissiveMaterial>
<EmissiveMaterial.Brush>
<ImageBrush ImageSource="images\roundcornersheet.png">
<ImageBrush.Transform>
<TransformGroup>
<TransformGroup.Children>
<RotateTransform CenterX="0.5" CenterY="0.5" Angle="0" />
</TransformGroup.Children>
</TransformGroup>
</ImageBrush.Transform>
</ImageBrush>
</EmissiveMaterial.Brush>
</EmissiveMaterial>
</MaterialGroup.Children>
</MaterialGroup>
</GeometryModel3D.BackMaterial>
</GeometryModel3D>
</Model3DGroup.Children>
</Model3DGroup>
<Model3DGroup>
<Model3DGroup.Children>
<AmbientLight Color="#ffcccccc"/>
<DirectionalLight Color="LightGray" Direction="-1,-1,-1" />
</Model3DGroup.Children>
</Model3DGroup>
</Model3DGroup.Children>
</Model3DGroup>
</ModelVisual3D.Content>
</ModelVisual3D>
</Viewport3D>
<TextBlock Foreground="White" FontSize="12" FontFamily="Verdana" HoizontalAlignment="Right" VerticalAlignment="Bottom" Grid.Column="1" Margin="4">right click and drag to rotate.</TextBlock>
</Grid>
</Page>

Basically the problem is that if a ResourceDictionary is defined in Page.Resources all of the resources need to be defined within that ResourceDictionary.
ivolved_Mike_Brown at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 8

thank you!

this is exactly what i have been looking for!

Ihave one more question about it: can it done only with C# (without xaml)?

'cuse i want to do this on run-time...

and if so, how?

Thanks again,

Omri

omrivm at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 9

No, Sorry, after I review the sample again i understand that this is not what i was looking for.

Why?

As you can see in the sample there is cube inside a cube - excellent!

But you can move only the entire "big" cube, and what i was looking for is the ability to move the inner cube as well as a separated object.

imagine "big" cube with a lot of inner objects that you can move the entire shap (the "big" cube) but you can move the each small object as well.

Thanks a lot again and sorry for the misapprehension,

Omri

omrivm at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 10

You can set the Transform property on any Model3DGroup to move any part of the scene you wish, whether it's the entire scene or just a small part. If you're using a Visual3D tree for your scene structure (which enables hit testing with more granularity, extensibility, etc), you can set Transform on ModelVisual3D.

-Adam Smith [MS]

AdamSmithMS at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...

Visual Studio Orcas

Site Classified