private Texture2D GetCameraTexture(int index, int width, int height)
        {
            int size = width * height;

            byte[] image = new byte[size];
            MapViewer.GetInstance().GetImage(index, out image[0]);

            byte alpha = 127;

            byte[] rawTextureData = new byte[size * 4];
            for (int j = 0; j < size; j++)
            {
                rawTextureData[j * 4 + 0] = alpha;
                rawTextureData[j * 4 + 1] = image[j];
                rawTextureData[j * 4 + 2] = image[j];
                rawTextureData[j * 4 + 3] = image[j];
            }

            Texture2D texture = new Texture2D(width, height, TextureFormat.ARGB32, false);

            texture.LoadRawTextureData(rawTextureData);
            texture.Apply();

            return(texture);
        }
Esempio n. 2
0
 internal static MapViewer GetInstance()
 {
     if (instance == null)
     {
         instance = new MapViewer();
     }
     return(instance);
 }
Esempio n. 3
0
        private Mesh CreateMapViewerMesh(int idx, Vector3[] vertices)
        {
            int verticesLength = vertices.Length;

            if (verticesLength == 0)
            {
                return(null);
            }

            int size = MapViewer.GetInstance().Create(idx);

            if (size == 0)
            {
                return(null);
            }

            int[]   indices   = new int[size];
            float[] texCoords = new float[verticesLength * 2];

            MapViewer.GetInstance().GetIndices(out indices[0]);
            MapViewer.GetInstance().GetTexCoords(out texCoords[0]);

            Vector2[] uvs = new Vector2[verticesLength];
            for (int j = 0; j < verticesLength; j++)
            {
                uvs[j][0] = texCoords[2 * j + 0];
                uvs[j][1] = texCoords[2 * j + 1];
            }

            Mesh mesh = new Mesh();

            mesh.vertices  = vertices;
            mesh.triangles = indices;
            mesh.uv        = uvs;
            mesh.RecalculateNormals();

            return(mesh);
        }
        private bool ReadMap(string fileName)
        {
            MapViewer.GetInstance().Deinitialize();
            if (!MapViewer.GetInstance().Initialize(fileName))
            {
                return(false);
            }

            IntPtr jsonPtr = MapViewer.GetInstance().GetJson();
            string json    = Marshal.PtrToStringAnsi(jsonPtr);

            if (json.Length < 1)
            {
                Debug.Log("Map is not opened");
                return(false);
            }

            Map3D map3D = JsonReader.Deserialize <Map3D>(json);

            int width  = map3D.width;
            int height = map3D.height;

            maxKeyframeCount = map3D.imageCount;

            vertices = new Vector3[map3D.vertexCount];
            for (int i = 0; i < map3D.vertexCount; i++)
            {
                vertices[i] = new Vector3(map3D.vertices[i].x, -map3D.vertices[i].y, map3D.vertices[i].z);
            }

            cameraMatrices = new Matrix4x4[maxKeyframeCount];
            for (int i = 0; i < maxKeyframeCount; i++)
            {
                for (int j = 0; j < 16; j++)
                {
                    cameraMatrices[i][j] = map3D.poseMatrices[i][j];
                }
                cameraMatrices[i] = cameraMatrices[i].inverse;
            }

            cameraRotations = new Quaternion[maxKeyframeCount];
            for (int i = 0; i < maxKeyframeCount; i++)
            {
                cameraRotations[i] = MatrixUtils.InvQuaternionFromMatrix(cameraMatrices[i]);
                Vector3 tempR = cameraRotations[i].eulerAngles;
                tempR.x            = -tempR.x;
                tempR.y            = -tempR.y;
                cameraRotations[i] = Quaternion.Euler(tempR);
            }

            Shader color = Shader.Find("Unlit/Texture");

            materials = new Material[maxKeyframeCount];
            for (int i = 0; i < maxKeyframeCount; i++)
            {
                materials[i]             = new Material(color);
                materials[i].mainTexture = GetCameraTexture(i, width, height);
            }

            return(true);
        }
        private bool ReadMap(string fileName)
        {
            MapViewer.GetInstance().Deinitialize();
            int length = MapViewer.GetInstance().Initialize(fileName);

            if (length == -1)
            {
                return(false);
            }

            byte[] jsonBuffer = new byte[length];
            MapViewer.GetInstance().GetJson(jsonBuffer, length);

            string json = Encoding.UTF8.GetString(jsonBuffer);

            if (json.Length < 1)
            {
                Debug.Log("Map is not opened");
                return(false);
            }

            Map3D map3D = JsonReader.Deserialize <Map3D>(json);

            int width  = map3D.width;
            int height = map3D.height;

            maxKeyframeCount = map3D.imageCount;

            vertices = new Vector3[map3D.vertexCount];
            for (int i = 0; i < map3D.vertexCount; i++)
            {
                vertices[i] = new Vector3(map3D.vertices[i].x, -map3D.vertices[i].y, map3D.vertices[i].z);
            }

            cameraMatrices = new Matrix4x4[maxKeyframeCount];
            for (int i = 0; i < maxKeyframeCount; i++)
            {
                for (int j = 0; j < 16; j++)
                {
                    cameraMatrices[i][j] = map3D.poseMatrices[i][j];
                }
                cameraMatrices[i] = cameraMatrices[i].inverse;
            }

            cameraRotations = new Quaternion[maxKeyframeCount];
            for (int i = 0; i < maxKeyframeCount; i++)
            {
                cameraRotations[i] = MatrixUtils.InvQuaternionFromMatrix(cameraMatrices[i]);
                Vector3 tempR = cameraRotations[i].eulerAngles;
                tempR.x            = -tempR.x;
                tempR.y            = -tempR.y;
                cameraRotations[i] = Quaternion.Euler(tempR);
            }

            Shader color = Shader.Find("Unlit/Texture");

            materials = new Material[maxKeyframeCount];
            for (int i = 0; i < maxKeyframeCount; i++)
            {
                materials[i]             = new Material(color);
                materials[i].mainTexture = GetCameraTexture(i, width, height);
            }

            if (map3D.tagAnchors != null)
            {
                TagAnchor[] anchors = map3D.tagAnchors;
                this.tagAnchors = anchors;
            }
            else
            {
                tagAnchors = null;
                Debug.Log("No Anchors");
            }
            return(true);
        }