public override void Draw(DebugDraw debugDraw)
        {
            float r = 1000;
            Vec2 p1 = offset * normal + Vec2.Cross(normal, r);
            Vec2 p2 = offset * normal - Vec2.Cross(normal, r);

            Color color = new Color(0,0,0.8f);

            debugDraw.DrawSegment(p1, p2, color);
        }
        public override void Draw(DebugDraw debugDraw)
        {
            float r = 1000;
            Vector2 p1 = Offset * Normal + Normal.CrossScalarPostMultiply(r);
            Vector2 p2 = Offset * Normal - Normal.CrossScalarPostMultiply(r);

            Color color = new Color(0, 0, 0.8f);

            debugDraw.DrawSegment(p1, p2, color);
        }
예제 #3
0
            public void UpdatePresentationState(bool firstUpdate, float deltaTime)
            {
                if (firstUpdate)
                {
                    m_AnimState.turnDirection  = 0;
                    m_AnimState.turnStartAngle = m_AnimState.rotation;
                }

                var aimYawLocal    = Mathf.DeltaAngle(m_AnimState.rotation, m_AnimState.aimYaw);
                var absAimYawLocal = Mathf.Abs(aimYawLocal);

                if (m_AnimState.turnDirection == 0)
                {
                    if (absAimYawLocal > m_Settings.aimTurnLocalThreshold)
                    {
                        m_AnimState.turnStartAngle = m_AnimState.rotation;
                        m_AnimState.turnDirection  = Mathf.Sign(aimYawLocal);
                    }
                }

                float absAngleRemaining = 0f;

                if (m_AnimState.turnDirection != 0)
                {
                    var rotateAngleRemaining = Mathf.DeltaAngle(m_AnimState.rotation, m_AnimState.turnStartAngle) + m_Settings.animTurnAngle * m_AnimState.turnDirection;

                    if (rotateAngleRemaining * m_AnimState.turnDirection <= 0)
                    {
                        m_AnimState.turnDirection = 0;
                    }
                    else
                    {
                        var turnSpeed = m_Settings.turnSpeed;
                        if (absAimYawLocal > m_Settings.turnThreshold)
                        {
                            var factor = 1.0f - (180 - absAimYawLocal) / m_Settings.turnThreshold;
                            turnSpeed = turnSpeed + factor * 300;
                        }

                        var deltaAngle = deltaTime * turnSpeed;
                        absAngleRemaining = Mathf.Abs(rotateAngleRemaining);
                        if (deltaAngle > absAngleRemaining)
                        {
                            deltaAngle = absAngleRemaining;
                        }

                        var sign = Mathf.Sign(rotateAngleRemaining);

                        m_AnimState.rotation += sign * deltaAngle;
                        while (m_AnimState.rotation > 360.0f)
                        {
                            m_AnimState.rotation -= 360.0f;
                        }
                        while (m_AnimState.rotation < 0.0f)
                        {
                            m_AnimState.rotation += 360.0f;
                        }
                    }
                }


                if (m_Settings.footIK.enabled)
                {
                    var footIkJob = m_FootIk.GetJobData <FootIkJob>();
                    if (m_PredictedState.velocity.magnitude > 0.001f)
                    {
                        m_StandState = StandState.Moving;
                    }
                    else if (m_AnimState.turnDirection != 0 && m_StandState != StandState.TurnStart && m_StandState != StandState.Turning)
                    {
                        m_StandState = StandState.TurnStart;
                    }
                    else if (m_AnimState.turnDirection != 0)
                    {
                        m_StandState = StandState.Turning;
                    }
                    else if (m_AnimState.turnDirection == 0 && m_StandState == StandState.Turning)
                    {
                        m_StandState = StandState.TurnEnd;
                    }
                    else
                    {
                        m_StandState = StandState.Standing;
                    }

                    if (m_StandState == StandState.Moving || firstUpdate)
                    {
                        var rotation = Quaternion.Euler(0f, m_AnimState.rotation, 0f);
                        m_LeftFootPos  = rotation * m_Settings.footIK.leftToeStandPos + m_AnimState.position;
                        m_RightFootPos = rotation * m_Settings.footIK.rightToeStandPos + m_AnimState.position;
                    }
                    else if (m_StandState == StandState.TurnStart)
                    {
                        var predictedRotation = Quaternion.Euler(0f, m_AnimState.turnStartAngle + m_Settings.animTurnAngle * m_AnimState.turnDirection, 0f);
                        m_LeftFootPos  = predictedRotation * m_Settings.footIK.leftToeStandPos + m_AnimState.position;
                        m_RightFootPos = predictedRotation * m_Settings.footIK.rightToeStandPos + m_AnimState.position;
                    }

                    if (m_StandState == StandState.Moving || m_StandState == StandState.TurnStart)
                    {
                        var rayEmitOffset  = Vector3.up * m_Settings.footIK.emitRayOffset;
                        var maxRayDistance = m_Settings.footIK.emitRayOffset + m_Settings.footIK.maxRayDistance;
                        m_LeftHitSuccess  = Physics.Raycast(m_LeftFootPos + rayEmitOffset, Vector3.down, out m_LeftHit, maxRayDistance, m_Mask);
                        m_RightHitSuccess = Physics.Raycast(m_RightFootPos + rayEmitOffset, Vector3.down, out m_RightHit, maxRayDistance, m_Mask);
                    }

                    if (firstUpdate)
                    {
                        footIkJob.ikWeight = 0.0f;
                    }

                    if (m_StandState == StandState.Moving || m_StandState == StandState.TurnEnd)
                    {
                        m_AnimState.footIkOffset     = GetClampedOffset();
                        m_AnimState.footIkNormalLeft = m_LeftHit.normal;
                        m_AnimState.footIkNormaRight = m_RightHit.normal;

                        m_TurnStartOffset.x   = m_AnimState.footIkOffset.x;
                        m_TurnStartOffset.y   = m_AnimState.footIkOffset.y;
                        m_TurnStartNormals[0] = m_LeftHit.normal;
                        m_TurnStartNormals[1] = m_RightHit.normal;
                    }
                    else if (m_StandState == StandState.TurnStart)
                    {
                        m_TurnEndOffset     = GetClampedOffset();
                        m_TurnEndNormals[0] = m_LeftHit.normal;
                        m_TurnEndNormals[1] = m_RightHit.normal;
                    }

                    if (m_StandState == StandState.TurnStart || m_StandState == StandState.Turning)
                    {
                        var turnFraction = (-absAngleRemaining + m_Settings.animTurnAngle) / m_Settings.animTurnAngle;
                        var footFalls    = m_AnimState.turnDirection == -1 ? m_LeftTurnFootFalls : m_RightTurnFootFalls;

                        var leftFootFraction = GetFootFraction(turnFraction, footFalls.leftFootUp, footFalls.leftFootDown);
                        m_AnimState.footIkOffset.x   = Mathf.Lerp(m_TurnStartOffset.x, m_TurnEndOffset.x, leftFootFraction);
                        m_AnimState.footIkNormalLeft = Vector3.Lerp(m_TurnStartNormals[0], m_TurnEndNormals[0], leftFootFraction);

                        var rightFootFraction = GetFootFraction(turnFraction, footFalls.rightFootUp, footFalls.rightFootDown);
                        m_AnimState.footIkOffset.y   = Mathf.Lerp(m_TurnStartOffset.y, m_TurnEndOffset.y, rightFootFraction);
                        m_AnimState.footIkNormaRight = Vector3.Lerp(m_TurnStartNormals[1], m_TurnEndNormals[1], rightFootFraction);
                    }

#if UNITY_EDITOR
                    footIkJob.settings = m_Settings.footIK;
                    if (m_Settings.footIK.debugRayCast)
                    {
                        DebugDraw.Sphere(m_LeftFootPos, 0.025f, Color.yellow);
                        DebugDraw.Sphere(m_RightFootPos, 0.025f, Color.yellow);

                        DebugDraw.Sphere(m_LeftHit.point, 0.015f);
                        DebugDraw.Sphere(m_RightHit.point, 0.015f);

                        Debug.DrawLine(m_LeftHit.point, m_LeftHit.point + m_LeftHit.normal, Color.green);
                        Debug.DrawLine(m_RightHit.point, m_RightHit.point + m_RightHit.normal, Color.red);
                    }
#endif
                    m_FootIk.SetJobData(footIkJob);
                }
            }
예제 #4
0
        void UploadBlueprint()
        {
            if (_blueprint == null)
            {
                return;
            }

            var buildingManager = gameObject.GetSystem <IBuildingSystem>();

            var buildPosition = Camera.main.transform.position + Camera.main.transform.rotation * Vector3.forward * 3f;
            var buildRotation = Quaternion.AngleAxis(Camera.main.transform.rotation.eulerAngles.y, Vector3.up);

            DebugDraw.DrawMarker(buildPosition, 0.25f, Color.blue);

            _blueprint.transform.position = buildPosition;
            _blueprint.transform.rotation = buildRotation;

            BuildingSlot closestSlot = null;
            var          occupied    = false;
            var          building    = buildingManager.GetBuildingInRange(buildPosition, 3f);

            if (building != null)
            {
                float closestDistance = float.MaxValue;

                var sockets = _blueprint.GetComponentsInChildren <BuildingSocket>();
                foreach (var socket in sockets)
                {
                    float distance;
                    var   slot = building.GetClosestSlot(socket.transform.position, socket.slotType, true, out distance);
                    if (slot == null)
                    {
                        continue;
                    }

                    if (distance < 0.25f && distance < closestDistance)
                    {
                        closestDistance = distance;
                        closestSlot     = slot;
                    }
                }

                if (closestSlot != null)
                {
                    buildPosition = closestSlot.transform.position;
                    buildRotation = closestSlot.transform.rotation;
                    occupied      = !building.IsSlotFree(closestSlot);
                }
            }
            _blueprint.transform.position = buildPosition + Vector3.up * 0.025f;
            _blueprint.transform.rotation = buildRotation;
            _blueprint.GetComponent <Renderer>().sharedMaterial = !occupied ? blueprintMaterial : occupiedBlueprintMaterial;

            //
            var canBuild = (_currentPartType.canCreateNewBuilding && building == null || closestSlot != null) && !occupied;

            if (canBuild && Input.GetMouseButton(0))
            {
                if (building == null)
                {
                    //building = buildingManager.CreateBuilding(_buildingType, buildPosition, buildRotation);
                }
                building.AddPart(_currentPartType, closestSlot);
                building.Rebuild();
            }

            //
            if (building != null && Input.GetMouseButtonDown(1))
            {
                var partIdx = building.GetClosestPartIdx(buildPosition);
                if (partIdx != -1)
                {
                    building.RemovePart(partIdx);
                    building.Rebuild();
                }
            }
        }
예제 #5
0
    public static Vector3 ClosestPointOnSurface(TerrainCollider collider, Vector3 to, float radius, bool debug = false)
    {
        TerrainData terrainData = collider.terrainData;

        Vector3 local = collider.transform.InverseTransformPoint(to);

        // Calculate the size of each tile on the terrain horizontally and vertically.
        float pixelSizeX = terrainData.size.x / (terrainData.heightmapResolution - 1);
        float pixelSizeZ = terrainData.size.z / (terrainData.heightmapResolution - 1);

        float percentZ = Mathf.Clamp01(local.z / terrainData.size.z);
        float percentX = Mathf.Clamp01(local.x / terrainData.size.x);

        float positionX = percentX * (terrainData.heightmapResolution - 1);
        float positionZ = percentZ * (terrainData.heightmapResolution - 1);

        // Calculate our position, in tiles, on the terrain.
        int pixelX = Mathf.FloorToInt(positionX);
        int pixelZ = Mathf.FloorToInt(positionZ);

        // Calculate the distance from our point to the edge of the tile we are in.
        float distanceX = (positionX - pixelX) * pixelSizeX;
        float distanceZ = (positionZ - pixelZ) * pixelSizeZ;

        // Find out how many tiles we are overlapping on the X plane.
        float radiusExtentsLeftX  = radius - distanceX;
        float radiusExtentsRightX = radius - (pixelSizeX - distanceX);

        int overlappedTilesXLeft  = radiusExtentsLeftX > 0 ? Mathf.FloorToInt(radiusExtentsLeftX / pixelSizeX) + 1 : 0;
        int overlappedTilesXRight = radiusExtentsRightX > 0 ? Mathf.FloorToInt(radiusExtentsRightX / pixelSizeX) + 1 : 0;

        // Find out how many tiles we are overlapping on the Z plane.
        float radiusExtentsLeftZ  = radius - distanceZ;
        float radiusExtentsRightZ = radius - (pixelSizeZ - distanceZ);

        int overlappedTilesZLeft  = radiusExtentsLeftZ > 0 ? Mathf.FloorToInt(radiusExtentsLeftZ / pixelSizeZ) + 1 : 0;
        int overlappedTilesZRight = radiusExtentsRightZ > 0 ? Mathf.FloorToInt(radiusExtentsRightZ / pixelSizeZ) + 1 : 0;

        // Retrieve the heights of the pixels we are testing against.
        int startPositionX = pixelX - overlappedTilesXLeft;
        int startPositionZ = pixelZ - overlappedTilesZLeft;

        int numberOfXPixels = overlappedTilesXRight + overlappedTilesXLeft + 1;
        int numberOfZPixels = overlappedTilesZRight + overlappedTilesZLeft + 1;

        // Account for if we are off the terrain.
        if (startPositionX < 0)
        {
            numberOfXPixels -= Mathf.Abs(startPositionX);
            startPositionX   = 0;
        }

        if (startPositionZ < 0)
        {
            numberOfZPixels -= Mathf.Abs(startPositionZ);
            startPositionZ   = 0;
        }

        if (startPositionX + numberOfXPixels + 1 > terrainData.heightmapResolution)
        {
            numberOfXPixels = terrainData.heightmapResolution - startPositionX - 1;
        }

        if (startPositionZ + numberOfZPixels + 1 > terrainData.heightmapResolution)
        {
            numberOfZPixels = terrainData.heightmapResolution - startPositionZ - 1;
        }

        // Retrieve the heights of the tile we are in and all overlapped tiles.
        float[,] heights = terrainData.GetHeights(startPositionX, startPositionZ, numberOfXPixels + 1, numberOfZPixels + 1);

        // Pre-scale the heights data to be world-scale instead of 0...1.
        for (int i = 0; i < numberOfXPixels + 1; i++)
        {
            for (int j = 0; j < numberOfZPixels + 1; j++)
            {
                heights[j, i] *= terrainData.size.y;
            }
        }

        // Find the shortest distance to any triangle in the set gathered.
        float shortestDistance = float.MaxValue;

        Vector3 shortestPoint = Vector3.zero;

        for (int x = 0; x < numberOfXPixels; x++)
        {
            for (int z = 0; z < numberOfZPixels; z++)
            {
                // Build the set of points that creates the two triangles that form this tile.
                Vector3 a = new Vector3((startPositionX + x) * pixelSizeX, heights[z, x], (startPositionZ + z) * pixelSizeZ);
                Vector3 b = new Vector3((startPositionX + x + 1) * pixelSizeX, heights[z, x + 1], (startPositionZ + z) * pixelSizeZ);
                Vector3 c = new Vector3((startPositionX + x) * pixelSizeX, heights[z + 1, x], (startPositionZ + z + 1) * pixelSizeZ);
                Vector3 d = new Vector3((startPositionX + x + 1) * pixelSizeX, heights[z + 1, x + 1], (startPositionZ + z + 1) * pixelSizeZ);


                BSPTree.ClosestPointOnTriangleToPoint(ref a, ref d, ref c, ref local, out Vector3 nearest);

                float distance = (local - nearest).sqrMagnitude;

                if (distance <= shortestDistance)
                {
                    shortestDistance = distance;
                    shortestPoint    = nearest;
                }

                BSPTree.ClosestPointOnTriangleToPoint(ref a, ref b, ref d, ref local, out nearest);

                distance = (local - nearest).sqrMagnitude;

                if (distance <= shortestDistance)
                {
                    shortestDistance = distance;
                    shortestPoint    = nearest;
                }

                if (debug)
                {
                    DebugDraw.DrawTriangle(a, d, c, Color.cyan);
                    DebugDraw.DrawTriangle(a, b, d, Color.red);
                }
            }
        }

        return(collider.transform.TransformPoint(shortestPoint));
    }
예제 #6
0
파일: NavDebug.cs 프로젝트: zwong91/Titan
        /// <summary>
        /// Draws a debug visualization of an individual navmesh tile.
        /// </summary>
        /// <remarks>
        /// <para>
        /// The tile will be checked to see if it is in use before it is drawn.  So there is no
        /// need for caller to do so.
        /// </para>
        /// </remarks>
        private static void Draw(NavmeshTile tile
                                 , NavmeshQuery query, uint[] markPolys, int markPolyCount
                                 , int colorId)
        {
            NavmeshTileHeader header = tile.GetHeader();

            // Keep this check.  Less trouble for clients.
            if (header.polyCount < 1)
            {
                return;
            }

            DebugDraw.SimpleMaterial.SetPass(0);

            uint polyBase = tile.GetBasePolyRef();

            NavmeshPoly[] polys = new NavmeshPoly[header.polyCount];
            tile.GetPolys(polys);

            Vector3[] verts = new Vector3[header.vertCount];
            tile.GetVerts(verts);

            NavmeshDetailMesh[] meshes =
                new NavmeshDetailMesh[header.detailMeshCount];
            tile.GetDetailMeshes(meshes);

            byte[] detailTris = new byte[header.detailTriCount * 4];
            tile.GetDetailTris(detailTris);

            Vector3[] detailVerts = new Vector3[header.detailVertCount];
            tile.GetDetailVerts(detailVerts);

            GL.Begin(GL.TRIANGLES);
            for (int i = 0; i < header.polyCount; i++)
            {
                NavmeshPoly poly = polys[i];

                if (poly.Type == NavmeshPolyType.OffMeshConnection)
                {
                    continue;
                }

                NavmeshDetailMesh mesh = meshes[i];

                Color color = GetStandardColor(polyBase | (uint)i
                                               , poly.Area, colorId
                                               , query, markPolys, markPolyCount);

                GL.Color(color);

                for (int j = 0; j < mesh.triCount; j++)
                {
                    int pTri = (int)(mesh.triBase + j) * 4;

                    for (int k = 0; k < 3; k++)
                    {
                        // Note: iVert and pVert refer to different
                        // arrays.
                        int iVert = detailTris[pTri + k];
                        if (iVert < poly.vertCount)
                        {
                            // Get the vertex from the main vertices.
                            int pVert = poly.indices[iVert];
                            GL.Vertex(verts[pVert]);
                        }
                        else
                        {
                            // Get the vertex from the detail vertices.
                            int pVert = (int)
                                        (mesh.vertBase + iVert - poly.vertCount);
                            GL.Vertex(detailVerts[pVert]);
                        }
                    }
                }
            }
            GL.End();

            NavmeshLink[] links = new NavmeshLink[header.maxLinkCount];
            tile.GetLinks(links);

            GL.Begin(GL.LINES);

            DrawPolyBoundaries(header
                               , polys
                               , verts
                               , meshes
                               , detailTris
                               , detailVerts
                               , links
                               , new Color(0, 0.2f, 0.25f, 0.13f)
                               , true);

            DrawPolyBoundaries(header
                               , polys
                               , verts
                               , meshes
                               , detailTris
                               , detailVerts
                               , links
                               , new Color(0.65f, 0.2f, 0, 0.9f)
                               , false);

            if (header.connCount == 0)
            {
                GL.End();
                return;
            }

            NavmeshConnection[] conns = new NavmeshConnection[header.connCount];
            tile.GetConnections(conns);

            for (int i = 0; i < header.polyCount; i++)
            {
                NavmeshPoly poly = polys[i];

                if (poly.Type != NavmeshPolyType.OffMeshConnection)
                {
                    continue;
                }

                Color color = GetStandardColor(polyBase | (uint)i
                                               , poly.Area, colorId
                                               , query, markPolys, markPolyCount);

                // Note: Alpha of less than one doesn't look good because connections tend to
                // overlay a lot of geometry, resulting is off color transitions.
                color.a = 1;

                GL.Color(color);

                NavmeshConnection conn = conns[i - header.connBase];

                Vector3 va = verts[poly.indices[0]];
                Vector3 vb = verts[poly.indices[1]];

                // Check to see if start and end end-points have links.
                bool startSet = false;
                bool endSet   = false;
                for (uint k = poly.firstLink; k != Navmesh.NullLink; k = links[k].next)
                {
                    if (links[k].edge == 0)
                    {
                        startSet = true;
                    }
                    if (links[k].edge == 1)
                    {
                        endSet = true;
                    }
                }

                // For linked endpoints: Draw a line between on-mesh location and endpoint,
                // and draw circle at the endpoint.
                // For un-linked endpoints: Draw a small red x-marker.

                if (startSet)
                {
                    GL.Vertex(va);
                    GL.Vertex(conn.endpoints[0]);
                    DebugDraw.AppendCircle(conn.endpoints[0], conn.radius);
                }
                else
                {
                    GL.Color(Color.red);
                    DebugDraw.AppendXMarker(conn.endpoints[0], 0.1f);
                    GL.Color(color);
                }

                if (endSet)
                {
                    GL.Vertex(vb);
                    GL.Vertex(conn.endpoints[1]);
                    DebugDraw.AppendCircle(conn.endpoints[1], conn.radius);
                }
                else
                {
                    GL.Color(Color.red);
                    DebugDraw.AppendXMarker(conn.endpoints[1], 0.1f);
                    GL.Color(color);
                }

                DebugDraw.AppendArc(conn.endpoints[0], conn.endpoints[1]
                                    , 0.25f
                                    , conn.IsBiDirectional ? 0.6f : 0
                                    , 0.6f);
            }

            GL.End();
        }
        private bool UpdateMale()
        {
            if (_maleAtom == null || !_maleAtom.on)
            {
                return(false);
            }

            var penisColliders = new List <string> {
                "AutoColliderGen1Hard",
                "AutoColliderGen2Hard",
                "AutoColliderGen3aHard",
                "AutoColliderGen3bHard"
            };

            var penisTransforms = _maleAtom
                                  .GetComponentsInChildren <Collider>()
                                  .Where(c => penisColliders.Contains(c.name))
                                  .OrderBy(c => c.name, StringComparer.OrdinalIgnoreCase)
                                  .Select(c => c.transform)
                                  .ToList();

            if (penisTransforms.Count != 4)
            {
                return(false);
            }

            _penisLength = 0.0f;
            for (int i = 0, j = 1; j < penisTransforms.Count; i = j++)
            {
                _penisLength += Vector3.Distance(penisTransforms[i].position, penisTransforms[j].position);
            }

            _penisOrigin = penisTransforms[0];

            var positionOffset = -_penisOrigin.up * (penisTransforms[1].position - penisTransforms[0].position).magnitude * 0.15f;

            _referencePosition = _penisOrigin.position + positionOffset;
            _penisLength      += positionOffset.magnitude;
            _penisLength      += penisTransforms[3].GetComponent <CapsuleCollider>().radius;
            _penisRadius       = penisTransforms[1].GetComponent <CapsuleCollider>().radius;

            var pelvisRight = _maleAtom.GetComponentByName <Collider>("AutoColliderpelvisFR3Joint")?.transform;
            var pelvidLeft  = _maleAtom.GetComponentByName <Collider>("AutoColliderpelvisFL3Joint")?.transform;
            var pelvisMid   = _maleAtom.GetComponentByName <Transform>("AutoColliderpelvisF1")?.GetComponentByName <Collider>("AutoColliderpelvisF4Joint")?.transform;

            if (pelvisRight == null || pelvidLeft == null || pelvisMid == null)
            {
                _planeNormal = _penisOrigin.up;
            }
            else
            {
                _planeNormal = Vector3.Cross(pelvisMid.position - pelvidLeft.position, pelvisMid.position - pelvisRight.position).normalized;
            }

            DebugDraw.DrawSquare(ReferencePosition, ReferencePlaneNormal, ReferenceRight, Color.white, 0.33f);
            DebugDraw.DrawTransform(ReferencePosition, ReferenceUp, ReferenceRight, ReferenceForward, 0.15f);
            DebugDraw.DrawRay(ReferencePosition, ReferenceUp, ReferenceLength, Color.white);
            DebugDraw.DrawLine(ReferencePosition, TargetPosition, Color.yellow);

            return(true);
        }
예제 #8
0
 public static void DrawFrame(SoftBody psb, DebugDraw iDraw)
 {
     btSoftBodyHelpers_DrawFrame(psb.Native, iDraw._native);
 }
예제 #9
0
 private void OnApplicationQuit( )
 {
     DebugDraw.DeInit( );
 }
예제 #10
0
 public static void Draw(SoftBody psb, DebugDraw iDraw, DrawFlags drawFlags = DrawFlags.Std)
 {
     btSoftBodyHelpers_Draw(psb.Native, iDraw._native, drawFlags);
 }
예제 #11
0
 private void Awake( )
 {
     DebugDraw.Init( );
 }
예제 #12
0
파일: Controller.cs 프로젝트: ajmaya/box2dx
 /// <summary>
 /// Controllers override this to provide debug drawing.
 /// </summary>
 public virtual void Draw(DebugDraw debugDraw) { }
예제 #13
0
파일: AtkComp.cs 프로젝트: kidsang/ProjectJ
        public override void UpdateDebugDraw()
        {
            if (rangeDebugDraw == null)
                rangeDebugDraw = DebugDraw.Create("AtkRangeDebug", Entity.gameObject, Color.yellow);

            rangeDebugDraw.DrawCircle(attrComp.AtkRange);
        }
예제 #14
0
 public static void DrawVector(Vector3 position, Vector3 direction, float raySize, float markerSize, Color color, float duration, bool depthTest = true)
 {
     Debug.DrawRay(position, direction * raySize, color, 0, false);
     DebugDraw.DrawMarker(position + direction * raySize, markerSize, color, 0, false);
 }
예제 #15
0
 public static void DrawNodeTree(SoftBody psb, DebugDraw iDraw, int minDepth = 0,
                                 int maxDepth = -1)
 {
     btSoftBodyHelpers_DrawNodeTree(psb.Native, iDraw._native,
                                    minDepth, maxDepth);
 }
예제 #16
0
        //\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
        //\ 
        //\ DRAWING
        //\ 
        //\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\


        /// <summary>
        /// Draw one rect for all trackable objects.
        ///
        /// NOTE: WE LOOP THROUGH OBJECTS OF INTEREST AND DRAW A RECT AROUND ALL
        ///
        /// </summary>
        private void _doDrawOneRectForAllTrackableObjects(TrackingPriority aTrackingPriority)
        {
            DebugDraw.DrawRect(_getRectForAllTrackableObjects(aTrackingPriority), _zPlaneCoordinate_float, Constants.GetDebugColorByPriority(aTrackingPriority));
        }
예제 #17
0
 public void DrawLastGroundHit()
 {
     //DebugDraw.EditorDrawArrow(GetLastGroundHitPoint(), GetLastGroundNormal(), Color.red);
     DebugDraw.DebugArrow(GetLastGroundHitPoint(), GetLastGroundNormal(), Color.red);
 }
예제 #18
0
 public static void DrawNodeTree(SoftBody psb, IDebugDraw iDraw, int minDepth = 0,
                                 int maxDepth = -1)
 {
     btSoftBodyHelpers_DrawNodeTree(psb.Native, DebugDraw.GetUnmanaged(iDraw),
                                    minDepth, maxDepth);
 }
예제 #19
0
 public static void Draw(SoftBody psb, IDebugDraw iDraw, int drawFlags)
 {
     btSoftBodyHelpers_Draw2(psb._native, DebugDraw.GetUnmanaged(iDraw), drawFlags);
 }
예제 #20
0
파일: NavDebug.cs 프로젝트: zwong91/Titan
        /// <summary>
        /// Draws a debug visualization of a corridor.
        /// </summary>
        /// <param name="mesh">The navigation mesh associated with the corridor.</param>
        /// <param name="corridor">The corridor to draw.</param>
        public static void Draw(Navmesh mesh, PathCorridorData corridor)
        {
            if (corridor.pathCount == 0)
            {
                return;
            }

            DebugDraw.SimpleMaterial.SetPass(0);

            Vector3[] tileVerts = null;

            for (int iPoly = 0; iPoly < corridor.pathCount; iPoly++)
            {
                NavmeshTile tile;
                NavmeshPoly poly;
                mesh.GetTileAndPoly(corridor.path[iPoly], out tile, out poly);

                if (poly.Type == NavmeshPolyType.OffMeshConnection)
                {
                    continue;
                }

                NavmeshTileHeader header = tile.GetHeader();
                if (tileVerts == null ||
                    tileVerts.Length < 3 * header.vertCount)
                {
                    // Resize.
                    tileVerts = new Vector3[header.vertCount];
                }

                tile.GetVerts(tileVerts);

                GL.Begin(GL.TRIANGLES);
                GL.Color(polygonOverlayColor);

                int pA = poly.indices[0];
                for (int i = 2; i < poly.vertCount; i++)
                {
                    int pB = poly.indices[i - 1];
                    int pC = poly.indices[i];

                    GL.Vertex(tileVerts[pA]);
                    GL.Vertex(tileVerts[pB]);
                    GL.Vertex(tileVerts[pC]);
                }

                GL.End();

                // Not drawing boundaries since it would obscure other agent
                // debug data.
            }

            Vector3 v = corridor.position;

            DebugDraw.XMarker(v, positionScale, positionColor);
            DebugDraw.Circle(v, positionScale, positionColor);
            DebugDraw.Circle(v, positionScale * 0.5f, positionColor);
            DebugDraw.Circle(v, positionScale * 0.25f, positionColor);

            v = corridor.target;
            DebugDraw.XMarker(v, goalScale, goalColor);
            DebugDraw.Circle(v, goalScale, goalColor);
            DebugDraw.Circle(v, goalScale * 0.5f, goalColor);
            DebugDraw.Circle(v, goalScale * 0.25f, goalColor);
        }
예제 #21
0
 public static void DrawClusterTree(SoftBody psb, IDebugDraw iDraw, int minDepth,
                                    int maxDepth)
 {
     btSoftBodyHelpers_DrawClusterTree3(psb._native, DebugDraw.GetUnmanaged(iDraw),
                                        minDepth, maxDepth);
 }
예제 #22
0
    /// <summary>
    /// Check if any of the CollisionSpheres are colliding with any walkable objects in the world.
    /// If they are, apply a proper pushback and retrieve the collision data
    /// </summary>
    void RecursivePushback(int depth, int maxDepth)
    {
        PushIgnoredColliders();

        bool contact = false;

        foreach (var sphere in spheres)
        {
            foreach (Collider col in Physics.OverlapSphere((SpherePosition(sphere)), radius, Walkable, triggerInteraction))
            {
                Vector3 position = SpherePosition(sphere);
                Vector3 contactPoint;
                bool    contactPointSuccess = SuperCollider.ClosestPointOnSurface(col, position, radius, out contactPoint);

                if (!contactPointSuccess)
                {
                    return;
                }

                if (debugPushbackMesssages)
                {
                    DebugDraw.DrawMarker(contactPoint, 2.0f, Color.cyan, 0.0f, false);
                }

                Vector3 v = contactPoint - position;
                if (v != Vector3.zero)
                {
                    // Cache the collider's layer so that we can cast against it
                    int layer = col.gameObject.layer;

                    col.gameObject.layer = TemporaryLayerIndex;

                    // Check which side of the normal we are on
                    bool facingNormal = Physics.SphereCast(new Ray(position, v.normalized), TinyTolerance, v.magnitude + TinyTolerance, 1 << TemporaryLayerIndex);

                    col.gameObject.layer = layer;

                    // Orient and scale our vector based on which side of the normal we are situated
                    if (facingNormal)
                    {
                        if (Vector3.Distance(position, contactPoint) < radius)
                        {
                            v = v.normalized * (radius - v.magnitude) * -1;
                        }
                        else
                        {
                            // A previously resolved collision has had a side effect that moved us outside this collider
                            continue;
                        }
                    }
                    else
                    {
                        v = v.normalized * (radius + v.magnitude);
                    }

                    contact = true;

                    transform.position += v;

                    col.gameObject.layer = TemporaryLayerIndex;

                    // Retrieve the surface normal of the collided point
                    RaycastHit normalHit;

                    Physics.SphereCast(new Ray(position + v, contactPoint - (position + v)), TinyTolerance, out normalHit, 1 << TemporaryLayerIndex);

                    col.gameObject.layer = layer;

                    SuperCollisionType superColType = col.gameObject.GetComponent <SuperCollisionType>();

                    if (superColType == null)
                    {
                        superColType = defaultCollisionType;
                    }

                    // Our collision affected the collider; add it to the collision data
                    var collision = new SuperCollision()
                    {
                        collisionSphere    = sphere,
                        superCollisionType = superColType,
                        gameObject         = col.gameObject,
                        point  = contactPoint,
                        normal = normalHit.normal
                    };

                    collisionData.Add(collision);
                }
            }
        }

        PopIgnoredColliders();

        if (depth < maxDepth && contact)
        {
            RecursivePushback(depth + 1, maxDepth);
        }
    }
예제 #23
0
 public static void DrawNodeTree(SoftBody psb, IDebugDraw iDraw)
 {
     btSoftBodyHelpers_DrawNodeTree(psb._native, DebugDraw.GetUnmanaged(iDraw));
 }
 /// <summary>
 /// Sets a drawing routine. Methods on the provided object are called-back to perform drawing on each update.
 /// </summary>
 /// <param name="debugDraw"></param>
 public void SetDebugDraw(DebugDraw debugDraw)
 {
     _world.SetDebugDraw(debugDraw);
 }
예제 #25
0
 public static void DrawNodeTree(SoftBody psb, IDebugDraw iDraw, int minDepth)
 {
     btSoftBodyHelpers_DrawNodeTree2(psb._native, DebugDraw.GetUnmanaged(iDraw),
                                     minDepth);
 }
예제 #26
0
        public bool UpdateMotion(IMotionSource motionSource)
        {
            var length          = motionSource.ReferenceLength * ReferenceLengthScaleSlider.val;
            var radius          = motionSource.ReferenceRadius * ReferenceRadiusScaleSlider.val;
            var referenceEnding = motionSource.ReferencePosition + motionSource.ReferenceUp * length;
            var diffPosition    = motionSource.TargetPosition - motionSource.ReferencePosition;
            var diffEnding      = motionSource.TargetPosition - referenceEnding;
            var aboveTarget     = (Vector3.Dot(diffPosition, motionSource.TargetUp) < 0 && Vector3.Dot(diffEnding, motionSource.TargetUp) < 0) ||
                                  Vector3.Dot(diffPosition, motionSource.ReferenceUp) < 0;

            for (var i = 0; i < 5; i++)
            {
                DebugDraw.DrawCircle(Vector3.Lerp(motionSource.ReferencePosition, referenceEnding, i / 4.0f), motionSource.ReferenceUp, motionSource.ReferenceRight, Color.grey, radius);
            }

            var t            = Mathf.Clamp(Vector3.Dot(motionSource.TargetPosition - motionSource.ReferencePosition, motionSource.ReferenceUp), 0f, length);
            var closestPoint = motionSource.ReferencePosition + motionSource.ReferenceUp * t;

            if (Vector3.Magnitude(closestPoint - motionSource.TargetPosition) <= radius)
            {
                if (diffPosition.magnitude > 0.0001f)
                {
                    XTarget[0] = 1 - Mathf.Clamp01((closestPoint - motionSource.ReferencePosition).magnitude / length);
                    if (aboveTarget)
                    {
                        XTarget[0] = XTarget[0] > 0 ? 1 : 0;
                    }

                    var diffOnPlane   = Vector3.ProjectOnPlane(diffPosition, motionSource.ReferencePlaneNormal);
                    var rightOffset   = Vector3.Project(diffOnPlane, motionSource.ReferenceRight);
                    var forwardOffset = Vector3.Project(diffOnPlane, motionSource.ReferenceForward);
                    XTarget[1] = forwardOffset.magnitude * Mathf.Sign(Vector3.Dot(forwardOffset, motionSource.ReferenceForward));
                    XTarget[2] = rightOffset.magnitude * Mathf.Sign(Vector3.Dot(rightOffset, motionSource.ReferenceRight));
                }
                else
                {
                    XTarget[0] = 1;
                    XTarget[1] = 0;
                    XTarget[2] = 0;
                }

                var correctedRight = Vector3.ProjectOnPlane(motionSource.TargetRight, motionSource.ReferenceUp);
                if (Vector3.Dot(correctedRight, motionSource.ReferenceRight) < 0)
                {
                    correctedRight -= 2 * Vector3.Project(correctedRight, motionSource.ReferenceRight);
                }

                RTarget[0] = Vector3.SignedAngle(motionSource.ReferenceRight, correctedRight, motionSource.ReferenceUp) / 180;
                RTarget[1] = -Vector3.SignedAngle(motionSource.ReferenceUp, Vector3.ProjectOnPlane(motionSource.TargetUp, motionSource.ReferenceForward), motionSource.ReferenceForward) / 90;
                RTarget[2] = Vector3.SignedAngle(motionSource.ReferenceUp, Vector3.ProjectOnPlane(motionSource.TargetUp, motionSource.ReferenceRight), motionSource.ReferenceRight) / 90;

                ETarget[0] = OutputV0CurveEditorSettings.Evaluate(XTarget, RTarget);
                ETarget[1] = OutputA0CurveEditorSettings.Evaluate(XTarget, RTarget);
                ETarget[2] = OutputA1CurveEditorSettings.Evaluate(XTarget, RTarget);
                ETarget[3] = OutputA2CurveEditorSettings.Evaluate(XTarget, RTarget);

                if (_lastNoCollisionTime != null)
                {
                    _lastNoCollisionSmoothingEnabled   = true;
                    _lastNoCollisionSmoothingStartTime = Time.time;
                    _lastNoCollisionSmoothingDuration  = Mathf.Clamp(Time.time - _lastNoCollisionTime.Value, 0.5f, 2);
                    _lastNoCollisionTime = null;
                }

                return(true);
            }
            else
            {
                if (_lastNoCollisionTime == null)
                {
                    _lastNoCollisionTime = Time.time;
                }

                return(false);
            }
        }
예제 #27
0
    public Vector3 GetClosestPositionOnX(Vector3 pos)
    {
        float   closestDistance = float.MaxValue;
        Vector3 point           = Vector3.zero;
        Vector3 secondPoint     = Vector3.zero;

        for (int i = 0; i < curvePoints.Count; i++)
        {
            float currentDistance = Mathf.Abs(pos.x - curvePoints[i].x);

            if (currentDistance < closestDistance)
            {
                closestDistance = currentDistance;

                point = curvePoints[i];

                if (point.x < pos.x)
                {
                    if (i + 1 >= curvePoints.Count)
                    {
                        secondPoint = curvePoints[curvePoints.Count - 1];
                    }
                    else
                    {
                        secondPoint = curvePoints[i + 1];
                    }
                }
                else
                {
                    if (i - 1 <= 0)
                    {
                        secondPoint = points[0].transform.position;
                    }
                    else
                    {
                        secondPoint = curvePoints[i - 1];
                    }
                }
            }
        }

        Vector3 dir;
        Vector3 targetPos;
        float   cameraPos;

        if (point.x > secondPoint.x)
        {
            // close point ahead
            dir       = point - secondPoint;
            cameraPos = Converter.Remap(pos.x, secondPoint.x, point.x, 0, 1, true);

            targetPos = secondPoint + (dir * cameraPos);
        }
        else
        {
            // close point behinde
            dir       = secondPoint - point;
            cameraPos = Converter.Remap(pos.x, point.x, secondPoint.x, 0, 1, true);

            targetPos = point + (dir * cameraPos);
        }

        DebugDraw.DrawMarker(targetPos, 3f, Color.black, Time.fixedDeltaTime);
        //DebugDraw.DrawMarker(pos, 55f, Color.white, Time.fixedDeltaTime);
        //DebugDraw.DrawMarker(point, 2f, Color.red, Time.fixedDeltaTime);
        //DebugDraw.DrawMarker(secondPoint, 2f, Color.green, Time.fixedDeltaTime);

        return(targetPos);
    }
예제 #28
0
    void RecursivePartition(List <int> triangles, int depth, Node parent)
    {
        Vector3 partitionPoint = Vector3.zero;

        Vector3 maxExtents = new Vector3(-float.MaxValue, -float.MaxValue, -float.MaxValue);
        Vector3 minExtents = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);

        foreach (int triangle in triangles)
        {
            partitionPoint += vertices[tris[triangle]] + vertices[tris[triangle + 1]] + vertices[tris[triangle + 2]];

            minExtents.x = Mathf.Min(minExtents.x, vertices[tris[triangle]].x, vertices[tris[triangle + 1]].x, vertices[tris[triangle + 2]].x);
            minExtents.y = Mathf.Min(minExtents.y, vertices[tris[triangle]].y, vertices[tris[triangle + 1]].y, vertices[tris[triangle + 2]].y);
            minExtents.z = Mathf.Min(minExtents.z, vertices[tris[triangle]].z, vertices[tris[triangle + 1]].z, vertices[tris[triangle + 2]].z);

            maxExtents.x = Mathf.Max(maxExtents.x, vertices[tris[triangle]].x, vertices[tris[triangle + 1]].x, vertices[tris[triangle + 2]].x);
            maxExtents.y = Mathf.Max(maxExtents.y, vertices[tris[triangle]].y, vertices[tris[triangle + 1]].y, vertices[tris[triangle + 2]].y);
            maxExtents.z = Mathf.Max(maxExtents.z, vertices[tris[triangle]].z, vertices[tris[triangle + 1]].z, vertices[tris[triangle + 2]].z);
        }

        // Centroid of all vertices
        partitionPoint /= vertexCount;

        // Better idea? Center of bounding box
        partitionPoint = minExtents + Math3d.SetVectorLength((maxExtents - minExtents), (maxExtents - minExtents).magnitude * 0.5f);

        Vector3 extentsMagnitude = new Vector3(Mathf.Abs(maxExtents.x - minExtents.x), Mathf.Abs(maxExtents.y - minExtents.y), Mathf.Abs(maxExtents.z - minExtents.z));

        Vector3 partitionNormal;

        if (extentsMagnitude.x >= extentsMagnitude.y && extentsMagnitude.x >= extentsMagnitude.z)
        {
            partitionNormal = Vector3.right;
        }
        else if (extentsMagnitude.y >= extentsMagnitude.x && extentsMagnitude.y >= extentsMagnitude.z)
        {
            partitionNormal = Vector3.up;
        }
        else
        {
            partitionNormal = Vector3.forward;
        }

        List <int> positiveTriangles;
        List <int> negativeTriangles;

        Split(triangles, partitionPoint, partitionNormal, out positiveTriangles, out negativeTriangles);

        parent.partitionNormal = partitionNormal;
        parent.partitionPoint  = partitionPoint;

        Node posNode = new Node();

        parent.positiveChild = posNode;

        Node negNode = new Node();

        parent.negativeChild = negNode;

        if (positiveTriangles.Count < triangles.Count && positiveTriangles.Count > 3)
        {
            RecursivePartition(positiveTriangles, depth + 1, posNode);
        }
        else
        {
            posNode.triangles = positiveTriangles.ToArray();

            if (drawMeshTreeOnStart)
            {
                DrawTriangleSet(posNode.triangles, DebugDraw.RandomColor());
            }
        }

        if (negativeTriangles.Count < triangles.Count && negativeTriangles.Count > 3)
        {
            RecursivePartition(negativeTriangles, depth + 1, negNode);
        }
        else
        {
            negNode.triangles = negativeTriangles.ToArray();

            if (drawMeshTreeOnStart)
            {
                DrawTriangleSet(negNode.triangles, DebugDraw.RandomColor());
            }
        }
    }
예제 #29
0
 public static void Draw(SoftBody psb, IDebugDraw iDraw, DrawFlags drawFlags = DrawFlags.Std)
 {
     btSoftBodyHelpers_Draw(psb.Native, DebugDraw.GetUnmanaged(iDraw), drawFlags);
 }
예제 #30
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PrefabWindowViewport"/> class.
        /// </summary>
        /// <param name="window">Editor window.</param>
        public PrefabWindowViewport(PrefabWindow window)
            : base(true)
        {
            _window = window;
            _window.SelectionChanged += OnSelectionChanged;
            Undo              = window.Undo;
            ViewportCamera    = new FPSCamera();
            _debugDrawContext = DebugDraw.AllocateContext();

            // Prepare rendering task
            Task.ActorsSource      = ActorsSources.CustomActors;
            Task.ViewFlags         = ViewFlags.DefaultEditor;
            Task.Begin            += OnBegin;
            Task.CollectDrawCalls += OnCollectDrawCalls;
            Task.PostRender       += OnPostRender;

            // Create post effects
            SelectionOutline = FlaxEngine.Object.New <SelectionOutline>();
            SelectionOutline.SelectionGetter = () => TransformGizmo.SelectedParents;
            Task.CustomPostFx.Add(SelectionOutline);
            EditorPrimitives          = FlaxEngine.Object.New <EditorPrimitives>();
            EditorPrimitives.Viewport = this;
            Task.CustomPostFx.Add(EditorPrimitives);
            _spritesRenderer          = FlaxEngine.Object.New <PrefabSpritesRenderer>();
            _spritesRenderer.Task     = Task;
            _spritesRenderer.Viewport = this;
            Task.CustomPostFx.Add(_spritesRenderer);

            // Add transformation gizmo
            TransformGizmo = new TransformGizmo(this);
            TransformGizmo.ApplyTransformation += ApplyTransform;
            TransformGizmo.ModeChanged         += OnGizmoModeChanged;
            TransformGizmo.Duplicate           += _window.Duplicate;
            Gizmos.Active = TransformGizmo;

            // Transform space widget
            var transformSpaceWidget = new ViewportWidgetsContainer(ViewportWidgetLocation.UpperRight);
            var transformSpaceToggle = new ViewportWidgetButton(string.Empty, window.Editor.Icons.World16, null, true)
            {
                Checked     = TransformGizmo.ActiveTransformSpace == TransformGizmoBase.TransformSpace.World,
                TooltipText = "Gizmo transform space (world or local)",
                Parent      = transformSpaceWidget
            };

            transformSpaceToggle.Toggled += OnTransformSpaceToggle;
            transformSpaceWidget.Parent   = this;

            // Scale snapping widget
            var scaleSnappingWidget = new ViewportWidgetsContainer(ViewportWidgetLocation.UpperRight);
            var enableScaleSnapping = new ViewportWidgetButton(string.Empty, window.Editor.Icons.ScaleStep16, null, true)
            {
                Checked     = TransformGizmo.ScaleSnapEnabled,
                TooltipText = "Enable scale snapping",
                Parent      = scaleSnappingWidget
            };

            enableScaleSnapping.Toggled += OnScaleSnappingToggle;

            var scaleSnappingCM = new ContextMenu();

            _scaleSnapping = new ViewportWidgetButton(TransformGizmo.ScaleSnapValue.ToString(), SpriteHandle.Invalid, scaleSnappingCM)
            {
                TooltipText = "Scale snapping values"
            };

            for (int i = 0; i < EditorViewportScaleSnapValues.Length; i++)
            {
                var v      = EditorViewportScaleSnapValues[i];
                var button = scaleSnappingCM.AddButton(v.ToString());
                button.Tag = v;
            }
            scaleSnappingCM.ButtonClicked  += OnWidgetScaleSnapClick;
            scaleSnappingCM.VisibleChanged += OnWidgetScaleSnapShowHide;
            _scaleSnapping.Parent           = scaleSnappingWidget;
            scaleSnappingWidget.Parent      = this;

            // Rotation snapping widget
            var rotateSnappingWidget = new ViewportWidgetsContainer(ViewportWidgetLocation.UpperRight);
            var enableRotateSnapping = new ViewportWidgetButton(string.Empty, window.Editor.Icons.RotateStep16, null, true)
            {
                Checked     = TransformGizmo.RotationSnapEnabled,
                TooltipText = "Enable rotation snapping",
                Parent      = rotateSnappingWidget
            };

            enableRotateSnapping.Toggled += OnRotateSnappingToggle;

            var rotateSnappingCM = new ContextMenu();

            _rotateSnapping = new ViewportWidgetButton(TransformGizmo.RotationSnapValue.ToString(), SpriteHandle.Invalid, rotateSnappingCM)
            {
                TooltipText = "Rotation snapping values"
            };

            for (int i = 0; i < EditorViewportRotateSnapValues.Length; i++)
            {
                var v      = EditorViewportRotateSnapValues[i];
                var button = rotateSnappingCM.AddButton(v.ToString());
                button.Tag = v;
            }
            rotateSnappingCM.ButtonClicked  += OnWidgetRotateSnapClick;
            rotateSnappingCM.VisibleChanged += OnWidgetRotateSnapShowHide;
            _rotateSnapping.Parent           = rotateSnappingWidget;
            rotateSnappingWidget.Parent      = this;

            // Translation snapping widget
            var translateSnappingWidget = new ViewportWidgetsContainer(ViewportWidgetLocation.UpperRight);
            var enableTranslateSnapping = new ViewportWidgetButton(string.Empty, window.Editor.Icons.Grid16, null, true)
            {
                Checked     = TransformGizmo.TranslationSnapEnable,
                TooltipText = "Enable position snapping",
                Parent      = translateSnappingWidget
            };

            enableTranslateSnapping.Toggled += OnTranslateSnappingToggle;

            var translateSnappingCM = new ContextMenu();

            _translateSnappng = new ViewportWidgetButton(TransformGizmo.TranslationSnapValue.ToString(), SpriteHandle.Invalid, translateSnappingCM)
            {
                TooltipText = "Position snapping values"
            };

            for (int i = 0; i < EditorViewportTranslateSnapValues.Length; i++)
            {
                var v      = EditorViewportTranslateSnapValues[i];
                var button = translateSnappingCM.AddButton(v.ToString());
                button.Tag = v;
            }
            translateSnappingCM.ButtonClicked  += OnWidgetTranslateSnapClick;
            translateSnappingCM.VisibleChanged += OnWidgetTranslateSnapShowHide;
            _translateSnappng.Parent            = translateSnappingWidget;
            translateSnappingWidget.Parent      = this;

            // Gizmo mode widget
            var gizmoMode = new ViewportWidgetsContainer(ViewportWidgetLocation.UpperRight);

            _gizmoModeTranslate = new ViewportWidgetButton(string.Empty, window.Editor.Icons.Translate16, null, true)
            {
                Tag         = TransformGizmoBase.Mode.Translate,
                TooltipText = "Translate gizmo mode",
                Checked     = true,
                Parent      = gizmoMode
            };
            _gizmoModeTranslate.Toggled += OnGizmoModeToggle;
            _gizmoModeRotate             = new ViewportWidgetButton(string.Empty, window.Editor.Icons.Rotate16, null, true)
            {
                Tag         = TransformGizmoBase.Mode.Rotate,
                TooltipText = "Rotate gizmo mode",
                Parent      = gizmoMode
            };
            _gizmoModeRotate.Toggled += OnGizmoModeToggle;
            _gizmoModeScale           = new ViewportWidgetButton(string.Empty, window.Editor.Icons.Scale16, null, true)
            {
                Tag         = TransformGizmoBase.Mode.Scale,
                TooltipText = "Scale gizmo mode",
                Parent      = gizmoMode
            };
            _gizmoModeScale.Toggled += OnGizmoModeToggle;
            gizmoMode.Parent         = this;

            _dragHandlers.Add(_dragActorType);
            _dragHandlers.Add(_dragAssets);

            // Setup input actions
            InputActions.Add(options => options.TranslateMode, () => TransformGizmo.ActiveMode = TransformGizmoBase.Mode.Translate);
            InputActions.Add(options => options.RotateMode, () => TransformGizmo.ActiveMode    = TransformGizmoBase.Mode.Rotate);
            InputActions.Add(options => options.ScaleMode, () => TransformGizmo.ActiveMode     = TransformGizmoBase.Mode.Scale);
            InputActions.Add(options => options.FocusSelection, ShowSelectedActors);

            SetUpdate(ref _update, OnUpdate);
        }
예제 #31
0
 public static void DrawFrame(SoftBody psb, IDebugDraw iDraw)
 {
     btSoftBodyHelpers_DrawFrame(psb.Native, DebugDraw.GetUnmanaged(iDraw));
 }
예제 #32
0
 static void DrawLineBetweenDataPoints(DataPoint data1, DataPoint data2, Color color)
 {
     //Gizmos.color = color;
     //Gizmos.DrawLine(data1.LocalPosition, data2.LocalPosition);
     DebugDraw.DrawLine(data1.LocalPosition, data2.LocalPosition, color);
 }
예제 #33
0
 public static void DrawInfos(SoftBody psb, IDebugDraw iDraw, bool masses,
                              bool areas, bool stress)
 {
     btSoftBodyHelpers_DrawInfos(psb.Native, DebugDraw.GetUnmanaged(iDraw),
                                 masses, areas, stress);
 }
예제 #34
0
 /// <summary>
 /// Draw center point crosshairs for rect of all trackable objects.
 /// </summary>
 private void _doDrawCenterPointCrosshairsForRectOfAllTrackableObjects(TrackingPriority aTrackingPriority)
 {
     DebugDraw.DrawCenterPointCrosshairsForRect(_getRectForAllTrackableObjects(aTrackingPriority), _zPlaneCoordinate_float, Constants.GetDebugColorByPriority(aTrackingPriority));
 }
예제 #35
0
        void Start()
        {
            GameObject debugDrawGo = new GameObject("DebugDraw");
            debugDraw = debugDrawGo.AddComponent<DebugDraw>();

            ResourceManager.Init();
            SettingManager.Init(StartTest);
        }