(01-04-2013, 11:52 AM)Vidyadhar Wrote: 1) I am able to convert a 3ds model to a string using GetXAML() method. But when I try to render it again it throws an error. On closely looking at the converted string the object names have a space in between them and hence this error. Is there a way I can resolve this. XAML does not take a space for its x:Name property and this is where the error comes from.
This is a bug in Reader3ds 8.3. I am preparing a fix that will be released soon.
(01-04-2013, 11:52 AM)Vidyadhar Wrote: 2) I want to change the color of the model thru. code after I render the 3ds from a XAML stored on the disk. Is it possible and if yes how we can do that.
With WPF it is quite easy to read xaml at runtime with XamlReader.Parse. But unfortunately when the root object in xaml is a 3D object (for example Model3DGroup or Model3DVisual) the names of the objects are not preserved. If the root object is Viewport3D (or probably some other object that derive from FrameworkElement), than you can call FindName on the read object and get the child objects.
I did not find any way to preserver the object names when reading pure xaml text.
However when using .Net 4.0 it is possible to get the object names when reading an xaml that was compiled into assembly (the xaml's BuildAction is Page and Custom Tool is MSBuild:Compile). The following code can be used to read the compiled xaml and than get on object by its name:
Title="MainWindow" Height="350" Width="725">
<!-- Scene camera -->
<PerspectiveCamera FieldOfView="45" NearPlaneDistance="0.125" FarPlaneDistance="Infinity" Position="-841.845062379205,655.098747538281,1468.0171928463" LookDirection="0.469846310392954,-0.342020143325669,-0.813797681349374" UpDirection="0.171010071662834,0.939692620785908,-0.296198132726024"/>
<ModelVisual3D x:Name="RootModelVisual" />
<DirectionalLight Direction="0.469846310392954,-0.342020143325669,-0.813797681349374" Color="White"/>
<Button Name="Button1" VerticalAlignment="Bottom" HorizontalAlignment="Right" Height="30" Click="Button1_OnClick">Change color</Button>
/// Interaction logic for MainWindow.xaml
public partial class MainWindow : Window
private Model3DGroup _rootModel;
private INameScope _modelNameScope;
_rootModel = LoadModel("Resources/HouseWithTrees.xaml", out _modelNameScope) as Model3DGroup;
RootModelVisual.Content = _rootModel;
private static object LoadModel(string uri, out INameScope nameScope)
using (var stream = Application.GetResourceStream(new Uri(uri, UriKind.Relative)).Stream)
var reader = new Baml2006Reader(stream);
var writer = new XamlObjectWriter(reader.SchemaContext);
// We need to save name scope so we can find objects later
nameScope = writer.RootNameScope;
result = writer.Result;
private void Button1_OnClick(object sender, RoutedEventArgs e)
var tree2 = _modelNameScope.FindName("Sphere02") as GeometryModel3D;
tree2.Material = new DiffuseMaterial(Brushes.Red);
This code is reading a file "Resources/HouseWithTrees.xaml". It was created with Viewer3ds with root object set to Model3DGroup.