Exemple #1
0
        private void TrimAll()
        {
            try
            {
                foreach (Sampling sample in studio.samplings)
                {
                    Texture2D trimTex = TextureHelper.TrimTexture(sample.tex, unifiedTexBound, 5, EngineGlobal.CLEAR_COLOR32);

                    if (trimTex.width >= trimTex.height && trimTex.width > MIN_LENGTH)
                    {
                        float ratio         = (float)trimTex.height / (float)trimTex.width;
                        int   newTrimWidth  = MIN_LENGTH;
                        int   newTrimHeight = Mathf.RoundToInt(newTrimWidth * ratio);
                        sample.tex = TextureHelper.ScaleTexture(trimTex, newTrimWidth, newTrimHeight);
                    }
                    else if (trimTex.width < trimTex.height && trimTex.height > MIN_LENGTH)
                    {
                        float ratio         = (float)trimTex.width / (float)trimTex.height;
                        int   newTrimHeight = MIN_LENGTH;
                        int   newTrimWidth  = Mathf.RoundToInt(newTrimHeight * ratio);
                        sample.tex = TextureHelper.ScaleTexture(trimTex, newTrimWidth, newTrimHeight);
                    }
                    else
                    {
                        sample.tex = trimTex;
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Exemple #2
0
        protected void TrimToUnifiedSize(IntegerVector[] pivots, Texture2D[] modelTextures, Texture2D[] normalMapTextures = null)
        {
            try
            {
                Debug.Assert(studio.trimming.isUnifiedForAllViews);

                for (int i = 0; i < modelTextures.Length; ++i)
                {
                    pivots[i].SubtractWithMargin(unifiedTexBound.min, studio.trimming.margin);

                    modelTextures[i] = TextureHelper.TrimTexture(modelTextures[i], unifiedTexBound, studio.trimming.margin, EngineGlobal.CLEAR_COLOR32);
                    if (studio.output.normalMapMake)
                    {
                        Color32 defaultColor = (studio.output.isGrayscaleMap ? EngineGlobal.CLEAR_COLOR32 : EngineGlobal.NORMALMAP_COLOR32);
                        normalMapTextures[i] = TextureHelper.TrimTexture(normalMapTextures[i], unifiedTexBound, studio.trimming.margin, defaultColor, studio.output.normalMapMake);
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Exemple #3
0
        private void TrimToUnifiedSizeAll()
        {
            try
            {
                for (int i = 0; i < bakingDataList.Length; ++i)
                {
                    BakingData bakingData = bakingDataList[i];

                    bakingData.pivot.SubtractWithMargin(unifiedTexBound.min, studio.trimming.margin);

                    bakingData.modelTexture = TextureHelper.TrimTexture(bakingData.modelTexture,
                                                                        unifiedTexBound, studio.trimming.margin, EngineGlobal.CLEAR_COLOR32);
                    if (studio.output.normalMapMake)
                    {
                        bakingData.normalMapTexture = TextureHelper.TrimTexture(bakingData.normalMapTexture,
                                                                                unifiedTexBound, studio.trimming.margin, EngineGlobal.NORMALMAP_COLOR32, true);
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Exemple #4
0
        public void OnCaptureFrame()
        {
            try
            {
                double deltaTime = EditorApplication.timeSinceStartup - prevTime;
                if (deltaTime < studio.frame.delay)
                {
                    return;
                }
                prevTime = EditorApplication.timeSinceStartup;

                if (studio.shadow.type == ShadowType.TopDown)
                {
                    Camera     camera;
                    GameObject fieldObj;
                    ShadowHelper.GetCameraAndFieldObject(studio.shadow.obj, out camera, out fieldObj);
                    ShadowHelper.BakeStaticShadow(camera, fieldObj, particleModel, studio);
                }

                Texture2D tex = CapturingHelper.CaptureModelManagingShadow(model, studio);

                IntegerBound texBound = new IntegerBound();
                if (!TextureHelper.CalcTextureBound(tex, pivot2D, texBound))
                {
                    texBound.min.x = pivot2D.x - 1;
                    texBound.max.x = pivot2D.x + 1;
                    texBound.min.y = pivot2D.y - 1;
                    texBound.max.y = pivot2D.y + 1;
                }

                if (studio.trimming.on)
                {
                    if (studio.trimming.isUnifiedForAllViews)
                    {
                        TextureHelper.MakeUnifiedBound(pivot2D, texBound, unifiedTexBound);
                    }
                    else
                    {
                        pivot2D.SubtractWithMargin(texBound.min, studio.trimming.margin);
                        tex = TextureHelper.TrimTexture(tex, texBound, studio.trimming.margin, EngineGlobal.CLEAR_COLOR32);
                    }
                }

                if (studio.packing.on || studio.trimming.isUnifiedForAllViews)
                {
                    frameModelTextures[frameIndex] = tex;
                    framePivots[frameIndex]        = pivot2D;
                }
                else // !studio.packing.on && !studio.trim.isUnifiedSize
                {
                    BakeIndividually(tex, pivot2D, viewName, frameIndex);
                }

                stateMachine.ChangeState(BakingState.EndFrame);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                Finish();
            }
        }
Exemple #5
0
        public void OnCaptureFrame()
        {
            try
            {
                double deltaTime = EditorApplication.timeSinceStartup - prevTime;
                if (deltaTime < studio.frame.delay)
                {
                    return;
                }
                prevTime = EditorApplication.timeSinceStartup;

                if (studio.shadow.type == ShadowType.Simple && studio.shadow.simple.isDynamicScale)
                {
                    ShadowHelper.ScaleSimpleShadowDynamically(modelBaseSizeForView, simpleShadowBaseScale, meshModel, studio);
                }

                Texture2D modelTexture     = CapturingHelper.CaptureModelManagingShadow(model, studio);
                Texture2D normalMapTexture = null;
                if (studio.output.normalMapMake)
                {
                    normalMapTexture = CapturingHelper.CaptureModelForNormalMap(model, studio.output.isGrayscaleMap, studio.shadow.obj);
                }

                IntegerBound texBound     = new IntegerBound();
                IntegerBound compactBound = new IntegerBound();
                if (!TextureHelper.CalcTextureBound(modelTexture, pivot2D, texBound, compactBound))
                {
                    texBound.min.x = pivot2D.x - 1;
                    texBound.max.x = pivot2D.x + 1;
                    texBound.min.y = pivot2D.y - 1;
                    texBound.max.y = pivot2D.y + 1;
                }

                if (frameCompactBounds != null)
                {
                    frameCompactBounds[frameIndex] = compactBound;
                }

                if (studio.trimming.on)
                {
                    if (studio.trimming.isUnifiedForAllViews)
                    {
                        TextureHelper.MakeUnifiedBound(pivot2D, texBound, unifiedTexBound);
                    }
                    else
                    {
                        pivot2D.SubtractWithMargin(texBound.min, studio.trimming.margin);

                        modelTexture = TextureHelper.TrimTexture(modelTexture, texBound, studio.trimming.margin, EngineGlobal.CLEAR_COLOR32);
                        if (studio.output.normalMapMake)
                        {
                            Color32 defaultColor = (studio.output.isGrayscaleMap ? EngineGlobal.CLEAR_COLOR32 : EngineGlobal.NORMALMAP_COLOR32);
                            normalMapTexture = TextureHelper.TrimTexture(normalMapTexture, texBound, studio.trimming.margin, defaultColor, true);
                        }

                        if (frameCompactBounds != null)
                        {
                            CalcCompactVector(modelTexture, texBound);
                        }

                        if (locationMappings != null)
                        {
                            foreach (LocationMapping mapping in locationMappings)
                            {
                                mapping.frameLocationPositions[frameIndex].SubtractWithMargin(texBound.min, studio.trimming.margin);
                            }
                        }
                    }
                }

                if (studio.packing.on || studio.trimming.isUnifiedForAllViews)
                {
                    framePivots[frameIndex]        = pivot2D;
                    frameModelTextures[frameIndex] = modelTexture;
                    if (studio.output.normalMapMake)
                    {
                        frameNormalMapTextures[frameIndex] = normalMapTexture;
                    }
                }
                else // !studio.packing.on && !studio.trim.isUnifiedSize
                {
                    BakeIndividually(modelTexture, pivot2D, viewName, frameIndex);
                    if (studio.output.normalMapMake)
                    {
                        BakeIndividually(normalMapTexture, pivot2D, viewName, frameIndex, true);
                    }
                }

                stateMachine.ChangeState(BakingState.EndFrame);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                Finish();
            }
        }
Exemple #6
0
        public void OnCaptureFrame()
        {
            try
            {
                double deltaTime = EditorApplication.timeSinceStartup - prevTime;
                if (deltaTime < studio.frame.delay)
                {
                    return;
                }
                prevTime = EditorApplication.timeSinceStartup;

                Texture2D modelTexture     = CapturingHelper.CaptureModelManagingShadow(model, studio);
                Texture2D normalMapTexture = null;
                if (studio.output.normalMapMake)
                {
                    normalMapTexture = CapturingHelper.CaptureModelForNormalMap(model, studio.output.isGrayscaleMap, studio.shadow.obj);
                }

                IntegerBound texBound = new IntegerBound();
                if (!TextureHelper.CalcTextureBound(modelTexture, pivot2D, texBound))
                {
                    texBound.min.x = pivot2D.x - 1;
                    texBound.max.x = pivot2D.x + 1;
                    texBound.min.y = pivot2D.y - 1;
                    texBound.max.y = pivot2D.y + 1;
                }

                if (studio.trimming.on)
                {
                    if (studio.trimming.isUnifiedForAllViews)
                    {
                        TextureHelper.MakeUnifiedBound(pivot2D, texBound, unifiedTexBound);
                    }
                    else
                    {
                        pivot2D.SubtractWithMargin(texBound.min, studio.trimming.margin);

                        modelTexture = TextureHelper.TrimTexture(modelTexture, texBound, studio.trimming.margin, EngineGlobal.CLEAR_COLOR32);
                        if (studio.output.normalMapMake)
                        {
                            Color32 defaultColor = (studio.output.isGrayscaleMap ? EngineGlobal.CLEAR_COLOR32 : EngineGlobal.NORMALMAP_COLOR32);
                            normalMapTexture = TextureHelper.TrimTexture(normalMapTexture, texBound, studio.trimming.margin, defaultColor, true);
                        }
                    }
                }

                string viewName = studio.view.checkedSubViews[viewIndex].name;
                if (studio.packing.on || studio.trimming.isUnifiedForAllViews)
                {
                    bakingDataList[viewIndex] = new BakingData(viewName, pivot2D, modelTexture, normalMapTexture);
                }
                else // !studio.packing.on && !studio.trim.isUnifiedSize
                {
                    BakeIndividually(modelTexture, pivot2D, viewName, "");
                    if (studio.output.normalMapMake)
                    {
                        BakeIndividually(normalMapTexture, pivot2D, viewName, "", true);
                    }
                }

                stateMachine.ChangeState(BakingState.EndView);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                Finish();
            }
        }