Sign in to follow this  
lennyac

factory method problem

Recommended Posts

lennyac    100
I created 2 model loaders, an MD2 and a RAW Faces model loader. The MD2 model loader can do animations. The RAW model loader can't do animations. I use a factory method to get an instance of the model, for example:
model = modelFactory.LoadModel("test.md2");
or
model = modelFactory.LoadModel("test.raw");
I can then access the methods that apply for both types, such as Draw(); However, if the model is in MD2 format I want to use the Play() (play animation) method. But I'm talking to an interface and can't access it. I want that, if the model is an MD2 I can use the Play() method, but if it's an RAW, the method shouldn't be available. How can I access the method Play()? Do I use the right pattern?

Share this post


Link to post
Share on other sites
Kylotan    9864
Your factory method is creating objects that implement an interface. Therefore, if you want to take objects from that factory and use methods outside of that interface, you are using the wrong factory method.

Either:
- extend the interface to provide the method you want (eg. make Play() exist for RAW, but do nothing)
- create a new interface (eg. AnimatedModel) with the extra method, and a new factory method that only creates AnimatedModels. (This would fail if passed "test.raw".)

Share this post


Link to post
Share on other sites
LorenzoGatti    4442
Maybe you could implement the animation control methods in the RAW model class to display the same still pose at all times, with only one (animated) model interface.

The factory would return a possibly animated model object and you should be calling its animation control methods to treat it uniformly with other models and in the most general way.

Tomorrow, when you improve your assets, you might just replace the still RAW model with a MD2 animated one and it would be animated without additional interface juggling effort.

Can you explain the animation-related methods and metadata of your model objects in more detail?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this