Ejemplo n.º 1
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();
            }
        }
Ejemplo n.º 2
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();
            }
        }