Esempio n. 1
0
    public void OnDrawRuntimeGizmos(RuntimeGizmoDrawer drawer)
    {
        if (!_drawDebug)
        {
            return;
        }

        if (objectTransform == null)
        {
            return;
        }

        drawer.PushMatrix();
        drawer.matrix = objectTransform.localToWorldMatrix;

        drawer.color = LeapColor.coral;
        drawer.DrawWireCube(Vector3.zero, Vector3.one * 0.20f);

        drawer.color = LeapColor.jade;
        drawer.DrawWireCube(Vector3.zero, Vector3.one * 0.10f);

        drawer.PopMatrix();

        if (_constrainPosition && _drawPositionConstraints)
        {
            drawer.color = LeapColor.lavender;
            var dir = (Camera.main.transform.position.From(_basePosition)).normalized;
            drawer.DrawWireSphere(_basePosition,
                                  objectTransform.TransformVector(Vector3.right * _constraintDistance).magnitude);

            drawer.color = LeapColor.violet;
            drawer.DrawWireSphere(_basePosition,
                                  _maxWorldDistance);
        }
    }
Esempio n. 2
0
 public override void OnDrawRuntimeGizmos(RuntimeGizmoDrawer drawer)
 {
     if (_wearableUIGizmosEnabled)
     {
         drawer.color = Color.red;
         if (IsWorkstation)
         {
             drawer.DrawWireSphere(this.transform.position, GetWorkstationDangerZoneRadius());
         }
         else
         {
             drawer.DrawWireSphere(this.transform.position, GetAnchoredDangerZoneRadius());
         }
     }
 }
Esempio n. 3
0
        public void OnDrawRuntimeGizmos(RuntimeGizmoDrawer drawer)
        {
            if (!gameObject.activeInHierarchy)
            {
                return;
            }

            drawer.color = color;
            drawer.DrawWireSphere(this.transform.position, radius);
        }
        public void OnDrawRuntimeGizmos(RuntimeGizmoDrawer drawer)
        {
            Color pinchOriginColor = Color.blue;

            if (_isTipHandTracked && !brush.IsBrushing())
            {
                drawer.color = pinchOriginColor;
                drawer.DrawWireSphere(_pointBeginPosition, tipRadius);
            }
        }
Esempio n. 5
0
 public void OnDrawRuntimeGizmos(RuntimeGizmoDrawer drawer)
 {
     if (_drawGizmos)
     {
         drawer.PushMatrix();
         drawer.matrix = this.transform.localToWorldMatrix;
         drawer.color  = Color.blue;
         drawer.DrawWireSphere(Vector3.zero, _radius);
         drawer.PopMatrix();
     }
 }
Esempio n. 6
0
        public static void DrawWireSphere(this RuntimeGizmoDrawer drawer,
                                          Vector3 position,
                                          Quaternion rotation,
                                          float radius)
        {
            drawer.PushMatrix();

            drawer.matrix = Matrix4x4.TRS(position, rotation, Vector3.one);

            drawer.DrawWireSphere(Vector3.zero, radius);

            drawer.PopMatrix();
        }
Esempio n. 7
0
        public void DrawEllipse(RuntimeGizmoDrawer drawer, Vector3 foci1, Vector3 foci2, float MinorAxis)
        {
            drawer.PushMatrix();
            Vector3    ellipseCenter   = (foci1 + foci2) / 2f;
            Quaternion ellipseRotation = Quaternion.LookRotation(foci1 - foci2);

            MajorAxis = Mathf.Sqrt(Mathf.Pow(Vector3.Distance(foci1, foci2) / 2f, 2f) + Mathf.Pow(MinorAxis / 2f, 2f)) * 2f;
            Vector3 ellipseScale = new Vector3(MinorAxis, MinorAxis, MajorAxis);

            drawer.matrix      = Matrix4x4.TRS(ellipseCenter, ellipseRotation, ellipseScale);
            sphereToWorldSpace = drawer.matrix;
            worldToSphereSpace = sphereToWorldSpace.inverse;

            drawer.DrawWireSphere(Vector3.zero, 0.5f);
            drawer.PopMatrix();
        }
Esempio n. 8
0
            public static float Plane(List <Vector3> points, out Vector3 position,
                                      out Vector3 normal, int iters = 200, RuntimeGizmoDrawer drawer = null)
            {
                //Find the primary principal axis
                Vector3 primaryDirection = Vector3.right;

                Line(points, out position, ref primaryDirection, iters / 2);

                //Flatten the points along that axis
                List <Vector3> flattenedPoints = new List <Vector3>(points);

                for (int i = 0; i < flattenedPoints.Count; i++)
                {
                    flattenedPoints[i] = Vector3.ProjectOnPlane(points[i] - position, primaryDirection) + position;
                }

                //Find the secondary principal axis
                Vector3 secondaryDirection = Vector3.right;

                Line(flattenedPoints, out position, ref secondaryDirection, iters / 2);

                normal = Vector3.Cross(primaryDirection, secondaryDirection).normalized;

                float residualSum = 0f;

                foreach (Vector3 point in points)
                {
                    residualSum += Vector3.Distance(point, Vector3.ProjectOnPlane(point - position, normal) + position);
                }

                if (drawer != null)
                {
                    drawer.color = Color.red;
                    //foreach (Vector3 point in points) drawer.DrawLine(point, Vector3.ProjectOnPlane(point - position, normal) + position);
                    drawer.color = Color.blue;
                    drawer.DrawLine(position, position + (normal * 0.02f));
                    drawer.DrawLine(position, position - (normal * 0.02f));
                    drawer.matrix = Matrix4x4.TRS(position, Quaternion.LookRotation(normal, primaryDirection), new Vector3(0.025f, 0.025f, 0.001f));
                    drawer.DrawWireSphere(Vector3.zero, 1f);
                    drawer.matrix = Matrix4x4.identity;
                }

                return(residualSum);
            }
        public void OnDrawRuntimeGizmos(RuntimeGizmoDrawer drawer)
        {
            for (int i = 0; i < _heat.Length; i++)
            {
                _colors[i] = Color.Lerp(Color.cyan, Color.red, _heat[i]);
            }

            for (int i = 0; i < _indexPosBuffer.Count; i++)
            {
                drawer.color = _colors[i];
                float radius = 0.005F;
                if (_heat[i] > 0.8F)
                {
                    radius = 0.01F;
                }
                drawer.DrawSphere(_indexPosBuffer.Get(i), radius);
            }

            drawer.color = Color.green;
            drawer.DrawWireSphere(_lastTapPosition, 0.008F);
        }
Esempio n. 10
0
        public void OnDrawRuntimeGizmos(RuntimeGizmoDrawer drawer)
        {
            var mesh = polyMesh;

            if (mesh == null)
            {
                return;
            }

            // Verts.
            foreach (var poly in mesh.polygons)
            {
                int vertIdx = 0;
                drawer.color = debugVertColor;
                foreach (var vertPos in poly.verts.Query().Select(vIdx => poly.GetMeshPosition(vIdx)))
                {
                    drawer.DrawWireSphere(vertPos, PolyMath.POSITION_TOLERANCE * debugVertRadiusMult);
                    drawer.DrawWireCube(vertPos, Vector3.one * PolyMath.POSITION_TOLERANCE * debugVertRadiusMult);
                    vertIdx++;
                }
            }
        }
Esempio n. 11
0
        public void drawPingGizmos(RuntimeGizmoDrawer drawer)
        {
            Color      pingColor;
            float      pingSize;
            float      animTime;
            Vector3    pingPos0, pingPos1;
            Quaternion pingRot0;

            foreach (var ping in _activePings)
            {
                if (ping.position0Func != null)
                {
                    pingPos0 = ping.position0Func();
                }
                else
                {
                    pingPos0 = ping.position0;
                }

                if (ping.position1Func != null)
                {
                    pingPos1 = ping.position1Func();
                }
                else
                {
                    pingPos1 = ping.position1;
                }

                pingRot0 = ping.rotation0;

                pingColor = ping.color;

                animTime = Mathf.Lerp(0f, 1f, ping.time / PING_DURATION);
                animTime = pingAnimCurve.Evaluate(animTime);

                pingSize = ping.sizeMultiplier * DEFAULT_PING_RADIUS;

                switch (ping.animType)
                {
                case AnimType.Expand:
                    pingSize = pingSize * animTime;
                    break;

                case AnimType.Fade:
                    pingColor = ping.color.WithAlpha(1f - animTime);
                    break;

                case AnimType.ExpandAndFade:
                    pingSize  = pingSize * animTime;
                    pingColor = ping.color.WithAlpha(1f - animTime);
                    break;
                }


                drawer.color = pingColor;

                switch (ping.shapeType)
                {
                case ShapeType.Sphere:
                    drawer.DrawWireSphere(pingPos0, pingRot0, pingSize);
                    break;

                case ShapeType.Capsule:
                    drawer.DrawWireCapsule(pingPos0, pingPos1, pingSize);
                    break;

                case ShapeType.Cone:
                    drawer.DrawCone(pingPos0, pingPos1, pingSize);
                    break;
                }
            }
        }
Esempio n. 12
0
    protected virtual void Update()
    {
        _deltaTime = 1f / 5f;
        RuntimeGizmoManager.TryGetGizmoDrawer(out drawer);

        BeforeParticleUpdate();

        Array.Clear(collisionTimes, 0, collisionTimes.Length);
        for (int i = 0; i < _workerData.Length; i++)
        {
            _workerData[i].collisionChunkCounts.Clear();
            _workerData[i].socialChunkCounts.Clear();
        }

        using (new ProfilerSample("Destroy Particles")) {
            destroyParticles();
        }

        using (new ProfilerSample("Emit Particles")) {
            emitParticles();
        }

        if (_useMultithreading)
        {
            using (new ProfilerSample("Dispatch Simulation Jobs")) {
                _integrationForeach.Dispatch(_aliveParticles);
            }
        }
        else
        {
            using (new ProfilerSample("Integrate Particles")) {
                integrateParticles(0, 0, _aliveParticles);
            }
            Array.Copy(_particlesFront, _particlesBack, _aliveParticles);

            if (_useCollisionChunking)
            {
                using (new ProfilerSample("Accumulate And Sort")) {
                    sortIntoChunks(isCollision: true);
                }

                using (new ProfilerSample("Resolve Collisions")) {
                    resolveCollisionsChunked();
                }
            }
            else
            {
                using (new ProfilerSample("Resolve Collisions")) {
                    resolveCollisionsNaive(0, 0, _aliveParticles);
                }
            }

            if (_useSocialChunking)
            {
                using (new ProfilerSample("Accumulate And Sort")) {
                    sortIntoChunks(isCollision: false);
                }

                using (new ProfilerSample("Apply Forces")) {
                    doSocialForcesChunked();
                }
            }
            else
            {
                using (new ProfilerSample("Apply Forces")) {
                    doSocialForcesNaive(0, 0, _aliveParticles);
                }
            }

            using (new ProfilerSample("Apply Global Forces")) {
                applyGlobalForces(0, 0, _aliveParticles);
            }
        }

        if (Input.GetKeyDown(KeyCode.M))
        {
            useKMeans = true;
        }

        if (useKMeans)
        {
            int LEN = 20;
            if (_means == null)
            {
                _means  = new Vector3[LEN];
                _raddii = new float[LEN];
                for (int i = 0; i < LEN; i++)
                {
                    _means[i] = _particlesFront[UnityEngine.Random.Range(0, _aliveParticles)].position;
                }
            }

            var newMeans  = new Vector3[LEN];
            var newCounts = new int[LEN];

            _raddii = new float[LEN];

            for (int i = 0; i < _aliveParticles; i++)
            {
                Particle p = _particlesFront[i];

                float closestDist = float.MaxValue;
                int   index       = 0;
                for (int j = 0; j < LEN; j++)
                {
                    float dist = Vector3.Distance(p.position, _means[j]);
                    if (dist < closestDist)
                    {
                        closestDist = dist;
                        index       = j;
                    }
                }

                drawer.color = _randomColors[index];
                drawer.DrawWireSphere(p.position, 0.05f);

                newMeans[index]  += p.position;
                newCounts[index] += 1;
                _raddii[index]    = Mathf.Max(_raddii[index], closestDist);
            }

            for (int i = 0; i < LEN; i++)
            {
                if (newCounts[i] == 0)
                {
                    _means[i] = UnityEngine.Random.insideUnitSphere;
                }
                else
                {
                    _means[i] = newMeans[i] / newCounts[i];
                }

                drawer.color = _randomColors[i];
                drawer.DrawWireSphere(_means[i], _raddii[i]);
            }

            int totalInteractions = 0;
            for (int i = 0; i < _aliveParticles; i++)
            {
                Particle p = _particlesFront[i];

                float closestDist = float.MaxValue;
                int   index       = 0;
                for (int j = 0; j < LEN; j++)
                {
                    float dist = Vector3.Distance(p.position, _means[j]);
                    if (dist < closestDist)
                    {
                        closestDist = dist;
                        index       = j;
                    }
                }

                totalInteractions += newCounts[index];
                for (int j = 0; j < LEN; j++)
                {
                    if (j == index)
                    {
                        continue;
                    }

                    if (Vector3.Distance(p.position, _means[j]) < (0.5f + _raddii[j]))
                    {
                        totalInteractions += newCounts[j];
                    }
                }
            }

            Debug.Log(totalInteractions + " : " + (1024 * 1024));
        }
    }
Esempio n. 13
0
        private void fillOpenMarblePositions(Vector3[] marblePositions)
        {
            var pullTabLength = this.transform.position.From(pullTabOrigin.transform.position).magnitude;

            var pullLength = pullTabIntObj.transform.position.From(pullTabOrigin.position).magnitude;

            var pullOutDir = pullTabOrigin.transform.right * -1;

            var     curveStart   = this.transform.position;
            Vector3 curveEnd     = pullTabIntObj.transform.position;
            var     controlPoint = curveStart + (pullOutDir * pullLength / 3f);

            var curveLength = estimateCurveLength(curveStart, curveEnd, controlPoint);

            //var lengthBetweenMarbles = marbleSpacing;
            var totalStripLength = marbleSpacing * (marblePositions.Length - 1 + 1);

            var beginPoint = curveStart;

            if (totalStripLength > curveLength)
            {
                beginPoint += (totalStripLength - curveLength) * -pullOutDir;
            }

            var tFraction_AllMarbles = 1 / (float)(marblePositions.Length - 1 + (1 /* leave extra space at end of curve */));

            var curveStripLenRatio = totalStripLength / curveLength;

            var tStart = 1 - (1 * curveStripLenRatio);
            var tStep  = tFraction_AllMarbles * curveStripLenRatio;

            if (tStep < 0.001f)
            {
                Debug.LogError("Bad tStep!! " + tStep, this);
                tStep = 0.001f;
            }

            RuntimeGizmoDrawer drawer = null;

            {
                RuntimeGizmoManager.TryGetGizmoDrawer(out drawer);
            }

            if (drawer != null && drawDebug)
            {
                drawer.color = LeapColor.forest;
                drawer.DrawWireSphere(beginPoint, 0.04f);

                drawer.color = LeapColor.blue;
                drawer.DrawWireSphere(curveStart, 0.04f);
                drawer.DrawWireSphere(curveEnd, 0.04f);
                drawer.DrawWireSphere(controlPoint, 0.04f);
            }

            var t = tStart;

            if (t > 0)
            {
                t = 0;
            }
            for (int i = 0; i < marblePositions.Length; i++)
            {
                Vector3 marblePos;
                if (t < 0)
                {
                    marblePos = beginPoint + pullOutDir * (marbleSpacing * i);
                }
                else
                {
                    marblePos = evalCurve(curveStart, curveEnd, controlPoint, t);
                }
                marblePositions[i] = marblePos;

                if (drawer != null && drawDebug)
                {
                    drawer.color = Color.white;
                    drawer.DrawWireSphere(marblePos, 0.03f);
                }

                t += tStep;
            }
        }
 public void OnDrawRuntimeGizmos(RuntimeGizmoDrawer drawer)
 {
     drawer.color = Color.yellow;
     drawer.DrawWireSphere(_lastDoubleTapPos, 0.01F);
 }
Esempio n. 15
0
    public void OnDrawRuntimeGizmos(RuntimeGizmoDrawer drawer)
    {
        if (!this.enabled)
        {
            return;
        }
        if (!_drawDebug)
        {
            return;
        }

        // Sphere gizmo

        //drawer.color = LeapColor.forest.WithAlpha(0.2f);
        //float initAlpha = 0.2f;
        //int numRings = 8;
        //for (int i = 0; i < numRings; i++) {
        //  drawer.color = LeapColor.forest.WithAlpha(Mathf.Lerp(initAlpha, 0f, i / (float)numRings) * _widgetAlphaMult);
        //  float r = _widgetRadius - (_widgetRadius * (i / (float)numRings));
        //  drawer.DrawWireSphere(this.transform.position, r);
        //}

        var dir = Camera.main.transform.position.From(this.transform.position).normalized;

        drawer.color = LeapColor.forest;
        int   numDirRings  = 8;
        float angleStep    = 2f;
        float initDirAlpha = 0.9f;

        for (int i = 0; i < numDirRings; i++)
        {
            drawer.color = drawer.color.WithAlpha(Mathf.Lerp(initDirAlpha, 0f, i / (float)numDirRings) * _widgetAlphaMult);
            drawer.DrawWireArc(this.transform.position + (_widgetRadius * dir * Mathf.Sin(angleStep * i * Mathf.Deg2Rad)),
                               dir, dir.Perpendicular(),
                               _widgetRadius * Mathf.Cos(angleStep * i * Mathf.Deg2Rad),
                               1.0f, 32);
        }


        // Grasp gizmos

        float graspGizmoRadius = 0.03f;

        if (!Application.isPlaying)
        {
            drawer.color = LeapColor.forest;
            drawer.DrawWireSphere(this.transform.position, _widgetRadius);
        }

        if (_switchA != null)
        {
            if (_switchA.grasped)
            {
                drawer.color = LeapColor.forest.WithAlpha(0.7f);
                drawer.DrawWireSphere(_switchA.Position, graspGizmoRadius);

                var dirA             = Camera.main.transform.position.From(_switchA.Position).normalized;
                int numGizmoDirRings = 8;
                angleStep    = 9f;
                initDirAlpha = 0.8f;
                for (int i = 0; i < numGizmoDirRings; i++)
                {
                    drawer.color = drawer.color.WithAlpha(Mathf.Lerp(initDirAlpha, 0f, i / (float)numGizmoDirRings) * _widgetAlphaMult);
                    drawer.DrawWireArc(_switchA.Position + (graspGizmoRadius * dirA * Mathf.Sin(angleStep * i * Mathf.Deg2Rad)),
                                       dirA, dirA.Perpendicular(),
                                       graspGizmoRadius * Mathf.Cos(angleStep * i * Mathf.Deg2Rad),
                                       1.0f, (i == 0 ? 24 : 16));
                }
            }
            else if (_switchAWithinRange)
            {
                drawer.color = LeapColor.forest.WithAlpha(0.4f);
                drawer.DrawWireSphere(_switchA.Position, graspGizmoRadius * 0.7f);
            }
        }
        if (_switchB != null)
        {
            if (_switchB.grasped)
            {
                drawer.color = LeapColor.forest.WithAlpha(0.7f);
                drawer.DrawWireSphere(_switchB.Position, graspGizmoRadius);

                var dirB             = Camera.main.transform.position.From(_switchB.Position).normalized;
                int numGizmoDirRings = 8;
                angleStep    = 9f;
                initDirAlpha = 0.8f;
                for (int i = 0; i < numGizmoDirRings; i++)
                {
                    drawer.color = drawer.color.WithAlpha(Mathf.Lerp(initDirAlpha, 0f, i / (float)numGizmoDirRings) * _widgetAlphaMult);
                    drawer.DrawWireArc(_switchB.Position + (dirB * graspGizmoRadius * Mathf.Sin(angleStep * i * Mathf.Deg2Rad)),
                                       dirB, dirB.Perpendicular(),
                                       graspGizmoRadius * Mathf.Cos(angleStep * i * Mathf.Deg2Rad),
                                       1.0f, (i == 0 ? 24 : 16));
                }
            }
            else if (_switchBWithinRange)
            {
                drawer.color = LeapColor.mint.WithAlpha(0.4f);
                drawer.DrawWireSphere(_switchB.Position, graspGizmoRadius * 0.7f);
            }
        }

        bool switchAGrasped = _switchA != null && _switchA.grasped;
        bool switchBGrasped = _switchB != null && _switchB.grasped;

        if (switchAGrasped && switchBGrasped)
        {
            drawer.color = LeapColor.mint.WithAlpha(0.7f);

            var ATowardsB = (_switchB.Position - _switchA.Position).normalized;
            drawer.DrawLine(_switchA.Position + (ATowardsB) * graspGizmoRadius,
                            _switchB.Position - (ATowardsB) * graspGizmoRadius);
        }


        // Alpha multiplier
        var targetAlphaT = 0f;

        if (_switchAWithinRange || _switchBWithinRange)
        {
            targetAlphaT = 0.6f;

            if (_switchAWithinRange && _switchA.grasped)
            {
                targetAlphaT = 1.0f;
            }
            else if (_switchBWithinRange && _switchB.grasped)
            {
                targetAlphaT = 1.0f;
            }
        }

        if (_widgetAlphaT < targetAlphaT)
        {
            _widgetAlphaT += _widgetAlphaSpeed * Time.deltaTime;
            _widgetAlphaT  = Mathf.Min(_widgetAlphaT, targetAlphaT);
        }
        if (_widgetAlphaT > targetAlphaT)
        {
            _widgetAlphaT -= _widgetAlphaSpeed * Time.deltaTime;
            _widgetAlphaT  = Mathf.Max(_widgetAlphaT, targetAlphaT);
        }

        _widgetAlphaMult = _widgetAlphaCurve.Evaluate(_widgetAlphaT);
    }