public static SCNGeometrySource Create(List <SCNVector4> colors)
        {
            SCNGeometrySource result = null;

            unsafe
            {
                var bytes       = new List <byte>();
                var colorsArray = colors.ToArray();

                for (int i = 0; i < colors.Count; i++)
                {
                    fixed(SCNVector4 *point = &colorsArray[i])
                    {
                        var intPtr = new IntPtr(point);
                        var data   = NSData.FromBytes(intPtr, (nuint)SCNVector4.SizeInBytes);

                        bytes.AddRange(data.ToList());
                    }
                }

                var colorData = NSData.FromArray(bytes.ToArray());
                result = SCNGeometrySource.FromData(colorData,
                                                    SCNGeometrySourceSemantics.Color,
                                                    colors.Count,
                                                    true,
                                                    4,
                                                    sizeof(float),
                                                    0,
                                                    SCNVector4.SizeInBytes);
            }

            return(result);
        }
Exemple #2
0
        public void SCNGeometrySource_BoneStringTests()          // These were radar://17782603
        {
            Asserts.EnsureYosemite();

#pragma warning disable 0219
            SCNGeometrySource d = SCNGeometrySource.FromData(new NSData(), SCNGeometrySourceSemantic.BoneWeights, 1, false, 1, 1, 1, 1);
            d = SCNGeometrySource.FromData(new NSData(), SCNGeometrySourceSemantic.BoneIndices, 1, false, 1, 1, 1, 1);
#pragma warning restore 0219
        }
Exemple #3
0
        public void SCNGeometrySource_FromDataTest()
        {
            Asserts.EnsureMountainLion();
#pragma warning disable 0219
            SCNGeometrySource d = SCNGeometrySource.FromData(new NSData(), SCNGeometrySourceSemantic.Color, 1, false, 1, 1, 1, 1);
            foreach (SCNGeometrySourceSemantics s in Enum.GetValues(typeof(SCNGeometrySourceSemantics)))
            {
                if (!isValidEnumForPlatform(s))
                {
                    continue;
                }
                d = SCNGeometrySource.FromData(new NSData(), s, 1, false, 1, 1, 1, 1);
            }
#pragma warning restore 0219
        }
Exemple #4
0
        internal static SCNGeometry CreateVisualization(NVector3[] points, UIColor color, float size)
        {
            if (points.Length == 0)
            {
                return(null);
            }

            unsafe
            {
                var stride = sizeof(float) * 3;

                // Pin the data down so that it doesn't move
                fixed(NVector3 *pPoints = &points[0])
                {
                    // Grab a pointer to the data and treat it as a byte buffer of the appropriate length
                    var intPtr    = new IntPtr(pPoints);
                    var pointData = NSData.FromBytes(intPtr, (System.nuint)(stride * points.Length));

                    // Create a geometry source (factory) configured properly for the data (3 vertices)
                    var source = SCNGeometrySource.FromData(
                        pointData,
                        SCNGeometrySourceSemantics.Vertex,
                        points.Length,
                        true,
                        3,
                        sizeof(float),
                        0,
                        stride
                        );

                    // Don't unpin yet, because geometry creation is lazy

                    // Create geometry element
                    // The null and bytesPerElement = 0 look odd, but this is just a template object
                    var element = SCNGeometryElement.FromData(null, SCNGeometryPrimitiveType.Point, points.Length, 0);

                    element.PointSize = 0.001F;
                    element.MinimumPointScreenSpaceRadius = size;
                    element.MaximumPointScreenSpaceRadius = size;

                    // Stitch the data (source) together with the template (element) to create the new object
                    var pointsGeometry = SCNGeometry.Create(new[] { source }, new[] { element });

                    pointsGeometry.Materials = new[] { Utilities.Material(color) };
                    return(pointsGeometry);
                }
            }
        }