Esempio n. 1
0
 protected override void OnCaptureFrame_()
 {
     if (studio.shadow.type == ShadowType.Simple && studio.shadow.simple.isDynamicScale)
     {
         ShadowHelper.ScaleSimpleShadowDynamically(modelBaseSize, simpleShadowBaseScale, meshModel, studio);
     }
 }
Esempio n. 2
0
        protected override void Finish_()
        {
            if (studio.shadow.type == ShadowType.TopDown)
            {
                ObjectHelper.DeleteObject(EditorGlobal.STATIC_SHADOW_NAME);
                studio.shadow.obj = ObjectHelper.GetOrCreateObject(EditorGlobal.DYNAMIC_SHADOW_NAME, EditorGlobal.SHADOW_FOLDER_NAME, Vector3.zero);

                ShadowHelper.LocateShadowToModel(particleModel, studio);
            }
        }
Esempio n. 3
0
 protected override void OnCaptureFrame_()
 {
     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);
     }
 }
Esempio n. 4
0
        public void OnInitialize()
        {
            try
            {
                if (studio.view.rotationType == RotationType.Model)
                {
                    CameraHelper.LocateMainCameraToModel(model, studio);
                }

                ShadowHelper.LocateShadowToModel(model, studio);

                if (studio.shadow.type == ShadowType.Simple)
                {
                    ShadowHelper.ScaleSimpleShadow(model, studio);
                }
                else if (studio.shadow.type == ShadowType.TopDown)
                {
                    Camera     camera;
                    GameObject fieldObj;
                    ShadowHelper.GetCameraAndFieldObject(studio.shadow.obj, out camera, out fieldObj);

                    CameraHelper.LookAtModel(camera.transform, model);
                    ShadowHelper.ScaleShadowField(camera, fieldObj);
                }
                else if (studio.shadow.type == ShadowType.Matte)
                {
                    ShadowHelper.ScaleMatteField(meshModel, studio.shadow.obj, studio.lit);
                }

                if (studio.packing.on || studio.trimming.isUnifiedForAllViews)
                {
                    bakingDataList = new BakingData[studio.view.checkedSubViews.Count];
                }

                if (studio.trimming.isUnifiedForAllViews)
                {
                    unifiedTexBound = new IntegerBound();
                }

                fileBaseName = BuildFileBaseName();
                BuildFolderPathAndCreate(modelName);

                viewIndex = 0;

                stateMachine.ChangeState(BakingState.BeginView);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                Finish();
            }
        }
Esempio n. 5
0
        public static void DoCameraFollowing(Model model, Vector3 modelPosition, Vector3 vecFromCameraToModel, Studio studio)
        {
            Camera.main.transform.position = modelPosition - vecFromCameraToModel;

            if (studio.shadow.type == ShadowType.TopDown)
            {
                ShadowHelper.LocateShadowToModel(model, studio);
            }

            if (studio.lit.cameraPositionFollow)
            {
                studio.lit.com.transform.position = Camera.main.transform.position;
            }
        }
Esempio n. 6
0
        protected override void OnInitialize_()
        {
            if (studio.shadow.type == ShadowType.TopDown)
            {
                ObjectHelper.DeleteObject(EditorGlobal.DYNAMIC_SHADOW_NAME);
                studio.shadow.obj = ObjectHelper.GetOrCreateObject(EditorGlobal.STATIC_SHADOW_NAME, EditorGlobal.SHADOW_FOLDER_NAME, Vector3.zero);

                ShadowHelper.LocateShadowToModel(particleModel, studio);

                Camera     camera;
                GameObject fieldObj;
                ShadowHelper.GetCameraAndFieldObject(studio.shadow.obj, out camera, out fieldObj);

                CameraHelper.LookAtModel(camera.transform, particleModel);
                ShadowHelper.ScaleShadowField(camera, fieldObj);
            }
        }
Esempio n. 7
0
        public void OnInitialize()
        {
            try
            {
                if (studio.view.rotationType == RotationType.Model)
                {
                    CameraHelper.LocateMainCameraToModel(model, studio);
                }

                if (studio.shadow.type == ShadowType.TopDown)
                {
                    ObjectHelper.DeleteObject(EditorGlobal.DYNAMIC_SHADOW_NAME);
                    studio.shadow.obj = ObjectHelper.GetOrCreateObject(EditorGlobal.STATIC_SHADOW_NAME, EditorGlobal.SHADOW_FOLDER_NAME, Vector3.zero);

                    ShadowHelper.LocateShadowToModel(model, studio);

                    Camera     camera;
                    GameObject fieldObj;
                    ShadowHelper.GetCameraAndFieldObject(studio.shadow.obj, out camera, out fieldObj);

                    CameraHelper.LookAtModel(camera.transform, model);
                    ShadowHelper.ScaleShadowField(camera, fieldObj);
                }
                else
                {
                    ShadowHelper.LocateShadowToModel(model, studio);
                }

                particleModel.Animate(Frame.BEGIN); // important for particle simulation

                if (particleModel.selectedFrames.Count > 0)
                {
                    frames = new Frame[particleModel.selectedFrames.Count];
                    particleModel.selectedFrames.CopyTo(frames);
                }
                else
                {
                    frames = new Frame[studio.frame.size];
                    for (int i = 0; i < studio.frame.size; ++i)
                    {
                        float frameRatio = 0.0f;
                        if (i > 0 && i < studio.frame.size)
                        {
                            frameRatio = (float)i / (float)(studio.frame.size - 1);
                        }

                        float time = particleModel.GetTimeForRatio(frameRatio);
                        frames[i] = new Frame(i, time);
                    }
                }

                fileBaseName = BuildFileBaseName();
                BuildFolderPathAndCreate(modelName);

                if (studio.packing.on && studio.output.animatorControllerMake)
                {
                    BuildAnimatorController();
                }

                viewIndex = 0;

                stateMachine.ChangeState(BakingState.BeginView);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                Finish();
            }
        }
Esempio n. 8
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();
            }
        }
Esempio n. 9
0
        public void OnInitialize()
        {
            try
            {
                if (studio.view.rotationType == RotationType.Model)
                {
                    CameraHelper.LocateMainCameraToModel(model, studio);
                }

                ShadowHelper.LocateShadowToModel(model, studio);

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

                    CameraHelper.LookAtModel(camera.transform, model);
                    ShadowHelper.ScaleShadowField(camera, fieldObj);
                }
                else if (studio.shadow.type == ShadowType.Matte)
                {
                    ShadowHelper.ScaleMatteField(meshModel, studio.shadow.obj, studio.lit);
                }

                fileNameForModel = BuildFileBaseName();
                BuildFolderPathAndCreate(modelName);

                if (studio.packing.on)
                {
                    if (DoesMakePrefab())
                    {
                        outRootPrefab = PrefabUtility.InstantiatePrefab(model.spritePrefab) as GameObject;
                        outRootPrefab.gameObject.SetActive(false);

                        if (studio.output.DoesMakeLocationPrefab())
                        {
                            Location[] locations = model.GetComponentsInChildren <Location>();
                            if (locations.Length > 0)
                            {
                                locationMappings = new LocationMapping[locations.Length];
                                for (int i = 0; i < locations.Length; ++i)
                                {
                                    Location   loc    = locations[i];
                                    GameObject locObj = PrefabUtility.InstantiatePrefab(studio.output.locationSpritePrefab) as GameObject;
                                    locObj.transform.parent        = model.prefabBuilder.GetLocationsParent(outRootPrefab);
                                    locObj.transform.localPosition = Vector3.zero;
                                    locObj.transform.localRotation = Quaternion.identity;
                                    locObj.name        += "_" + loc.locationName;
                                    locationMappings[i] = new LocationMapping(loc, locObj);
                                }
                            }
                        }

                        if (outRootPrefab != null && studio.output.animatorControllerMake && studio.output.normalMapMake)
                        {
                            animationTextureDataList = new List <AnimationTextureData>();
                        }
                    }
                }

                AnimationIndex = 0;

                stateMachine.ChangeState(BakingState.BeginAnimation);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                Finish();
            }
        }
Esempio n. 10
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();
            }
        }