Unity's Animation animation resource compression

Source: Internet
Author: User

Recently updated a batch of bone animation resources, do not see, a look at a fright, the previously optimized out of the content will need to be re-processed again, so. Now let's take the previous stuff out and make a note.

Fortunately, the animation has been dynamically loaded, now only need to re-remove the excess information (FBX uses the import settings is legacy| Store in Root (New), and then the animated message is copied out in a separate way), mainly for the following two points:

1) The scale information of skeletal animation is basically useless

2) The float storage accuracy of each bone point information does not require very high precision (except for some animations, depending on the performance effect)

There was a first attempt to manually remove the test effect, but for unity's own reasons, will cause the manual modified Anim file to grow a lot (suspected unity bug) (using the UNITY5.5.2F1 version), the direct use of the program to clean the way it does not have this problem, first directly on the original code:

usingSystem.Collections;usingSystem.Collections.Generic;usingUnityengine;usingUnityeditor; Public classBoneanimoptimizetool {[MenuItem ("window/animationtool/optimize Boneanim")]     Public Static voidOptimizeanim () {varTobjarr =selection.gameobjects; foreach(varObjinchTobjarr)        {Removeanimationcurve (obj); }    }    //Remove Scale     Public Static voidRemoveanimationcurve (Gameobject _obj) {List<AnimationClip> tanimationcliplist =NewList<animationclip>(Animationutility.getanimationclips (_obj)); if(Tanimationcliplist.count = =0) {animationclip[] tobjectlist= UnityEngine.Object.FindObjectsOfType (typeof(Animationclip)) asanimationclip[];      Tanimationcliplist.addrange (tobjectlist); }foreach(Animationclip Animclipinchtanimationcliplist) {foreach(Editorcurvebinding curvebindinginchanimationutility.getcurvebindings (Animclip)) {stringTname =CurveBinding.propertyName.ToLower (); if(Tname.contains (" Scale") {animationutility.seteditorcurve (Animclip, curvebinding,NULL);    }} compressanimationclip (Animclip); }}//Compression Accuracy     Public Static voidCompressanimationclip (Animationclip _clip) {animationclipcurvedata[] Tcurvearr=animationutility.getallcurves (_clip);        Keyframe TKey;        Keyframe[] Tkeyframearr;  for(inti =0; i < tcurvearr.length; ++i) {animationclipcurvedata tcurvedata=Tcurvearr[i]; if(Tcurvedata.curve = =NULL|| TCurveData.curve.keys = =NULL)            {                Continue; } Tkeyframearr=TCurveData.curve.keys;  for(intj =0; J < Tkeyframearr.length; J + +) {TKey=Tkeyframearr[j]; Tkey.value=float. Parse (TKey.value.ToString ("f3"));//#.###Tkey.intangent =float. Parse (TKey.inTangent.ToString ("f3")); Tkey.outtangent=float. Parse (TKey.outTangent.ToString ("f3")); TKEYFRAMEARR[J]=TKey; } TCurveData.curve.keys=Tkeyframearr; _clip.        Setcurve (Tcurvedata.path, Tcurvedata.type, Tcurvedata.propertyname, Tcurvedata.curve); }    }}
For the convenience of each update, the ANIM resource can be automated and can be extended to monitor animation resources and then automate the process.

Unity's Animation animation resource compression

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.