private void LocateCuttingPoints(Vector3[] cutPoint)
    {
        var mousePos = Input.mousePosition;
        var ray      = Camera.main.ScreenPointToRay(mousePos);
        var hit      = new RaycastHit();

        if (Physics.Raycast(ray, out hit, 100000) && cutPoints.Count < 3)
        {
            tapPoint = hit.point;

            var cutPointOBJ = GameObject.CreatePrimitive(PrimitiveType.Sphere);
            cutPointOBJ.transform.position      = tapPoint;
            cutPointOBJ.transform.parent        = hit.transform;
            cutPointOBJ.transform.localRotation = new Quaternion(0, 0, 0, 0);
            cutPointOBJ.transform.localPosition = new Vector3(0, cutPointOBJ.transform.localPosition.y, 0);
            cutPointOBJ.transform.localScale    = new Vector3(0.05f, 0.05f, 0.05f);
            Destroy(cutPointOBJ.GetComponent <SphereCollider>());

            cutPoints.Add(cutPointOBJ.transform.position);
            cutPointObjects.Add(cutPointOBJ);
            Destroy(hit.collider);

            if (cutPoints.Count == 3)
            {
                if (cutPoints[0].x == cutPoints[1].x && cutPoints[0].x == cutPoints[2].x)
                {
                    CutObject.meshState = MeshState.Invalid;
                }
                else if (cutPoints[0].z == cutPoints[1].z && cutPoints[0].z == cutPoints[2].z)
                {
                    CutObject.meshState = MeshState.Invalid;
                }
                else if (cutPoints[0].y == cutPoints[1].y && cutPoints[0].y == cutPoints[2].y)
                {
                    CutObject.meshState = MeshState.Invalid;
                }
                else
                {
                    CutObject.Cut(cube, material);
                }

                Destroy(cutPointObjects[0]);
                Destroy(cutPointObjects[1]);
                Destroy(cutPointObjects[2]);
            }
        }
    }
Example #2
0
    void ComputeOcclusionQueries(RenderTexture tempBuffer, CutObject cutObject, int cutObjectIndex, int internalState, bool cullProtein, bool cullLipid)
    {
        if (cullProtein)
        {
            // Always clear append buffer before usage
            GPUBuffers.Get.SphereBatches.ClearAppendBuffer();

            //Fill the buffer with occluders
            ComputeShaderManager.Get.SphereBatchCS.SetUniform("_NumInstances", SceneManager.Get.NumProteinInstances);
            ComputeShaderManager.Get.SphereBatchCS.SetBuffer(1, "_ProteinInstanceInfo", GPUBuffers.Get.ProteinInstancesInfo);
            ComputeShaderManager.Get.SphereBatchCS.SetBuffer(1, "_ProteinInstanceCullFlags", GPUBuffers.Get.ProteinInstanceCullFlags);

            ComputeShaderManager.Get.SphereBatchCS.SetBuffer(1, "_IngredientMaskParams", GPUBuffers.Get.IngredientMaskParams);
            ComputeShaderManager.Get.SphereBatchCS.SetBuffer(1, "_OccludeeSphereBatches", GPUBuffers.Get.SphereBatches);
            ComputeShaderManager.Get.SphereBatchCS.Dispatch(1, Mathf.CeilToInt(SceneManager.Get.NumProteinInstances / 64.0f), 1, 1);

            // Count occluder instances
            ComputeBuffer.CopyCount(GPUBuffers.Get.SphereBatches, GPUBuffers.Get.ArgBuffer, 0);

            //DebugSphereBatchCount();

            // Clear protein occlusion buffer
            ComputeShaderManager.Get.ComputeVisibilityCS.SetBuffer(0, "_FlagBuffer", GPUBuffers.Get.ProteinInstanceOcclusionFlags);
            ComputeShaderManager.Get.ComputeVisibilityCS.Dispatch(0, Mathf.CeilToInt(SceneManager.Get.NumProteinInstances / 64.0f), 1, 1);

            // Bind the read/write occlusion buffer to the shader
            // After this draw call the occlusion buffer will be filled with ones if an instance occluded and occludee, zero otherwise
            Graphics.SetRandomWriteTarget(1, GPUBuffers.Get.ProteinInstanceOcclusionFlags);
            MyUtility.DummyBlit();   // Dunny why yet, but without this I cannot write to the buffer from the shader, go figure

            // Set the render target
            Graphics.SetRenderTarget(tempBuffer);

            OcclusionQueriesMaterial.SetInt("_CutObjectIndex", cutObjectIndex);
            OcclusionQueriesMaterial.SetInt("_NumIngredients", SceneManager.Get.NumAllIngredients);
            OcclusionQueriesMaterial.SetBuffer("_CutInfo", GPUBuffers.Get.CutInfo);
            OcclusionQueriesMaterial.SetTexture("_DistanceField", _floodFillTexturePong);

            OcclusionQueriesMaterial.SetFloat("_Scale", GlobalProperties.Get.Scale);
            OcclusionQueriesMaterial.SetBuffer("_ProteinRadii", GPUBuffers.Get.ProteinRadii);
            OcclusionQueriesMaterial.SetBuffer("_ProteinInstanceInfo", GPUBuffers.Get.ProteinInstancesInfo);
            OcclusionQueriesMaterial.SetBuffer("_ProteinInstancePositions", GPUBuffers.Get.ProteinInstancePositions);
            OcclusionQueriesMaterial.SetBuffer("_OccludeeSphereBatches", GPUBuffers.Get.SphereBatches);
            OcclusionQueriesMaterial.SetPass(1);

            // Issue draw call for occluders - bounding quads only - depth/stencil test enabled - no write to color/depth/stencil
            Graphics.DrawProceduralIndirect(MeshTopology.Points, GPUBuffers.Get.ArgBuffer);
            Graphics.ClearRandomWriteTargets();

            ComputeShaderManager.Get.ComputeVisibilityCS.SetUniform("_CutObjectIndex", cutObjectIndex);
            ComputeShaderManager.Get.ComputeVisibilityCS.SetUniform("_NumIngredients", SceneManager.Get.NumAllIngredients);
            ComputeShaderManager.Get.ComputeVisibilityCS.SetBuffer(3, "_CutInfo", GPUBuffers.Get.CutInfo);

            //// Discard occluding instances according to value2
            ComputeShaderManager.Get.ComputeVisibilityCS.SetUniform("_CutObjectId", cutObject.Id);
            ComputeShaderManager.Get.ComputeVisibilityCS.SetUniform("_ConsumeRestoreState", internalState);
            ComputeShaderManager.Get.ComputeVisibilityCS.SetBuffer(3, "_Histograms", GPUBuffers.Get.Histograms);
            ComputeShaderManager.Get.ComputeVisibilityCS.SetBuffer(3, "_HistogramsLookup", GPUBuffers.Get.HistogramsLookup);
            ComputeShaderManager.Get.ComputeVisibilityCS.SetBuffer(3, "_ProteinInstanceInfo", GPUBuffers.Get.ProteinInstancesInfo);
            ComputeShaderManager.Get.ComputeVisibilityCS.SetBuffer(3, "_ProteinInstanceCullFlags", GPUBuffers.Get.ProteinInstanceCullFlags);
            ComputeShaderManager.Get.ComputeVisibilityCS.SetBuffer(3, "_ProteinInstanceOcclusionFlags", GPUBuffers.Get.ProteinInstanceOcclusionFlags);
            ComputeShaderManager.Get.ComputeVisibilityCS.Dispatch(3, Mathf.CeilToInt(SceneManager.Get.NumProteinInstances / 64.0f), 1, 1);
        }

        if (cullLipid)
        {
            // Always clear append buffer before usage
            GPUBuffers.Get.SphereBatches.ClearAppendBuffer();

            //Fill the buffer with occluders
            ComputeShaderManager.Get.SphereBatchCS.SetUniform("_NumInstances", SceneManager.Get.NumLipidInstances);
            ComputeShaderManager.Get.SphereBatchCS.SetBuffer(3, "_LipidInstanceInfo", GPUBuffers.Get.LipidInstancesInfo);
            ComputeShaderManager.Get.SphereBatchCS.SetBuffer(3, "_LipidInstanceCullFlags", GPUBuffers.Get.LipidInstanceCullFlags);

            ComputeShaderManager.Get.SphereBatchCS.SetBuffer(3, "_IngredientMaskParams", GPUBuffers.Get.IngredientMaskParams);
            ComputeShaderManager.Get.SphereBatchCS.SetBuffer(3, "_OccludeeSphereBatches", GPUBuffers.Get.SphereBatches);
            ComputeShaderManager.Get.SphereBatchCS.Dispatch(3, Mathf.CeilToInt(SceneManager.Get.NumLipidInstances / 64.0f), 1, 1);

            // Count occluder instances
            ComputeBuffer.CopyCount(GPUBuffers.Get.SphereBatches, GPUBuffers.Get.ArgBuffer, 0);

            // Clear lipid occlusion buffer
            ComputeShaderManager.Get.ComputeVisibilityCS.SetBuffer(0, "_FlagBuffer", GPUBuffers.Get.LipidInstanceOcclusionFlags);
            ComputeShaderManager.Get.ComputeVisibilityCS.Dispatch(0, Mathf.CeilToInt(SceneManager.Get.NumLipidInstances / 64.0f), 1, 1);

            // Bind the read/write occlusion buffer to the shader
            // After this draw call the occlusion buffer will be filled with ones if an instance occluded and occludee, zero otherwise
            Graphics.SetRandomWriteTarget(1, GPUBuffers.Get.LipidInstanceOcclusionFlags);
            MyUtility.DummyBlit();   // Dunny why yet, but without this I cannot write to the buffer from the shader, go figure

            // Set the render target
            Graphics.SetRenderTarget(tempBuffer);

            OcclusionQueriesMaterial.SetInt("_CutObjectIndex", cutObjectIndex);
            OcclusionQueriesMaterial.SetInt("_NumIngredients", SceneManager.Get.NumAllIngredients);
            OcclusionQueriesMaterial.SetBuffer("_CutInfo", GPUBuffers.Get.CutInfo);
            OcclusionQueriesMaterial.SetTexture("_DistanceField", _floodFillTexturePong);

            OcclusionQueriesMaterial.SetFloat("_Scale", GlobalProperties.Get.Scale);
            OcclusionQueriesMaterial.SetBuffer("_LipidInstanceInfo", GPUBuffers.Get.LipidInstancesInfo);
            OcclusionQueriesMaterial.SetBuffer("_LipidInstancePositions", GPUBuffers.Get.LipidInstancePositions);
            OcclusionQueriesMaterial.SetBuffer("_OccludeeSphereBatches", GPUBuffers.Get.SphereBatches);
            OcclusionQueriesMaterial.SetPass(3);

            // Issue draw call for occluders - bounding quads only - depth/stencil test enabled - no write to color/depth/stencil
            Graphics.DrawProceduralIndirect(MeshTopology.Points, GPUBuffers.Get.ArgBuffer);
            Graphics.ClearRandomWriteTargets();

            ComputeShaderManager.Get.ComputeVisibilityCS.SetUniform("_CutObjectIndex", cutObjectIndex);
            ComputeShaderManager.Get.ComputeVisibilityCS.SetUniform("_NumIngredients", SceneManager.Get.NumAllIngredients);
            ComputeShaderManager.Get.ComputeVisibilityCS.SetBuffer(4, "_CutInfo", GPUBuffers.Get.CutInfo);

            //// Discard occluding instances according to value2
            ComputeShaderManager.Get.ComputeVisibilityCS.SetUniform("_CutObjectId", cutObject.Id);
            ComputeShaderManager.Get.ComputeVisibilityCS.SetUniform("_ConsumeRestoreState", internalState);
            ComputeShaderManager.Get.ComputeVisibilityCS.SetBuffer(4, "_Histograms", GPUBuffers.Get.Histograms);
            ComputeShaderManager.Get.ComputeVisibilityCS.SetBuffer(4, "_HistogramsLookup", GPUBuffers.Get.HistogramsLookup);
            ComputeShaderManager.Get.ComputeVisibilityCS.SetBuffer(4, "_LipidInstanceInfo", GPUBuffers.Get.LipidInstancesInfo);
            ComputeShaderManager.Get.ComputeVisibilityCS.SetBuffer(4, "_LipidInstanceCullFlags", GPUBuffers.Get.LipidInstanceCullFlags);
            ComputeShaderManager.Get.ComputeVisibilityCS.SetBuffer(4, "_LipidInstanceOcclusionFlags", GPUBuffers.Get.LipidInstanceOcclusionFlags);
            ComputeShaderManager.Get.ComputeVisibilityCS.Dispatch(4, Mathf.CeilToInt(SceneManager.Get.NumLipidInstances / 64.0f), 1, 1);
        }
    }
    void ComputeOcclusionQueries(RenderTexture tempBuffer, CutObject cutObject, int cutObjectIndex, int internalState, bool cullProtein, bool cullLipid, bool animated = false)
    {
        if (cullProtein)
        {
            // Always clear append buffer before usage
            GPUBuffers.Instance.SphereBatches.ClearAppendBuffer();

            //Fill the buffer with occluders
            ComputeShaderManager.Instance.SphereBatchCS.SetUniform("_NumInstances", SceneManager.Get.NumProteinInstances);
            ComputeShaderManager.Instance.SphereBatchCS.SetBuffer(1, "_ProteinInstanceInfo", GPUBuffers.Instance.ProteinInstanceInfo);
            ComputeShaderManager.Instance.SphereBatchCS.SetBuffer(1, "_ProteinInstanceCullFlags", GPUBuffers.Instance.ProteinInstanceCullFlags);

            ComputeShaderManager.Instance.SphereBatchCS.SetBuffer(1, "_IngredientMaskParams", GPUBuffers.Instance.IngredientMaskParams);
            ComputeShaderManager.Instance.SphereBatchCS.SetBuffer(1, "_OccludeeSphereBatches", GPUBuffers.Instance.SphereBatches);
            ComputeShaderManager.Instance.SphereBatchCS.Dispatch(1, Mathf.CeilToInt(SceneManager.Get.NumProteinInstances / 64.0f), 1, 1);

            // Count occluder instances
            ComputeBuffer.CopyCount(GPUBuffers.Instance.SphereBatches, GPUBuffers.Instance.ArgBuffer, 0);

            //DebugSphereBatchCount();

            // Clear protein occlusion buffer 
            ComputeShaderManager.Instance.ComputeVisibilityCS.SetBuffer(0, "_FlagBuffer", GPUBuffers.Instance.ProteinInstanceOcclusionFlags);
            ComputeShaderManager.Instance.ComputeVisibilityCS.Dispatch(0, Mathf.CeilToInt(SceneManager.Get.NumProteinInstances / 64.0f), 1, 1);

            // Bind the read/write occlusion buffer to the shader
            // After this draw call the occlusion buffer will be filled with ones if an instance occluded and occludee, zero otherwise
            Graphics.SetRandomWriteTarget(1, GPUBuffers.Instance.ProteinInstanceOcclusionFlags);
            MyUtility.DummyBlit();   // Dunny why yet, but without this I cannot write to the buffer from the shader, go figure

            // Set the render target
            Graphics.SetRenderTarget(tempBuffer);

            OcclusionQueriesMaterial.SetInt("_CutObjectIndex", cutObjectIndex);
            OcclusionQueriesMaterial.SetInt("_NumIngredients", SceneManager.Get.NumAllIngredients);
            OcclusionQueriesMaterial.SetBuffer("_CutInfo", GPUBuffers.Instance.CutInfo);
            OcclusionQueriesMaterial.SetTexture("_DistanceField", _floodFillTexturePong);

            OcclusionQueriesMaterial.SetFloat("_Scale", PersistantSettings.Instance.Scale);
            OcclusionQueriesMaterial.SetBuffer("_ProteinRadii", GPUBuffers.Instance.ProteinRadii);
            OcclusionQueriesMaterial.SetBuffer("_ProteinInstanceInfo", GPUBuffers.Instance.ProteinInstanceInfo);

            if(animated) OcclusionQueriesMaterial.SetBuffer("_ProteinInstancePositions", GPUBuffers.Instance.ProteinAnimationPositions);
            else OcclusionQueriesMaterial.SetBuffer("_ProteinInstancePositions", GPUBuffers.Instance.ProteinInstancePositions);

            OcclusionQueriesMaterial.SetBuffer("_OccludeeSphereBatches", GPUBuffers.Instance.SphereBatches);
            OcclusionQueriesMaterial.SetPass(1);

            // Issue draw call for occluders - bounding quads only - depth/stencil test enabled - no write to color/depth/stencil
            Graphics.DrawProceduralIndirect(MeshTopology.Points, GPUBuffers.Instance.ArgBuffer);
            Graphics.ClearRandomWriteTargets();

            ComputeShaderManager.Instance.ComputeVisibilityCS.SetUniform("_CutObjectIndex", cutObjectIndex);
            ComputeShaderManager.Instance.ComputeVisibilityCS.SetUniform("_NumIngredients", SceneManager.Get.NumAllIngredients);
            ComputeShaderManager.Instance.ComputeVisibilityCS.SetBuffer(3, "_CutInfo", GPUBuffers.Instance.CutInfo);

            //// Discard occluding instances according to value2
            ComputeShaderManager.Instance.ComputeVisibilityCS.SetUniform("_CutObjectId", cutObject.Id);
            ComputeShaderManager.Instance.ComputeVisibilityCS.SetUniform("_ConsumeRestoreState", internalState);
            ComputeShaderManager.Instance.ComputeVisibilityCS.SetBuffer(3, "_Histograms", GPUBuffers.Instance.Histograms);
            ComputeShaderManager.Instance.ComputeVisibilityCS.SetBuffer(3, "_HistogramsLookup", GPUBuffers.Instance.HistogramsLookup);
            ComputeShaderManager.Instance.ComputeVisibilityCS.SetBuffer(3, "_ProteinInstanceInfo", GPUBuffers.Instance.ProteinInstanceInfo);
            ComputeShaderManager.Instance.ComputeVisibilityCS.SetBuffer(3, "_ProteinInstanceCullFlags", GPUBuffers.Instance.ProteinInstanceCullFlags);
            ComputeShaderManager.Instance.ComputeVisibilityCS.SetBuffer(3, "_ProteinInstanceOcclusionFlags", GPUBuffers.Instance.ProteinInstanceOcclusionFlags);
            ComputeShaderManager.Instance.ComputeVisibilityCS.Dispatch(3, Mathf.CeilToInt(SceneManager.Get.NumProteinInstances / 64.0f), 1, 1);
        }

        if (cullLipid)
        {
            // Always clear append buffer before usage
            GPUBuffers.Instance.SphereBatches.ClearAppendBuffer();

            //Fill the buffer with occluders
            ComputeShaderManager.Instance.SphereBatchCS.SetUniform("_NumInstances", SceneManager.Get.NumLipidInstances);
            ComputeShaderManager.Instance.SphereBatchCS.SetBuffer(3, "_LipidInstanceInfo", GPUBuffers.Instance.LipidInstanceInfo);
            ComputeShaderManager.Instance.SphereBatchCS.SetBuffer(3, "_LipidInstanceCullFlags", GPUBuffers.Instance.LipidInstanceCullFlags);

            ComputeShaderManager.Instance.SphereBatchCS.SetBuffer(3, "_IngredientMaskParams", GPUBuffers.Instance.IngredientMaskParams);
            ComputeShaderManager.Instance.SphereBatchCS.SetBuffer(3, "_OccludeeSphereBatches", GPUBuffers.Instance.SphereBatches);
            ComputeShaderManager.Instance.SphereBatchCS.Dispatch(3, Mathf.CeilToInt(SceneManager.Get.NumLipidInstances / 64.0f), 1, 1);

            // Count occluder instances
            ComputeBuffer.CopyCount(GPUBuffers.Instance.SphereBatches, GPUBuffers.Instance.ArgBuffer, 0);

            // Clear lipid occlusion buffer 
            ComputeShaderManager.Instance.ComputeVisibilityCS.SetBuffer(0, "_FlagBuffer", GPUBuffers.Instance.LipidInstanceOcclusionFlags);
            ComputeShaderManager.Instance.ComputeVisibilityCS.Dispatch(0, Mathf.CeilToInt(SceneManager.Get.NumLipidInstances / 64.0f), 1, 1);

            // Bind the read/write occlusion buffer to the shader
            // After this draw call the occlusion buffer will be filled with ones if an instance occluded and occludee, zero otherwise
            Graphics.SetRandomWriteTarget(1, GPUBuffers.Instance.LipidInstanceOcclusionFlags);
            MyUtility.DummyBlit();   // Dunny why yet, but without this I cannot write to the buffer from the shader, go figure

            // Set the render target
            Graphics.SetRenderTarget(tempBuffer);

            OcclusionQueriesMaterial.SetInt("_CutObjectIndex", cutObjectIndex);
            OcclusionQueriesMaterial.SetInt("_NumIngredients", SceneManager.Get.NumAllIngredients);
            OcclusionQueriesMaterial.SetBuffer("_CutInfo", GPUBuffers.Instance.CutInfo);
            OcclusionQueriesMaterial.SetTexture("_DistanceField", _floodFillTexturePong);

            OcclusionQueriesMaterial.SetFloat("_Scale", PersistantSettings.Instance.Scale);
            OcclusionQueriesMaterial.SetBuffer("_LipidInstanceInfo", GPUBuffers.Instance.LipidInstanceInfo);
            OcclusionQueriesMaterial.SetBuffer("_LipidInstancePositions", GPUBuffers.Instance.LipidInstancePositions);
            OcclusionQueriesMaterial.SetBuffer("_OccludeeSphereBatches", GPUBuffers.Instance.SphereBatches);
            OcclusionQueriesMaterial.SetPass(3);

            // Issue draw call for occluders - bounding quads only - depth/stencil test enabled - no write to color/depth/stencil
            Graphics.DrawProceduralIndirect(MeshTopology.Points, GPUBuffers.Instance.ArgBuffer);
            Graphics.ClearRandomWriteTargets();

            ComputeShaderManager.Instance.ComputeVisibilityCS.SetUniform("_CutObjectIndex", cutObjectIndex);
            ComputeShaderManager.Instance.ComputeVisibilityCS.SetUniform("_NumIngredients", SceneManager.Get.NumAllIngredients);
            ComputeShaderManager.Instance.ComputeVisibilityCS.SetBuffer(4, "_CutInfo", GPUBuffers.Instance.CutInfo);

            //// Discard occluding instances according to value2
            ComputeShaderManager.Instance.ComputeVisibilityCS.SetUniform("_CutObjectId", cutObject.Id);
            ComputeShaderManager.Instance.ComputeVisibilityCS.SetUniform("_ConsumeRestoreState", internalState);
            ComputeShaderManager.Instance.ComputeVisibilityCS.SetBuffer(4, "_Histograms", GPUBuffers.Instance.Histograms);
            ComputeShaderManager.Instance.ComputeVisibilityCS.SetBuffer(4, "_HistogramsLookup", GPUBuffers.Instance.HistogramsLookup);
            ComputeShaderManager.Instance.ComputeVisibilityCS.SetBuffer(4, "_LipidInstanceInfo", GPUBuffers.Instance.LipidInstanceInfo);
            ComputeShaderManager.Instance.ComputeVisibilityCS.SetBuffer(4, "_LipidInstanceCullFlags", GPUBuffers.Instance.LipidInstanceCullFlags);
            ComputeShaderManager.Instance.ComputeVisibilityCS.SetBuffer(4, "_LipidInstanceOcclusionFlags", GPUBuffers.Instance.LipidInstanceOcclusionFlags);
            ComputeShaderManager.Instance.ComputeVisibilityCS.Dispatch(4, Mathf.CeilToInt(SceneManager.Get.NumLipidInstances / 64.0f), 1, 1);
        }
    }
Example #4
0
 public override string ToString()
 {
     return(CutObject?.ToString() ?? (ObjectID.ToString() + ": " + Name.ToString()));
 }
Example #5
0
        public void Init(CutObject obj, GameFileCache gfc)
        {
            CutObject = obj;
            ObjectID  = obj?.iObjectId ?? -1;

            if (obj is CutNamedObject nobj)
            {
                Name = nobj.cName;
            }

            if (obj is CutAnimationManagerObject anim)
            {
            }
            else if (obj is CutAssetManagerObject ass)
            {
            }
            else if (obj is CutCameraObject cam)
            {
            }
            else if (obj is CutPedModelObject ped)
            {
                InitPed(ped, gfc);
            }
            else if (obj is CutPropModelObject prop)
            {
                InitProp(prop, gfc);
            }
            else if (obj is CutVehicleModelObject veh)
            {
                InitVehicle(veh, gfc);
            }
            else if (obj is CutWeaponModelObject weap)
            {
                InitWeapon(weap, gfc);
            }
            else if (obj is CutHiddenModelObject hid)
            {
                InitHiddenModel(hid, gfc);
            }
            else if (obj is CutFixupModelObject fix)
            {
            }
            else if (obj is CutRayfireObject rayf)
            {
            }
            else if (obj is CutParticleEffectObject eff)
            {
            }
            else if (obj is CutAnimatedParticleEffectObject aeff)
            {
            }
            else if (obj is CutLightObject light)
            {
            }
            else if (obj is CutAnimatedLightObject alight)
            {
            }
            else if (obj is CutDecalObject dec)
            {
            }
            else if (obj is CutOverlayObject ovr)
            {
            }
            else if (obj is CutAudioObject aud)
            {
            }
            else if (obj is CutSubtitleObject sub)
            {
            }
            else if (obj is CutBlockingBoundsObject blk)
            {
            }
            else if (obj is CutScreenFadeObject fad)
            {
            }
            else
            {
            }
        }
Example #6
0
        void menuItem_Click(object sender, EventArgs e)

        {
            try
            {
                TreeNode      selectedNod = treeView1.SelectedNode;
                var           tag         = selectedNod.Tag;
                ToolStripItem menuItem    = (ToolStripItem)sender;

                if (menuItem.Name == "AddTable")

                {
                    if (tag != null)
                    {
                        if (tag.GetType().Equals(typeof(ArrayList)))
                        {
                            var parent   = (ArrayList)tag;
                            var newtable = inv.NewTable(parent);
                            var newnod   = selectedNod.Nodes.Add("Table");
                            newnod.Tag             = newtable;
                            treeView1.SelectedNode = newnod;
                            newnod.EnsureVisible();
                            treeView1_NodeMouseClick(treeView1, new TreeNodeMouseClickEventArgs(newnod, MouseButtons.Left, 1, 0, 0));
                            return;
                        }
                        if (tag.GetType().Equals(typeof(iTable)))
                        {
                            var parent   = (iTable)tag;
                            var newtable = inv.NewTable(parent.Columns);
                            var newnod   = selectedNod.Nodes.Add("Table");
                            newnod.Tag             = newtable;
                            treeView1.SelectedNode = newnod;
                            newnod.EnsureVisible();
                            treeView1_NodeMouseClick(treeView1, new TreeNodeMouseClickEventArgs(newnod, MouseButtons.Left, 1, 0, 0));
                            return;
                        }
                    }
                }
                if (menuItem.Name == "AddCellColumn")
                {
                    iTable header = treeView1.SelectedNode.Tag as iTable;
                    if (header != null)
                    {
                        var col    = inv.NewColumn(header);
                        var newnod = selectedNod.Nodes.Add(col.Text);
                        newnod.Tag             = col;
                        treeView1.SelectedNode = newnod;
                        newnod.EnsureVisible();
                        treeView1_NodeMouseClick(treeView1, new TreeNodeMouseClickEventArgs(newnod, MouseButtons.Left, 1, 0, 0));
                        //LoadTree();
                    }
                }
                if (menuItem.Name == "AddCellImage")
                {
                    iTable header = treeView1.SelectedNode.Tag as iTable;
                    if (header != null)
                    {
                        string filename = GetImageFile();
                        if (filename == "")
                        {
                            return;
                        }
                        var col    = inv.NewImage(header, filename);
                        var newnod = selectedNod.Nodes.Add("Image");
                        newnod.Tag             = col;
                        treeView1.SelectedNode = newnod;
                        newnod.EnsureVisible();
                        treeView1_NodeMouseClick(treeView1, new TreeNodeMouseClickEventArgs(newnod, MouseButtons.Left, 1, 0, 0));
                        //LoadTree();
                    }
                }
                if (menuItem.Name == "RemoveTable")
                {
                    var    currenNod = treeView1.SelectedNode;
                    iTable header    = currenNod.Tag as iTable;
                    var    parentNod = currenNod.Parent;
                    var    parent    = parentNod.Tag;
                    if (header != null)
                    {
                        if (parent.GetType().Equals(typeof(iTable)))
                        {
                            if (inv.RemoveTable(header, ((iTable)parent).Columns) == true)
                            {
                                currenNod.Remove();
                            }
                        }
                        else
                        {
                            if (inv.RemoveTable(header, parent) == true)
                            {
                                currenNod.Remove();
                            }
                        }

                        //LoadTree();
                    }
                }
                if (menuItem.Name == "RemoveCellColumn")
                {
                    var     currenNod    = treeView1.SelectedNode;
                    iColumn headerColumn = currenNod.Tag as iColumn;
                    iTable  header       = currenNod.Parent.Tag as iTable;
                    if (header != null)
                    {
                        if (headerColumn != null)
                        {
                            if (inv.RemoveColumn(header, headerColumn) == true)
                            {
                                currenNod.Remove();
                                var newnod = treeView1.SelectedNode;
                                treeView1_NodeMouseClick(treeView1, new TreeNodeMouseClickEventArgs(newnod, MouseButtons.Left, 1, 0, 0));
                                //LoadTree();
                            }
                        }
                    }
                }

                if (menuItem.Name == "RemoveCellImage")
                {
                    var    currenNod    = treeView1.SelectedNode;
                    iImage headerColumn = currenNod.Tag as iImage;
                    iTable header       = currenNod.Parent.Tag as iTable;
                    if (header != null)
                    {
                        if (headerColumn != null)
                        {
                            if (inv.RemoveImage(header, headerColumn) == true)
                            {
                                currenNod.Remove();
                                var newnod = treeView1.SelectedNode;
                                treeView1_NodeMouseClick(treeView1, new TreeNodeMouseClickEventArgs(newnod, MouseButtons.Left, 1, 0, 0));
                                //LoadTree();
                            }
                        }
                    }
                }

                if (menuItem.Name == "Cut")
                {
                    var currenNod = treeView1.SelectedNode;
                    if (currenNod.Tag == null)
                    {
                        CutItem = null; return;
                    }
                    ;

                    var    parrentNod  = currenNod.Parent;
                    iTable parentTable = parrentNod.Tag as iTable;
                    if (parentTable == null)
                    {
                        return;
                    }
                    var ind = parentTable.Columns.IndexOf(currenNod.Tag);

                    CutItem = new CutObject()
                    {
                        CutNode = currenNod, CutObjIndex = ind, CutParentobj = parentTable
                    };
                }

                if (menuItem.Name == "Paste")
                {
                    var currenNod = treeView1.SelectedNode;
                    if (currenNod.Tag == null)
                    {
                        throw new Exception("selected item is null");
                    }
                    if (CutItem == null)
                    {
                        throw new Exception("Cut item not found");
                    }
                    var parentNod  = treeView1.SelectedNode.Parent;
                    var parentItem = parentNod.Tag;
                    if (parentItem == null)
                    {
                        throw new Exception("Parent is not found");
                    }
                    //if (parentNod.Text == "Data") throw new Exception("Data section cannot be pasted");
                    //if (!CutItem.CutObj.GetType().Equals(currenNod.Tag.GetType())) throw new Exception("Cut item and paste item do not match");
                    var CutObj = CutItem.CutParentobj.Columns[CutItem.CutObjIndex];
                    if (CutObj.GetType().Equals(typeof(iColumn)) || CutObj.GetType().Equals(typeof(iTable)))
                    {
                        if (CutObj.GetType().Equals(typeof(iTable)) && (parentNod.Text == "Detail Header" || parentNod.Text == "Detail Footer" || parentNod.Text == "Data"))
                        {
                            throw new Exception("Table cannot be paste here");
                        }
                        //{
                        var parenttbl = parentItem as iTable;
                        if (parenttbl == null)
                        {
                            throw new Exception("Parent is not a table");
                        }

                        CutItem.CutParentobj.Columns.RemoveAt(CutItem.CutObjIndex);
                        var arrayIndex = parenttbl.Columns.IndexOf(currenNod.Tag);
                        parenttbl.Columns.Insert(arrayIndex, CutObj);
                        var    nodIndex    = selectedNod.Index;
                        string text        = CutObj.GetType().Equals(typeof(iColumn)) ? ((iColumn)CutObj).Text : "Table";
                        var    insertedNod = parentNod.Nodes.Insert(nodIndex, text);
                        insertedNod.Tag = CutObj;
                        CutItem.CutNode.Parent.Nodes.Remove(CutItem.CutNode);
                        CutItem = null;

                        //}
                    }

                    //if (currenNod.Tag.GetType().Equals(typeof(iTable)))
                    //{
                    //    CutObject = currenNod.Tag as iTable;
                    //}
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }