Exemplo n.º 1
0
        private PickMode PickTriangle(PickMode pickMode)
        {
            if (Camera.current == null)
            {
                return(PickMode.Undecided);
            }

            Ray pickRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);

            int hitTriIndex = -1;

            if (RaycastUtil.Raycast(targetMeshCollider, pickRay, out hitTriIndex, 10000.0f))
            {
                if (currentHullPainter.paintingData.HasActiveHull())
                {
                    Hull hull = currentHullPainter.paintingData.GetActiveHull();
                    if (pickMode == PickMode.Additive)
                    {
                        if (!hull.selectedFaces.Contains(hitTriIndex))
                        {
                            hull.selectedFaces.Add(hitTriIndex);
                        }

                        PickArea(targetMeshCollider, hull, Event.current.mousePosition, true);

                        return(PickMode.Additive);
                    }
                    else if (pickMode == PickMode.Subtractive)
                    {
                        hull.selectedFaces.Remove(hitTriIndex);

                        PickArea(targetMeshCollider, hull, Event.current.mousePosition, false);

                        return(PickMode.Subtractive);
                    }
                    else if (pickMode == PickMode.Undecided)
                    {
                        if (hull.selectedFaces.Contains(hitTriIndex))
                        {
                            hull.selectedFaces.Remove(hitTriIndex);

                            PickArea(targetMeshCollider, hull, Event.current.mousePosition, false);

                            return(PickMode.Subtractive);
                        }
                        else
                        {
                            hull.selectedFaces.Add(hitTriIndex);

                            PickArea(targetMeshCollider, hull, Event.current.mousePosition, true);

                            return(PickMode.Additive);
                        }
                    }
                }
            }

            return(PickMode.Undecided);
        }
Exemplo n.º 2
0
        private void CameraLookEvents()
        { // first person camera
            var cam = Camera.main.transform;
            KeyValuePair <bool, RaycastHit> hitInfo = RaycastUtil.AABB(new Ray(cam.position, cam.forward), 3F);
            BlockInfo raycast = null;

            if (!hitInfo.Key)
            {
                return;
            }
            if (MasterEngine.getInstance().getVoxelEngine().raycastHasVoxel(hitInfo.Value))
            {
                raycast = MasterEngine.getInstance().getVoxelEngine().getVoxelInfo(hitInfo.Value, 3f, false);
            }
            if (raycast != null)
            {
                // create a local copy of the hit voxel so we can call functions on it
                GameObject voxelObject = Instantiate(MasterEngine.getInstance().GetVoxelGameObject(raycast.GetVoxel())) as GameObject;

                // only execute this if the voxel actually has any events (either VoxelEvents component, or any component that inherits from it)
                if (voxelObject.GetComponent <VoxelEvents>() != null)
                {
                    voxelObject.GetComponent <VoxelEvents>().OnLook(raycast);

                    // for all mouse buttons, send events
                    for (int i = 0; i < 3; i++)
                    {
                        if (Input.GetMouseButtonDown(i))
                        {
                            voxelObject.GetComponent <VoxelEvents>().OnMouseDown(i, raycast);
                        }
                        if (Input.GetMouseButtonUp(i))
                        {
                            voxelObject.GetComponent <VoxelEvents>().OnMouseUp(i, raycast);
                        }
                        if (Input.GetMouseButton(i))
                        {
                            voxelObject.GetComponent <VoxelEvents>().OnMouseHold(i, raycast);
                        }
                    }
                }

                Destroy(voxelObject);
            }

            else
            {
                // disable selected block ui when no block is hit
                if (SelectedBlockGraphics != null)
                {
                    SelectedBlockGraphics.GetComponent <Renderer>().enabled = false;
                }
            }
        }
Exemplo n.º 3
0
        private void MouseCursorEvents()
        { // cursor position
            KeyValuePair <bool, RaycastHit> hitInfo = RaycastUtil.AABB(Camera.main.ScreenPointToRay(Input.mousePosition), 2F);
            //Vector3 pos = new Vector3 (Input.mousePosition.x, Input.mousePosition.y, 10.0f);
            BlockInfo raycast = null;

            if (MasterEngine.getInstance().getVoxelEngine().raycastHasVoxel(hitInfo.Value))
            {
                raycast = MasterEngine.getInstance().getVoxelEngine().getVoxelInfo(hitInfo.Value, 2F, false);
            }
            if (raycast != null)
            {
                // create a local copy of the hit voxel so we can call functions on it
                GameObject voxelObject = Instantiate(MasterEngine.getInstance().GetVoxelGameObject(raycast.GetVoxel())) as GameObject;

                // only execute this if the voxel actually has any events (either VoxelEvents component, or any component that inherits from it)
                if (voxelObject.GetComponent <VoxelEvents>() != null)
                {
                    voxelObject.GetComponent <VoxelEvents>().OnLook(raycast);

                    // for all mouse buttons, send events
                    for (int i = 0; i < 3; i++)
                    {
                        if (Input.GetMouseButtonDown(i))
                        {
                            voxelObject.GetComponent <VoxelEvents>().OnMouseDown(i, raycast);
                        }
                        if (Input.GetMouseButtonUp(i))
                        {
                            voxelObject.GetComponent <VoxelEvents>().OnMouseUp(i, raycast);
                        }
                        if (Input.GetMouseButton(i))
                        {
                            voxelObject.GetComponent <VoxelEvents>().OnMouseHold(i, raycast);
                        }
                    }
                }

                Destroy(voxelObject);
            }

            else
            {
                // disable selected block ui when no block is hit

                if (SelectedBlockGraphics != null)
                {
                    SelectedBlockGraphics.GetComponent <Renderer>().enabled = false;
                }
            }
        }
Exemplo n.º 4
0
        private void PickArea(MeshCollider targetMeshCollider, Hull hull, Vector2 clickPos, bool asAdditive)
        {
            int range   = GetBrushPixelSize();
            int numRays = range + 1;

            for (int i = 0; i < numRays; i++)
            {
                Vector2 jitteredPos;

                if (i == 0)
                {
                    jitteredPos = clickPos;
                }
                else
                {
                    jitteredPos = new Vector2(clickPos.x + Random.Range(-range, range), clickPos.y + Random.Range(-range, range));
                }

                Ray pickRay = HandleUtility.GUIPointToWorldRay(jitteredPos);

                int hitTriIndex = -1;
                if (RaycastUtil.Raycast(targetMeshCollider, pickRay, out hitTriIndex, 10000.0f))
                {
                    if (asAdditive)
                    {
                        if (!hull.selectedFaces.Contains(hitTriIndex))
                        {
                            hull.selectedFaces.Add(hitTriIndex);
                        }
                    }
                    else
                    {
                        hull.selectedFaces.Remove(hitTriIndex);
                    }
                }
            }
        }
Exemplo n.º 5
0
        public bool DoMouseDown(PickMode initialMode)
        {
            if (currentToolSelection == ToolSelection.TrianglePainting)
            {
                if (targetMeshCollider != null)
                {
                    if (currentHullPainter != null && currentHullPainter.paintingData != null)
                    {
                        Undo.RecordObject(currentHullPainter.paintingData, "Paint Hull");

                        pickMode = PickTriangle(initialMode);
                        if (pickMode != PickMode.Undecided)
                        {
                            //	Debug.Log ("Start drag");

                            Sync();

                            EditorUtility.SetDirty(currentHullPainter.paintingData);

                            isSelectingFaces = true;

                            return(true);
                        }
                        else
                        {
                            //	Debug.Log ("Abandon drag");
                        }
                    }
                    else
                    {
                        // This can happen when unity triggers scene callbacks in an odd order and the currentHullPainter isn't set yet
                        //	Debug.LogError("SceneManipulator has no currentHullPainter!");
                    }
                }
                else
                {
                    Debug.Log("Mouse down but no targetMeshCollider, ignoring");
                }
            }
            else if (currentToolSelection == ToolSelection.Pipette)
            {
                // Raycast against the target mesh collider and see if the triangle we hit is in any current hull

                bool anyFound = false;

                Ray pickRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);

                int hitTriIndex = -1;
                if (targetMeshCollider != null && RaycastUtil.Raycast(targetMeshCollider, pickRay, out hitTriIndex, 10000.0f))
                {
                    for (int i = 0; i < currentHullPainter.paintingData.hulls.Count; i++)
                    {
                        Hull hull = currentHullPainter.paintingData.hulls[i];
                        if (hull.selectedFaces.Contains(hitTriIndex))
                        {
                            // Now painting this hull!
                            currentHullPainter.paintingData.activeHull = i;
                            currentToolSelection = ToolSelection.TrianglePainting;
                            anyFound             = true;
                            break;
                        }
                    }
                }

                if (!anyFound)
                {
                    currentToolSelection = ToolSelection.TrianglePainting;
                    currentHullPainter.paintingData.activeHull = -1;
                }
            }

            return(false);
        }
Exemplo n.º 6
0
    private bool ToucheMurDroite()
    {
        Bounds bounds = _collider.bounds;

        return(RaycastUtil.TesterCollision2D(bounds.center, Vector2.right, bounds.extents.x, layerSol));
    }
Exemplo n.º 7
0
    private bool EstSurLeSol()
    {
        Bounds bounds = _collider.bounds;

        return(RaycastUtil.TesterCollision2D(bounds.center, Vector2.down, bounds.extents.y, layerSol));
    }