Unity Mecanim Scripting Dynamic Animation - animation

I have a scene with one fully-rigged model of human body
and I would like to users could make their own animations by transforming the model.
I am talking about an app with time-line and possibility of rotating certain muscles.
Could you please recommend me some way how to do that?
I can imagine storing some information about model state in certain times.. but I do not know how to save it as an animation.

You can't edit animations at runtime. You can create an animation from scratch and use AnimationClip.SetCurve to build up your animation, but you can't access the curves directly at runtime.
However in an editor script you can use the AnimationUtilitys to modify an Animationclip, but of course only in the editor since this is an editor class.
Answer picked from this thread.
I think best possible solution for you is to create many different animations for every body part by your own and let user to choose different combinations of animations (if you are using Animator or Animations). Or you can split model by body parts and let user change transform parameters with iTweens (move from A to B and change angle from C to D). Then u can easily save object's "from" transform and object's "to" transform and use it as animation.

Related

Add an event listener to a particular part of a 3D Object in Three.js

I am having a human body object and what I want is that my code should open a popup whenever I click on any of the specified body parts such as eyes, nose, arms, etc. The object is a single compiled .obj file and I'm unable to figure out as to how should I attach an event listener to the multiple body parts. Any kind of help is much appreciated!
PS: - I am also using orbit controls to handle the zoom and rotation of object.
Thanks in advance..
To solve this issue, it's necessary to design your model in a way such that individual components like arms, eyes etc. are independent 3D objects grouped together to build a more complex asset. This is something you have to ensure during the design phase with a tool like Blender.
In the next step export to glTF instead of OBJ, load the model with THREE.GLTFLoader into your app and then perform a recursive raycasting with the entire asset via:
raycaster.intersectObject( gltf.scene, true, intersects );
By executing this code in a pointermove or pointerdown event listener you can find out whether the user interacts with the model or not.
Notice that three.js has no system to directly assign event listeners to 3D objects. You have to use a different solution like raycasting for this.

SceneKit transform/rotate object

I want to create an app using SceneKit with a solid 3D object, whose shape I can change using a given user input. Is it better to do this with predefined animations or to make lots of smaller objects (as nodes) and change their arrangements to mimic a single object changing shape? Many thanks!
Depending on what you mean by 'change shape' you have following options:
If your object is simple (ex: SCNBox, SCNCone, SCNCylinder and alike) and you can change its shape the way you want using its animatable properties (ex: chamfer radius of SCNBox), then animations is simpliest way to go.
If your object is SCNNode with contents loaded from external source and by change its shape you mean scale/rotate/translate, you can also use animations.
If you can create complex object using graph of simple objects with acceptable performance and you can achieve desired shape change with animatable properties then you can also use animations.
If your object is complex (for example, based on some mathematical model) and/or performance is main prioprity for you, then the only way to go with SceneKit is constructing custom SCNGeometries (by filling SCNGeometrySource/SCGeometryElement) from your model.
Since question have tag blender and title mentions rotate, then perhaps (2) is best for you.

animation not playing unity

This appears to be such a common problem, that finding answer to my specific case is near impossible, because of the amount of noise in google or forum searches.
I have imported object to unity from blender. This objects had smaller objects inside it. Those smaller objects have animation on them, which was created in unity. If I open the animation window (Window->Animation) and press play - I can see correct movement of an object. Animation is set to play automatically in inspector, culling type is always animate. If I play the game however, animation does not play. Why?
add the animation to the main object, then animate the smaller object...
you have to put animation component to main object, then animate the small part...
it is important...
it should work
I Could not find any unity inspector based answer. For now, the best option I have is to create new script, and in update() check if the animation is playing. If not, play it. Very inefficient, so to whoever might stumble upon this post in the future, I suggest you try to add this.animation.play() in setting up part of the script.
I know it's kinda late, but this is for others having this same issue.
Animations in Unity have types (2 of which I know).
Type 1 can be attached to an object using the Animation Component.
Type 2 can only be used in Animators (Mechanim).
Animations imported with FBX files are type 2 (and as far as I know, animation type in FBX files can NOT be changed), so they will usually not work when attached directly to an object with "Animation". They should be used with Animators and Animator Controllers. Just create a New Controller and add the animation. It will become the default animation state and play automatically.
If you want it to loop, click on the FBX asset, and in the Animation tab, choose Loop Time and click Apply.

Cocoa control to render a tile map

Is there any Cocoa control that is capable of drawing tile maps with multiple layers and multiple texture sources which can also intercept touches into single tiles? Having multiple layer support is not a real requirement but an optional feature (the views could still be stacked). Hardware acceleration is not needed at all.
So far I have toyed around with NSMatrix, IKImageBrowser and NSCollectionView but non of them felt like a good solution for the problem. Ideally I need an control similar to the one in Tiled.app. Is there anything, third party or built-in, or do I have to handcraft this control?
I fear that you will be hardly able to find a ready-to-use control for managing tile maps.
If I had to implement something like that on my own, I would consider using CATiledLayer, since this is the closest thing to a tile map control that I know of.
From CATiledLayer Reference:
CATiledLayer is a subclass of CALayer providing a way to asynchronously provide tiles of the layer's content, potentially cached at multiple levels of detail.
There is a nice sample by Bill Dudney (the author of "Core Animation for MacOS and the iPhone"). This sample could provide you a solid foundation for your own project, though it only displays one single PDF, allowing you to zoom in the area you clicked on (this requires rereading the tile at a different detail level).
Another interesting introduction can be found here. This is more step-by-step, so you might start with this.
Finally, on Cocoa is my Girlfriend there is a nice article, although it focuses on iOS, but you may find it anyway relevant.
Cocos2D supports building mac applications now
Article on cocos2d stating this: http://www.cocos2d-iphone.org/archives/1444
Aee here for how to do it: http://chris-fletcher.com/tag/cocos2d-os-x/
Aee here on how to use TMX tile maps with Cocos2D to build tile based maps: http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:tiled_maps
This means you can use the power of Cocos2d and you will have to write much less code to get to where you want with a tile based map.
If you don't want to use Cocos2D:
It seems you would have to code it yourself, but it shouldn't be too hard to do.
First you can create your .TMX file using the tile editor "Tiled.app" then you would need to parse the XML using a standard xml library for Cocoa.
To lay out the tiles use a UIView for the overall container and then create a tile class that holds your tile display information and responds to clicks the tile class should extend UIView. For the tile class allow the assigning of a click delegate and assign your ViewController as the click delegate for all tiles so you can handle clicks easily with the clicked tile being passed to you.
Loop through your xml data and create and position the tiles in the overall UIView by using the tiles width/height and your tilemaps rows/columns.
I think in about a day or 2 you could have the tile map being rendered and clickable using the standard TMX format which will allow you to edit your map in "Tiled.app"
The TMX standard is covered here: https://github.com/bjorn/tiled/wiki/TMX-Map-Format
route-me might fit the bill.

Placing objects on scrolling background in XNA

How do I place objects that appear only if the background scrolls to a certain point?
Example- I have this long image that keeps scrolling using the technique above. However, after scrolling to part of the image, I want to add a platform there. How would I do that?
In general, you will probably need to save the locations of your objects in a file and then load that file at the beginning of the level (assuming you are making some kind of platformer game). You can do this by creating a class or a struct containing all the relevant information for the platform (position, size, texture, etc) and then using XML serialization to write an array of those classes/structs to a file.
Your level loader would then load and deserialize the level data, which would end up being a list of all the objects in your level (such as platforms). Now that you have the locations of your platforms in memory you have a couple different options on how to get them to the screen.
Draw all the objects (platforms) all the time, whether or not they are in the view of the camera. If your levels don't contain a lot of objects, this would be simple to implement.
Draw only those in the camera's view. Without knowing how you implemented the horizontal scroller, it's kind of hard to make suggestions for this part. Whatever mechanism you currently have to identify the boundaries of what part of the background to show could be used to determine which objects to draw as well.
I'm working on a game that scrolls vertically right now, and I needed a way to do something similar: place objects in a level and have them appear when the background scrolled to them. I used TorqueX 2D (free engine binaries if you've payed to develop for XNA) and its 2D scene editor to set this up pretty easily. I have my camera scrolling up, the background stays in place. When it gets to an object position defined in the XML level file it spawns the object in the level.

Resources