Showing and Hiding objects
#1
Hi!
We just bought the library professional version and I´d like to say that it`s a fantastic work! Congrats!

But We have a tiny problem showing and hiding objects in the scene.
When I add and ojb to my scene (reader3ds.ReadFile((Stream)obj, MyViewPort3D)) There's no way to hide the object or take it out from the visualtree because when I'm animationg the object I can not manage my own visualtree in the Viewport3D :S

Is there any good solution for this? Because I don't really want to reinstance and reload the whole object :S What is really bad for the performance.

thanks! and great job again!
#2
Hello,

I am glad that you like my importer.

I think I understand your problem.
You are using the Animator class in Reader3ds to animate the read objects. You have used the Read method with MyViewPort3D parameter so the animator can automatically refresh the models.

But you can also do the animation without specifying the MyViewPort3D in the Read method. The trick is to set UseModelTransforms in Reader3ds to true before reading the 3ds file - this also improves the performance of the animation.

For example with the following XAML:
Code:
<Viewport3D Name="MyViewPort3D">
  <ModelVisual3D>
    <ModelVisual3D.Content>
      <Model3DGroup x:Name="MainModelGroup">
      </Model3DGroup>
    </ModelVisual3D.Content>
  </ModelVisual3D>
</Viewport3D>

... you can use the following code:

Code:
// seting UseModelTransforms to true will just update the transformations on the model when animating
reader3ds.UseModelTransforms = true;

Model3DGroup readModel = reader3ds.ReadFile((Stream)obj);

// Add the read 3d model into custom MainModelGroup
MainModelGroup.Children.Clear();
MainModelGroup.Children.Add(readModel);

// Don't forget to set the camera if it is defined in 3ds
MyViewPort3D.Camera = _reader3ds.Cameras[0];

... add the code to start the animation - the models will be updated automatically

Now when you want you can simply clear the MainModelGroup.Children to hide the models.


If you do not set the UseModelTransforms to true, than for each animation frame a completely new Model3DGroup is created. It is also possible to use Animator with this mode. Here use the Model3DGroup that is returned from each DoAnimate method and use it to replace the current content of the MainModelGroup.

I hope this will help you.

To make the Reader3ds even more powerful, try also the Ab3d.PowerToys (see more: http://www.ab4d.com/PowerToys.aspx). With the Ab3d.PowerToys the programming with WPF 3D will be even easier. It contains improved cameras, mouse camera controllers, simplified events management, base 3d objects and 3d lines support.

Andrej

(11-06-2009, 03:30 PM)riacosta Wrote: Hi!
We just bought the library professional version and I´d like to say that it`s a fantastic work! Congrats!

But We have a tiny problem showing and hiding objects in the scene.
When I add and ojb to my scene (reader3ds.ReadFile((Stream)obj, MyViewPort3D)) There's no way to hide the object or take it out from the visualtree because when I'm animationg the object I can not manage my own visualtree in the Viewport3D :S

Is there any good solution for this? Because I don't really want to reinstance and reload the whole object :S What is really bad for the performance.

thanks! and great job again!
#3
Thanks for your really quick answer!

What you're saying was my first try but unfortunately the model doesn't animate :S

I Load the model and set the model3dgroup as a content of a modelvisual3D and I place the modelvisual3d into my viewport. And that's ok, I can see my model in the scene but then when I start my animation (in the compositiontarget rendering event with DoAnimate method) And it doesn't work :S.

And as you said I set UseModelTransforms to true before all of this.

Code:
rd = new Reader3ds();
            rd.UseModelTransforms = true;
            rd.Animator.AutoRepeat = true;
            MainModel = new Model3DGroup();
            Content = MainModel;
            MainModel.Children.Add(rd.ReadFile((Stream)obj));
            CompositionTarget.Rendering +=  new EventHandler(CompositionTarget_Rendering);


void CompositionTarget_Rendering(object sender, EventArgs e)
        {
            rd.Animator.DoAnimate();
        }
#4
Hm, that's strange.

I have also tried it by changing the Animator3ds sample and it worked for me.

I assume that the animation was played when you used reader3ds.ReadFile((Stream)obj, MyViewPort3D).

So I am guessing that you are animating only the camera.

In this case you will have to manually get the animated camera with the following:
Code:
void CompositionTarget_Rendering(object sender, EventArgs e)
        {
            rd.Animator.DoAnimate();
            viewport.Camera = rd.GetCameraForFrame(cameraIndex, rd.Animator.LastFrame);
        }

cameraIndex is the index of the camera in 3ds file.

Setting the camera can be automatically done when the ReadFile method with Viewport3D is used. But without knowing the Viewport3D, the camera cannot be set.

Andrej


(11-06-2009, 05:35 PM)riacosta Wrote: Thanks for your really quick answer!

What you're saying was my first try but unfortunately the model doesn't animate :S

I Load the model and set the model3dgroup as a content of a modelvisual3D and I place the modelvisual3d into my viewport. And that's ok, I can see my model in the scene but then when I start my animation (in the compositiontarget rendering event with DoAnimate method) And it doesn't work :S.

And as you said I set UseModelTransforms to true before all of this.

Code:
rd = new Reader3ds();
            rd.UseModelTransforms = true;
            rd.Animator.AutoRepeat = true;
            MainModel = new Model3DGroup();
            Content = MainModel;
            MainModel.Children.Add(rd.ReadFile((Stream)obj));
            CompositionTarget.Rendering +=  new EventHandler(CompositionTarget_Rendering);


void CompositionTarget_Rendering(object sender, EventArgs e)
        {
            rd.Animator.DoAnimate();
        }
#5
Hi and thanks again for your quick reply!

Unfortunately I'm not using an imported camera, I'm using a normal perspectivecamera defined in XAML.

My animation consists in many objects moving by inverse kinematics (It's a robot caracter moving and doing things :-) )
The animation works perfectly when I use the ReadFile(file,viewport) but, as I told you, I need to hide and show these caracters in the scene(due to app performance) so I need to use readfile(file) as you said.

My structure is something like this:
Code:
public class RobotModel3D : ModelVisual3D
    {
       Reader3ds rd;          
       public RobotModel3D()
        {
            rd = new Reader3ds();
            rd.UseModelTransforms = true;
            Content = (rd.ReadFile((Stream)obj));
            CompositionTarget.Rendering += new EventHandler(CompositionTarget_Rendering);
        }

void CompositionTarget_Rendering(object sender, EventArgs e)
        {
            rd.Animator.DoAnimate();
            rd.RootModel3DGroup.Transform = this.Transform;
        }

}

and then I instance this class in my mainpage and get it into my viewport:
Code:
RobotModel3D r = new RobotModel3D();
                              viewport.Children.Add(r);

With this method I can hide and show my objects but they don't animate :S Am I doing something wrong? Thanks again and sorry for all of these silly questions!
#6
I've found low performance a solution which is re-setting the content each render pass like this:
Code:
void CompositionTarget_Rendering(object sender, EventArgs e)
        {
            Content = rd.Animator.DoAnimate();

        }

Now I can see my animation but of course the performance has got down deeply.
Is there any other solution? I hope so!
Thanks!
#7
Hm, I have run out of ideas.

Is it possible that you send me your code so I can make a closer look at the problem.

The sample can be send to me privately as attachment on my Feedback page (http://www.ab4d.com/Feedback.aspx).

Andrej
  


Forum Jump:


Users browsing this thread:
1 Guest(s)