Ejemplo n.º 1
0
        protected override void OnStart()
        {
            var visualMesh = sonarLink.GetComponentInChildren <MeshFilter>();

            sensorStartOffset = (visualMesh == null) ? 0f : visualMesh.sharedMesh.bounds.max.y;

            // Create a new sensing area
            var meshCollider = gameObject.AddComponent <MeshCollider>();

            float sensorMeshOffset = 0;
            Mesh  mesh             = null;

            if (geometry.Equals("sphere"))
            {
                mesh             = ProceduralMesh.CreateSphere((float)radius);
                sensorMeshOffset = (float)radius;
            }
            else
            {
                mesh             = ProceduralMesh.CreateCone((float)radius, 0, (float)rangeMax, 10);
                sensorMeshOffset = (float)rangeMax / 2;
            }

            TranslateDetectionArea(mesh, 0.0005f + sensorStartOffset + sensorMeshOffset);

            meshCollider.sharedMesh = mesh;
            meshCollider.convex     = true;
            meshCollider.isTrigger  = true;

            ResolveSensingArea(meshCollider);

            // const MeshColliderCookingOptions cookingOptions
            //  = MeshColliderCookingOptions.EnableMeshCleaning|MeshColliderCookingOptions.WeldColocatedVertices;
            // meshCollider.cookingOptions = cookingOptions;
            // meshCollider.hideFlags |= HideFlags.NotEditable;

            var sonar = sonarStamped.Sonar;

            sonar.Frame    = deviceName;
            sonar.Radius   = radius;
            sonar.RangeMin = rangeMin;
            sonar.RangeMax = rangeMax;
        }
Ejemplo n.º 2
0
        protected override void OnStart()
        {
            var visualMesh = sonarLink.GetComponentInChildren <MeshFilter>();

            sensorStartOffset = (visualMesh == null) ? 0f : visualMesh.sharedMesh.bounds.max.y;

            // Create a new sensing area
            var meshCollider = gameObject.AddComponent <MeshCollider>();

            float sensorMeshOffset = 0;
            Mesh  mesh             = null;

            if (geometry.Equals("sphere"))
            {
                mesh             = ProceduralMesh.CreateSphere((float)radius);
                sensorMeshOffset = (float)radius;
            }
            else
            {
                mesh             = ProceduralMesh.CreateCone((float)radius, 0, (float)rangeMax, 10);
                sensorMeshOffset = (float)rangeMax / 2;
            }

            TranslateDetectionArea(mesh, 0.0001f + sensorStartOffset + sensorMeshOffset + (float)rangeMin);

            meshCollider.sharedMesh = mesh;
            meshCollider.convex     = true;
            meshCollider.isTrigger  = true;

            ResolveSensingArea(meshCollider.sharedMesh);

            var sonar = sonarStamped.Sonar;

            sonar.Frame    = deviceName;
            sonar.Radius   = radius;
            sonar.RangeMin = rangeMin;
            sonar.RangeMax = rangeMax;
        }