예제 #1
0
 public static Mesh UpdateMesh(VuforiaManagerImpl.MeshData meshData, Mesh oldMesh, bool setNormalsUpwards, bool swapYZ)
 {
     if (meshData.numVertexValues == 0 || meshData.numTriangleIndices == 0)
     {
         return(null);
     }
     if (oldMesh == null)
     {
         oldMesh = new Mesh();
     }
     else
     {
         oldMesh.Clear();
     }
     MeshUtils.CopyPositions(meshData.positionsArray, meshData.numVertexValues, oldMesh, swapYZ);
     MeshUtils.CopyTriangles(meshData.triangleIdxArray, meshData.numTriangleIndices, oldMesh);
     if (meshData.hasNormals == 1)
     {
         MeshUtils.CopyNormals(meshData.normalsArray, meshData.numVertexValues, oldMesh, swapYZ);
     }
     else if (setNormalsUpwards)
     {
         Vector3[] array = new Vector3[meshData.numVertexValues / 3];
         for (int i = 0; i < array.Length; i++)
         {
             array[i] = Vector3.up;
         }
         oldMesh.normals = array;
     }
     else
     {
         oldMesh.RecalculateNormals();
     }
     if (meshData.hasTexCoords == 1)
     {
         MeshUtils.CopyTexCoords(meshData.texCoordsArray, meshData.numVertexValues * 2 / 3, oldMesh);
     }
     else
     {
         Vector2[] array2 = new Vector2[meshData.numVertexValues / 3];
         for (int j = 0; j < meshData.numVertexValues / 3; j++)
         {
             array2[j] = new Vector2(0.5f, 0.5f);
         }
         oldMesh.uv = array2;
     }
     return(oldMesh);
 }
예제 #2
0
        private void UpdateProps(VuforiaManagerImpl.SmartTerrainRevisionData[] smartTerrainRevisions, VuforiaManagerImpl.PropData[] updatedPropData)
        {
            List <Prop> list  = new List <Prop>();
            List <Prop> list2 = new List <Prop>();
            List <Prop> list3 = new List <Prop>();

            for (int i = 0; i < updatedPropData.Length; i++)
            {
                VuforiaManagerImpl.PropData propData = updatedPropData[i];
                bool     flag = false;
                PropImpl propImpl;
                bool     flag2;
                if (!this.mProps.ContainsKey(propData.id))
                {
                    propImpl = new PropImpl(propData.id, this.FindSmartTerrainTrackable(propData.parentID));
                    this.mProps.Add(propData.id, propImpl);
                    list.Add(propImpl);
                    flag2 = true;
                    flag  = true;
                }
                else
                {
                    propImpl = (PropImpl)this.mProps[propData.id];
                    flag2    = (propData.revision != propImpl.MeshRevision);
                }
                if (flag2)
                {
                    Mesh mesh = MeshUtils.UpdateMesh(propData.meshData, propImpl.GetMesh(), false, true);
                    if (flag)
                    {
                        propImpl.SetLocalPose(propData.localPose);
                    }
                    propImpl.SetMesh(propData.revision, mesh);
                    VuforiaManagerImpl.Obb3D boundingBox = propData.boundingBox;
                    OrientedBoundingBox3D    obb         = new OrientedBoundingBox3D(boundingBox.center, boundingBox.halfExtents, boundingBox.rotationZ * 57.29578f);
                    propImpl.SetObb(obb);
                    list2.Add(propImpl);
                }
                else
                {
                    Debug.LogError("Inconsistency: received updated Prop, but mesh revision is unchanged!");
                }
            }
            int[] array = new int[this.mProps.Count];
            this.mProps.Keys.CopyTo(array, 0);
            int[] array2 = array;
            for (int i = 0; i < array2.Length; i++)
            {
                int  num   = array2[i];
                bool flag3 = false;
                for (int j = 0; j < smartTerrainRevisions.Length; j++)
                {
                    if (smartTerrainRevisions[j].id == num)
                    {
                        flag3 = true;
                    }
                }
                if (!flag3)
                {
                    list3.Add(this.mProps[num]);
                    ((PropImpl)this.mProps[num]).DestroyMesh();
                    this.mProps.Remove(num);
                }
            }
            this.UnregisterDeletedProps(list3);
            foreach (Prop current in list3)
            {
                if (current.Parent != null)
                {
                    ((SmartTerrainTrackableImpl)current.Parent).RemoveChild(current);
                }
            }
            foreach (Prop current2 in list)
            {
                if (current2.Parent != null)
                {
                    ((SmartTerrainTrackableImpl)current2.Parent).AddChild(current2);
                }
            }
            this.NotifyPropEventHandlers(list, list2, list3);
        }
예제 #3
0
        private void UpdateSurfaces(VuforiaManagerImpl.SmartTerrainRevisionData[] smartTerrainRevisions, VuforiaManagerImpl.SurfaceData[] updatedSurfaceData)
        {
            List <Surface> list  = new List <Surface>();
            List <Surface> list2 = new List <Surface>();
            List <Surface> list3 = new List <Surface>();

            for (int i = 0; i < updatedSurfaceData.Length; i++)
            {
                VuforiaManagerImpl.SurfaceData surfaceData = updatedSurfaceData[i];
                bool        flag = false;
                SurfaceImpl surfaceImpl;
                bool        flag2;
                if (!this.mSurfaces.ContainsKey(surfaceData.id))
                {
                    surfaceImpl = new SurfaceImpl(surfaceData.id, this.FindSmartTerrainTrackable(surfaceData.parentID));
                    this.mSurfaces.Add(surfaceData.id, surfaceImpl);
                    list.Add(surfaceImpl);
                    flag2 = true;
                    flag  = true;
                }
                else
                {
                    surfaceImpl = (SurfaceImpl)this.mSurfaces[surfaceData.id];
                    flag2       = (surfaceData.revision != surfaceImpl.MeshRevision);
                }
                if (flag2)
                {
                    Mesh mesh = MeshUtils.UpdateMesh(surfaceData.meshData, surfaceImpl.GetMesh(), false, true);
                    if (flag)
                    {
                        surfaceImpl.SetLocalPose(surfaceData.localPose);
                    }
                    if (mesh != null)
                    {
                        Mesh navMesh = null;
                        if (this.mReconstruction.IsNavMeshUpdating())
                        {
                            navMesh = MeshUtils.UpdateMesh(surfaceData.navMeshData, surfaceImpl.GetNavMesh(), true, true);
                        }
                        int[] meshBoundaries = ReconstructionAbstractBehaviour.ReadMeshBoundaries(surfaceData.numBoundaryIndices, surfaceData.meshBoundaryArray);
                        surfaceImpl.SetMesh(surfaceData.revision, mesh, navMesh, meshBoundaries);
                    }
                    RectangleData boundingBox  = surfaceData.boundingBox;
                    Rect          boundingBox2 = new Rect(boundingBox.leftTopX, boundingBox.leftTopY, boundingBox.rightBottomX - boundingBox.leftTopX, boundingBox.rightBottomY - boundingBox.leftTopY);
                    surfaceImpl.SetBoundingBox(boundingBox2);
                    list2.Add(surfaceImpl);
                }
                else
                {
                    Debug.LogError("Inconsistency: received updated Surface, but mesh revision is unchanged!");
                }
            }
            int[] array = new int[this.mSurfaces.Count];
            this.mSurfaces.Keys.CopyTo(array, 0);
            int[] array2 = array;
            for (int i = 0; i < array2.Length; i++)
            {
                int  num   = array2[i];
                bool flag3 = false;
                for (int j = 0; j < smartTerrainRevisions.Length; j++)
                {
                    if (smartTerrainRevisions[j].id == num)
                    {
                        flag3 = true;
                    }
                }
                if (!flag3)
                {
                    list3.Add(this.mSurfaces[num]);
                    ((SurfaceImpl)this.mSurfaces[num]).DestroyMesh();
                    this.mSurfaces.Remove(num);
                }
            }
            this.UnregisterDeletedSurfaces(list3);
            foreach (Surface current in list3)
            {
                if (current.Parent != null)
                {
                    ((SmartTerrainTrackableImpl)current.Parent).RemoveChild(current);
                }
            }
            foreach (Surface current2 in list)
            {
                if (current2.Parent != null)
                {
                    ((SmartTerrainTrackableImpl)current2.Parent).AddChild(current2);
                }
            }
            this.NotifySurfaceEventHandlers(list, list2, list3);
        }