public void UpdateVisualPercentages(PoissonModeData modeData)
 {
     if (TopMaterial)
     {
         TopMaterial.SetFloat("_PercentageX", modeData.RejectPercentageX);
         TopMaterial.SetFloat("_PercentageZ", modeData.RejectPercentageY);
     }
 }
        public void InitVisual(PoissonModeData modeData, PoissonData data, PoissonPlacer placer, bool isWindow, bool refreshTopMaterial)
        {
            if (!isWindow && HelperVisual && refreshTopMaterial)
            {
                // Always create new TopMaterial, because when we copy the placer, we don't want the TopMaterial shared
                TopMaterial = new Material(TopMaterial);
                UpdateVisualMode(modeData);
            }
            if (!HelperVisual)
            {
                CreateBoxMesh();
                CreateCylinderMesh();

                Shader shader = Shader.Find("Poisson/PoissonHelperShader");
                TopMaterial = new Material(shader);
                TopMaterial.SetColor("_OuterColor", new Color(0.0f, 1.0f, 0.0f, 0.8f));
                TopMaterial.SetColor("_InnerColor", new Color(1.0f, 0.0f, 0.0f, 0.8f));
                TopMaterial.hideFlags = HideFlags.HideInInspector;

                FaceMaterial = new Material(shader);
                FaceMaterial.SetColor("_OuterColor", new Color(0.0f, 1.0f, 0.0f, 0.5f));
                FaceMaterial.SetColor("_InnerColor", new Color(1.0f, 0.0f, 0.0f, 0.5f));
                FaceMaterial.hideFlags = HideFlags.HideInInspector;

                GameObject parentObj = new GameObject();
                if (placer)
                {
                    parentObj.transform.parent = placer.transform;
                    parentObj.transform.SetAsFirstSibling();
                    parentObj.transform.parent        = parentObj.transform;
                    parentObj.transform.localPosition = Vector3.zero;
                    parentObj.transform.localRotation = Quaternion.identity;
                    parentObj.transform.localScale    = Vector3.one;
                }

                HelperVisual = new GameObject();


                HelperVisual.transform.parent = parentObj.transform;

                HelperVisual.gameObject.SetActive(false);

                MeshFilter = HelperVisual.AddComponent <MeshFilter>();

                Renderer = HelperVisual.AddComponent <MeshRenderer>();

                if (!isWindow)
                {
                    DeleteHelper = HelperVisual.AddComponent <PoissonDeleteHelper>();
                }

                RefreshVisual(modeData, data, isWindow);
            }
            if (placer && !isWindow)
            {
                DeleteHelper.Placer = placer;
            }
        }
        public void RefreshVisual(PoissonModeData modeData, PoissonData data, bool isWindow)
        {
            UpdateVisualMode(modeData);
            UpdateVisualPercentages(modeData);
            UpdateVisualTexture(modeData, data);
            UpdateAllowVisualTransformChanges(isWindow);

            HelperVisual.transform.localPosition = modeData.Position;
            HelperVisual.transform.localRotation = modeData.Rotation;
            HelperVisual.transform.localScale    = modeData.Scale;
        }
Exemple #4
0
        private void StoreDataHolder()
        {
            PoissonModeData.Copy(ModeData, DataHolder.ModeData);
            PoissonUIData.Copy(UIData, DataHolder.UIData);

            DataHolder.Data.Resize(Data.Count);
            for (int i = 0; i < Data.Count; ++i)
            {
                PoissonData.Copy(Data[i], DataHolder.Data[i]);
            }
        }
        public void UpdateVisualTexture(PoissonModeData modeData, PoissonData data)
        {
            if (TopMaterial)
            {
                TopMaterial.mainTexture = data.Map;
                TopMaterial.SetInt("_UseMap", (data.Map != null) ? 1 : 0);

                if (modeData.Mode != DistributionMode.Surface)
                {
                    SceneView.RepaintAll();
                }
            }
        }
        public void UpdateVisualMode(PoissonModeData modeData)
        {
            if (!HelperVisual)
            {
                return;
            }
            HelperVisual.gameObject.SetActive(modeData.Mode != DistributionMode.Surface);
            if (modeData.Mode == DistributionMode.Surface)
            {
                return;
            }

            switch (modeData.Mode)
            {
            case DistributionMode.Plane:
                MeshFilter.sharedMesh    = PlaneMesh;
                Renderer.sharedMaterials = new Material[] { TopMaterial };
                TopMaterial.SetInt("_IsEllipse", 0);
                break;

            case DistributionMode.ProjectionPlane:
                MeshFilter.sharedMesh    = BoxMesh;
                Renderer.sharedMaterials = new Material[] { FaceMaterial, TopMaterial };
                TopMaterial.SetInt("_IsEllipse", 0);
                break;

            case DistributionMode.Ellipse:
                MeshFilter.sharedMesh    = EllipseMesh;
                Renderer.sharedMaterials = new Material[] { TopMaterial };
                TopMaterial.SetInt("_IsEllipse", 1);
                break;

            case DistributionMode.ProjectionEllipse:
                MeshFilter.sharedMesh    = CylinderMesh;
                Renderer.sharedMaterials = new Material[] { FaceMaterial, TopMaterial };
                TopMaterial.SetInt("_IsEllipse", 1);
                break;
            }
        }
Exemple #7
0
        public static void Copy(PoissonModeData from, PoissonModeData to)
        {
            to.Mode    = from.Mode;
            to.Surface = from.Surface;

            to.RealtimePreview   = from.RealtimePreview;
            to.RejectPercentageX = from.RejectPercentageX;
            to.RejectPercentageY = from.RejectPercentageY;

            to.Position.x = from.Position.x;
            to.Position.y = from.Position.y;
            to.Position.z = from.Position.z;

            to.Rotation.x = from.Rotation.x;
            to.Rotation.y = from.Rotation.y;
            to.Rotation.z = from.Rotation.z;
            to.Rotation.w = from.Rotation.w;

            to.Scale.x = from.Scale.x;
            to.Scale.y = from.Scale.y;
            to.Scale.z = from.Scale.z;
        }
        public void DestroyVisual(PoissonModeData modeData)
        {
            if (HelperVisual)
            {
                modeData.Position = HelperVisual.transform.localPosition;
                modeData.Rotation = HelperVisual.transform.localRotation;
                modeData.Scale    = HelperVisual.transform.localScale;

                Object.DestroyImmediate(HelperVisual.transform.parent.gameObject);
            }
            HelperVisual = null;
            MeshFilter   = null;
            Renderer     = null;
            DeleteHelper = null;

            EllipseMesh  = null;
            PlaneMesh    = null;
            BoxMesh      = null;
            CylinderMesh = null;

            FaceMaterial = null;
            TopMaterial  = null;
        }