示例#1
0
        public static void BakeStaticShadow(Camera camera, GameObject fieldObj, Model model, Studio studio)
        {
            if (model == null)
            {
                return;
            }

            camera.CopyFrom(Camera.main);
            camera.targetDisplay = 1;

            camera.targetTexture = new RenderTexture(camera.pixelWidth, camera.pixelHeight, 24, RenderTextureFormat.ARGB32);

            string dirPath        = Path.Combine(Application.dataPath, EngineGlobal.PROJECT_PATH_NAME + "/Shadow");
            int    assetRootIndex = dirPath.IndexOf("Assets");

            if (assetRootIndex < 0)
            {
                Debug.LogError(string.Format("{0} is out of Assets folder.", dirPath));
                return;
            }
            dirPath = dirPath.Substring(assetRootIndex);

            camera.transform.localPosition = new Vector3(0, 500, 0);
            camera.transform.localRotation = Quaternion.Euler(90f, 0f, 0f);
            CameraHelper.LookAtModel(camera.transform, model);

            fieldObj.SetActive(false);
            Texture2D rawTex = CapturingHelper.CaptureModelInCamera(model, camera, studio, true);

            fieldObj.SetActive(true);

            string filePath = TextureHelper.SaveTexture(dirPath, EditorGlobal.STATIC_SHADOW_NAME, rawTex);

            AssetDatabase.ImportAsset(filePath);

            fieldObj.transform.localPosition = Vector3.zero;
            fieldObj.transform.localRotation = Quaternion.Euler(0f, 180f, 0f);
            ScaleShadowField(camera, fieldObj);

            camera.targetTexture = null;
            camera.targetDisplay = 2;
        }
示例#2
0
        public void OnCaptureFrame()
        {
            try
            {
                double deltaTime = EditorApplication.timeSinceStartup - prevTime;
                if (deltaTime < studio.frame.delay)
                {
                    return;
                }
                prevTime = EditorApplication.timeSinceStartup;

                OnCaptureFrame_();

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

                studio.samplings.Add(new Sampling(tex, frameTime));

                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;
                }

                TextureHelper.MakeUnifiedBound(pivot2D, texBound, unifiedTexBound);

                stateMachine.ChangeState(SamplingState.EndFrame);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                Finish();
            }
        }
示例#3
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();
            }
        }
示例#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.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();
            }
        }
示例#5
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();
            }
        }