Example #1
0
        public DMesh3 getMesh()
        {
            BpcData pc = GetBakedPointCloud();

            ulong size;

            byte[] data = GetPackedMesh(out size);
            Console.WriteLine($"Rawmesh size: {size}");

            List <int> tris = new List <int>();

            if (size > 0)
            {
                for (int position = 0; position < (int)size; position += 12)
                {
                    tris.Add((int)BitConverter.ToUInt32(data, position));
                    tris.Add((int)BitConverter.ToUInt32(data, position + 4));
                    tris.Add((int)BitConverter.ToUInt32(data, position + 8));
                }
            }

            DMesh3 dmesh = DMesh3Builder.Build <Vector3d, int, int>(pc.positions, tris);

            if (pc.colors.Count() > 0)
            {
                dmesh.EnableVertexColors(new Vector3f());
                foreach (int idx in dmesh.VertexIndices())
                {
                    dmesh.SetVertexColor(idx, pc.colors.ElementAt(idx));
                }
            }
            return(dmesh);
        }
Example #2
0
        public static Task <BakedPointCloud> InitializeAsync(BpcData data)
        {
            Task <BakedPointCloud> t1 = new Task <BakedPointCloud>(() =>
            {
                return(Initialize(data));
            });

            t1.Start(TaskScheduler.FromCurrentSynchronizationContext());
            return(t1);
        }
Example #3
0
        public static BakedPointCloud Initialize(BpcData data)
        {
            BakedPointCloud bpc = new BakedPointCloud();

            bpc._pointCount = data.size;

            int width = Mathf.CeilToInt(Mathf.Sqrt(bpc._pointCount));

            bpc._positionMap            = new Texture2D(width, width, TextureFormat.RGBAFloat, false);
            bpc._positionMap.name       = "Position Map";
            bpc._positionMap.filterMode = FilterMode.Point;

            bpc._colorMap            = new Texture2D(width, width, TextureFormat.RGBA32, false);
            bpc._colorMap.name       = "Color Map";
            bpc._colorMap.filterMode = FilterMode.Point;

            int  i1 = 0;
            uint i2 = 0U;

            IEnumerator <Vector3d> position = data.positions.GetEnumerator();
            IEnumerator <Colorf>   color    = data.colors.GetEnumerator();

            position.MoveNext();
            color.MoveNext();


            for (int y = 0; y < width; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    int i = i1 < bpc.pointCount ? i1 : (int)(i2 % bpc._pointCount);

                    Vector3d p = position.Current;
                    Colorf   c = color.Current;

                    bpc._positionMap.SetPixel(x, y, new Color((float)p.x, (float)p.y, (float)p.z));
                    bpc._colorMap.SetPixel(x, y, c);

                    i1++;
                    i2 += 132049U; // prime

                    position.MoveNext();
                    color.MoveNext();
                }
            }

            bpc._positionMap.Apply(false, true);
            bpc._colorMap.Apply(false, true);
            return(bpc);
        }