Ejemplo n.º 1
0
        private void DrawCutawayPlane(ObiDistanceField field, Matrix4x4 matrix)
        {
            if (field == null)
            {
                return;
            }

            RefreshCutawayTexture(field);

            material.mainTexture = cutawayTexture;
            material.SetPass(0);

            Quaternion rotation = Quaternion.identity;
            Vector3    offset   = Vector3.zero;

            offset[(int)axis] = field.FieldBounds.size[0];

            if (axis == Axis.Y)
            {
                rotation = Quaternion.Euler(90, 0, 0);
            }
            else if (axis == Axis.X)
            {
                rotation = Quaternion.Euler(0, -90, 0);
            }

            Matrix4x4 sc = Matrix4x4.TRS(field.FieldBounds.center + offset * (slice - 0.5f), rotation, Vector3.one * field.FieldBounds.size[0]);

            Graphics.DrawMeshNow(planeMesh, matrix * sc);
        }
 public ObiDistanceFieldShapeTracker(ObiDistanceField distanceField)
 {
     this.distanceField  = distanceField;
     adaptor.is2D        = false;
     oniShape            = Oni.CreateShape(Oni.ShapeType.SignedDistanceField);
     fieldDataHasChanged = true;
 }
        public ObiDistanceFieldHandle GetOrCreateDistanceField(ObiDistanceField source)
        {
            ObiDistanceFieldHandle handle;

            if (!handles.TryGetValue(source, out handle))
            {
                handle = new ObiDistanceFieldHandle(source, headers.count);
                handles.Add(source, handle);
                headers.Add(new DistanceFieldHeader(dfNodes.count, source.nodes.Count));

                dfNodes.AddRange(source.nodes);
            }

            return(handle);
        }
Ejemplo n.º 4
0
        private void RefreshCutawayTexture(ObiDistanceField field)
        {
            if (field == null)
            {
                return;
            }

            Bounds b = field.FieldBounds;

            sampleSize  = field.EffectiveSampleSize;
            sampleCount = (int)(b.size[0] / sampleSize) + 1;

            CreatePlaneMesh(field);
            ResizeTexture();

            float   sweep  = (sampleCount * slice) * sampleSize;
            Vector3 origin = b.center - b.extents;

            for (int x = 0; x < sampleCount; ++x)
            {
                for (int y = 0; y < sampleCount; ++y)
                {
                    Vector3 offset = Vector3.zero;
                    switch (axis)
                    {
                    case Axis.X: offset = new Vector3(sweep, y * sampleSize, x * sampleSize); break;

                    case Axis.Y: offset = new Vector3(x * sampleSize, sweep, y * sampleSize); break;

                    case Axis.Z: offset = new Vector3(x * sampleSize, y * sampleSize, sweep); break;
                    }

                    Vector4 position = origin + offset;
                    float   distance = Oni.SampleDistanceField(field.OniDistanceField, position.x, position.y, position.z);

                    float value = ObiUtils.Remap(distance, -maxDistance, maxDistance, 0, 1);

                    cutawayTexture.SetPixel(x, y, new Color(value, 0, 0));
                }
            }
            cutawayTexture.Apply();
        }
Ejemplo n.º 5
0
        private void CreatePlaneMesh(ObiDistanceField field)
        {
            if (field != null && planeMesh == null)
            {
                float uvBorder = (1 - field.FieldBounds.size[0] / (sampleSize * sampleCount)) * 0.5f;

                planeMesh = new Mesh();

                planeMesh.vertices = new Vector3[] { new Vector3(-0.5f, -0.5f, 0),
                                                     new Vector3(0.5f, -0.5f, 0),
                                                     new Vector3(-0.5f, 0.5f, 0),
                                                     new Vector3(0.5f, 0.5f, 0) };

                planeMesh.uv = new Vector2[] { new Vector2(uvBorder, uvBorder),
                                               new Vector2(1 - uvBorder, uvBorder),
                                               new Vector2(uvBorder, 1 - uvBorder),
                                               new Vector2(1 - uvBorder, 1 - uvBorder) };

                planeMesh.normals   = new Vector3[] { -Vector3.forward, -Vector3.forward, -Vector3.forward, -Vector3.forward };
                planeMesh.triangles = new int[] { 0, 2, 1, 2, 3, 1 };
            }
        }
 public ObiDistanceFieldHandle GetOrCreateDistanceField(ObiDistanceField df)
 {
     return(distanceFieldContainer.GetOrCreateDistanceField(df));
 }
 public void OnEnable()
 {
     distanceField = (ObiDistanceField)target;
     previewHelper = new PreviewHelpers();
     UpdatePreview();
 }
 public ObiDistanceFieldShapeTracker(ObiCollider source, Component collider, ObiDistanceField distanceField)
 {
     this.source        = source;
     this.collider      = collider;
     this.distanceField = distanceField;
 }