- Home /
Can I read model-data from assets at runtime via script?
So I want to do some morphing between meshes and skeletons. Do I have to instatiate the assets to get to the data? And is there any way to refer to an asset by its specific type (model) or can you only use GameObject for that?
Answer by cjdev · Aug 22, 2015 at 08:26 PM
As far as I know the only morphing Unity supports is Blend Shapes (other than custom mesh creation and manipulation). Is that what you mean? The only real information you can get from the object would be the number of blend shapes. If that's all you want you could load the GameObject from the Resources folder and get the SkinnedMeshRenderer component to access blendShapeCount.
Yes, I'm building custom meshes and skeletons from several models with the same "layout" (vertices & skeletons) by interpolating between them. Later I will just extract the actual morph-data from them, so I can skip vertices that don't change at all and speed up the morphing process a little. There may be better ways to morph, but this is the best I could come up with for now and it's an easy way to get some at-runtime-flexibility for those online character generators. I'm also thinking about writing code that will translate a morph target for use with a different mesh, using vertex proximity, normals, raycasting and stuff, but that sure won't be easy. It would be nice, however, because otherwise you would have to generate a million different clothing combinations (every piece for every morph).
$$anonymous$$y question was, if I have to instantiate the resource to get the bone-|ex-data. I guess by calling "load", that's what I'm doing, right? $$anonymous$$y other question was, if I can refer to a resource by type model (or texture, audio clip etc.) and not just by GameObject.
You don't necessarily have to instantiate a GameObject into your scene in order to manipulate or access it's data. Loading the object and assigning it to a variable in your script will let you do what you like with it and then you can instantiate it at a later time if you want to (or not). As for loading resources by type, you can cast the resource to it's appropriate type when you load it like this: Resources.Load("$$anonymous$$yTexture") as Texture
. Note that you can't load a GameObject's components though, so you couldn't load a $$anonymous$$eshRenderer from a model for example.
Answer by Thaina · Aug 24, 2015 at 11:59 AM
Sure you can
You would have find mesh object in your model. That contain vertex and index buffer. You can even create your fresh new model in runtime
http://docs.unity3d.com/ScriptReference/Mesh.html
If you don't want to instantiate you could use Resources.Load you would get asset object. But for loading things in runtime you need to put file you want to be loaded in folder named Resources
Most of asset type in unity 5 let you read, manipulate and generate anything at runtime if you could understand the engine. Not an easy task but not so difficult. Have fun
Your answer
Follow this Question
Related Questions
can you make a prefab but without a model? 3 Answers
Site to download models 6 Answers
Model imported at runtime not showing in-game 0 Answers
Free 3d ready model 10 Answers