Esempio n. 1
0
        public void OnBeginView()
        {
            try
            {
                if (studio.trimming.isUnifiedForAllViews)
                {
                    unifiedTexBound = new IntegerBound();
                }

                if (studio.packing.on || studio.trimming.isUnifiedForAllViews)
                {
                    frameModelTextures = new Texture2D[frames.Length];
                    framePivots        = new IntegerVector[frames.Length];
                }

                studio.view.checkedSubViews[viewIndex].func(model);
                viewName = studio.view.checkedSubViews[viewIndex].name;

                vecFromCameraToModel = model.transform.position - Camera.main.transform.position;

                Vector3 screenPos = Camera.main.WorldToScreenPoint(model.GetPivotPosition());
                pivot2D = new IntegerVector(screenPos);

                frameIndex = 0;

                stateMachine.ChangeState(BakingState.BeginFrame);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                Finish();
            }
        }
Esempio n. 2
0
        public void OnInitialize()
        {
            try
            {
                OnInitialize_();

                AnimateModel(Frame.BEGIN);

                frameIndex = 0;
                frameTime  = 0.0f;

                Vector3 screenPos = Camera.main.WorldToScreenPoint(model.GetPivotPosition());
                pivot2D = new IntegerVector(screenPos);

                unifiedTexBound = new IntegerBound();

                studio.samplings.Clear();
                ClearAllFrames();

                stateMachine.ChangeState(SamplingState.BeginFrame);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                Finish();
            }
        }
Esempio n. 3
0
        public void OnBeginView()
        {
            try
            {
                int   viewIndexForProgress = viewIndex + 1;
                float progress             = (float)viewIndexForProgress / (float)studio.view.checkedSubViews.Count;

                if (studio.view.checkedSubViews.Count == 0)
                {
                    IsCancelled = EditorUtility.DisplayCancelableProgressBar("Progress...", " (" + ((int)(progress * 100f)) + "%)", progress);
                }
                else
                {
                    IsCancelled = EditorUtility.DisplayCancelableProgressBar("Progress...", "View: " + viewIndexForProgress + " (" + ((int)(progress * 100f)) + "%)", progress);
                }

                if (IsCancelled)
                {
                    throw new Exception("Cancelled");
                }

                studio.view.checkedSubViews[viewIndex].func(model);
                viewName = studio.view.checkedSubViews[viewIndex].name;

                Vector3 screenPos = Camera.main.WorldToScreenPoint(model.GetPivotPosition());
                pivot2D = new IntegerVector(screenPos);

                stateMachine.ChangeState(BakingState.CaptureFrame);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                Finish();
            }
        }
Esempio n. 4
0
 public BakingData(string name, IntegerVector pivot, Texture2D modelTexture, Texture2D normalMapTexture = null)
 {
     this.name             = name;
     this.pivot            = pivot;
     this.modelTexture     = modelTexture;
     this.normalMapTexture = normalMapTexture;
 }
Esempio n. 5
0
 protected void BakeIndividually(Texture2D tex, IntegerVector pivot, string subName, int frame, bool isNormalMap = false)
 {
     try
     {
         string detailName = frame.ToString().PadLeft((frames.Length - 1).ToString().Length, '0');
         BakeIndividually(tex, pivot, subName, detailName, isNormalMap);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Esempio n. 6
0
        public static void MakeUnifiedBound(IntegerVector pivot, IntegerBound bound, IntegerBound unifiedBound)
        {
            if (pivot == null)
            {
                return;
            }

            unifiedBound.min.x = Mathf.Min(unifiedBound.min.x, bound.min.x);
            unifiedBound.max.x = Mathf.Max(unifiedBound.max.x, bound.max.x);
            unifiedBound.min.y = Mathf.Min(unifiedBound.min.y, bound.min.y);
            unifiedBound.max.y = Mathf.Max(unifiedBound.max.y, bound.max.y);
        }
Esempio n. 7
0
        protected void BakeIndividually(Texture2D tex, IntegerVector pivot, string subName, string detailName, bool isNormalMap = false)
        {
            try
            {
                string fileFullName = fileBaseName;
                if (subName.Length > 0)
                {
                    fileFullName += "_" + subName;
                }
                if (detailName.Length > 0)
                {
                    fileFullName += "_" + detailName;
                }
                if (isNormalMap)
                {
                    fileFullName += "_normal";
                }

                string filePath = TextureHelper.SaveTexture(folderPath, fileFullName, tex);

                AssetDatabase.ImportAsset(filePath);

                TextureImporter texImporter = (TextureImporter)AssetImporter.GetAtPath(filePath);
                if (texImporter != null)
                {
                    texImporter.textureType      = (isNormalMap ? TextureImporterType.NormalMap : TextureImporterType.Sprite);
                    texImporter.spriteImportMode = SpriteImportMode.Multiple;

                    SpriteMetaData[] metaData = new SpriteMetaData[1];
                    metaData[0].name      = "0";
                    metaData[0].rect      = new Rect(0.0f, 0.0f, (float)tex.width, (float)tex.height);
                    metaData[0].alignment = (int)SpriteAlignment.Custom;
                    metaData[0].pivot     = new Vector2((float)pivot.x / (float)tex.width,
                                                        (float)pivot.y / (float)tex.height);

                    texImporter.spritesheet = metaData;

                    AssetDatabase.ImportAsset(filePath);
                }

                if (firstSprite == null)
                {
                    firstSprite = AssetDatabase.LoadAssetAtPath <Sprite>(filePath);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Esempio n. 8
0
        public static bool CalcTextureBound(Texture2D tex, IntegerVector pivot, IntegerBound texBound, IntegerBound compactBound)
        {
            if (!CalcValidPixelBound(tex, compactBound))
            {
                return(false);
            }

            texBound.min.x = Mathf.Min(compactBound.min.x, pivot.x);
            texBound.min.y = Mathf.Min(compactBound.min.y, pivot.y);
            texBound.max.x = Mathf.Max(compactBound.max.x, pivot.x);
            texBound.max.y = Mathf.Max(compactBound.max.y, pivot.y);

            return(true);
        }
Esempio n. 9
0
        public void OnBeginView()
        {
            try
            {
                if (studio.trimming.isUnifiedForAllViews)
                {
                    unifiedTexBound = new IntegerBound();
                }

                if (studio.packing.on || studio.trimming.isUnifiedForAllViews)
                {
                    frameModelTextures = new Texture2D[frames.Length];
                    if (studio.output.normalMapMake)
                    {
                        frameNormalMapTextures = new Texture2D[frames.Length];
                    }
                    framePivots = new IntegerVector[frames.Length];
                }

                studio.view.checkedSubViews[viewIndex].func(model);
                viewName = studio.view.checkedSubViews[viewIndex].name;

                modelBaseSizeForView = model.GetSize();

                if (outRootPrefab && model.prefabBuilder.GetBoxCollider2D(outRootPrefab) != null && studio.output.isCompactCollider)
                {
                    frameCompactBounds  = new IntegerBound[frames.Length];
                    frameCompactVectors = new Vector2[frames.Length];
                }

                if (locationMappings != null)
                {
                    foreach (LocationMapping mapping in locationMappings)
                    {
                        mapping.frameLocationPositions = new IntegerVector[frames.Length];
                        mapping.frameRatioPositions    = new Vector2[frames.Length];
                    }
                }

                frameIndex = 0;

                stateMachine.ChangeState(BakingState.BeginFrame);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                Finish();
            }
        }
Esempio n. 10
0
        public void OnBeginFrame()
        {
            try
            {
                int   shownCurrFrameIndex = frameIndex + 1;
                float progress            = (float)(viewIndex * frames.Length + shownCurrFrameIndex) / (studio.view.checkedSubViews.Count * frames.Length);

                if (studio.view.checkedSubViews.Count == 0)
                {
                    IsCancelled = EditorUtility.DisplayCancelableProgressBar("Progress...", "Frame: " + shownCurrFrameIndex + " (" + ((int)(progress * 100f)) + "%)", progress);
                }
                else
                {
                    IsCancelled = EditorUtility.DisplayCancelableProgressBar("Progress...", "View: " + viewName + " | Frame: " + shownCurrFrameIndex + " (" + ((int)(progress * 100f)) + "%)", progress);
                }

                if (IsCancelled)
                {
                    throw new Exception("Cancelled");
                }

                Frame frame = frames[frameIndex];
                meshModel.Animate(animations[AnimationIndex], frame);

                Vector3 pivotScreenPos = Camera.main.WorldToScreenPoint(model.GetPivotPosition());
                pivot2D = new IntegerVector(pivotScreenPos);

                if (locationMappings != null)
                {
                    foreach (LocationMapping mapping in locationMappings)
                    {
                        Vector3 locationScreenPos = Camera.main.WorldToScreenPoint(mapping.location3d.transform.position);
                        mapping.frameLocationPositions[frameIndex] = new IntegerVector(locationScreenPos);
                    }
                }

                stateMachine.ChangeState(BakingState.CaptureFrame);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                Finish();
            }
        }
Esempio n. 11
0
 public void SubtractWithMargin(IntegerVector pos, int margin)
 {
     x -= (pos.x - margin);
     y -= (pos.y - margin);
 }
Esempio n. 12
0
 public IntegerVector(IntegerVector other)
 {
     this.x = other.x;
     this.y = other.y;
 }
Esempio n. 13
0
 public static bool CalcTextureBound(Texture2D tex, IntegerVector pivot, IntegerBound texBound)
 {
     return(CalcTextureBound(tex, pivot, texBound, new IntegerBound()));
 }
Esempio n. 14
0
        public void OnFinalize()
        {
            try
            {
                stateMachine = null;

                if (studio.trimming.isUnifiedForAllViews)
                {
                    TrimToUnifiedSizeAll();
                }

                if (!studio.packing.on && studio.trimming.isUnifiedForAllViews)
                {
                    foreach (BakingData data in bakingDataList)
                    {
                        BakeIndividually(data.modelTexture, data.pivot, data.name, "");
                        if (studio.output.normalMapMake)
                        {
                            BakeIndividually(data.normalMapTexture, data.pivot, data.name, "", true);
                        }
                    }
                }
                else if (studio.packing.on)
                {
                    IntegerVector[] pivots        = new IntegerVector[bakingDataList.Length];
                    string[]        spriteNames   = new string[bakingDataList.Length];
                    Texture2D[]     modelTextures = new Texture2D[bakingDataList.Length];

                    Texture2D[] normalMapTextures = null;
                    if (studio.output.normalMapMake)
                    {
                        normalMapTextures = new Texture2D[bakingDataList.Length];
                    }

                    for (int i = 0; i < bakingDataList.Length; ++i)
                    {
                        BakingData bakingData = bakingDataList[i];
                        pivots[i]        = bakingData.pivot;
                        spriteNames[i]   = bakingData.name;
                        modelTextures[i] = bakingData.modelTexture;
                        if (studio.output.normalMapMake)
                        {
                            normalMapTextures[i] = bakingData.normalMapTexture;
                        }
                    }

                    BakeWithPacking(pivots, "", spriteNames, modelTextures, normalMapTextures);
                }

                if (DoesMakePrefab())
                {
                    GameObject obj = PrefabUtility.InstantiatePrefab(model.spritePrefab) as GameObject;
                    if (obj != null)
                    {
                        if (firstSprite != null)
                        {
                            model.prefabBuilder.BindSprite(obj, firstSprite);
                        }

                        SaveAsPrefab(obj, fileBaseName);
                    }
                }
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }
            finally
            {
                Finish();
            }
        }