//-----------------------------// //- Class methods implement. -// //-----------------------------// public void Initialize() { //Initialize already called successfully if (_isInitialized == true) { return; } if (_dataSource == null) { int key = 0; //if (_sourceType == SOURCE_TYPE.Network) //{ // key = Bridge4DS.CreateConnection(_connexionHost, _connexionPort); //} //Creates data source from the given path _dataSource = DataSource4DS.CreateDataSource(key, _sequenceName, _dataInStreamingAssets, _mainDataPath, (int)_activeRangeMin, (int)_activeRangeMax, _outRangeMode); if (_dataSource == null) { OnModelNotFound?.Invoke(); return; } } _lastModelId = -1; _meshComponent = GetComponent <MeshFilter>(); _rendererComponent = GetComponent <Renderer>(); _meshCollider = GetComponent <MeshCollider>(); _nbFrames = Bridge4DS.GetSequenceNbFrames(_dataSource.FDVUUID); Bridge4DS.SetSpeed(_dataSource.FDVUUID, _speedRatio); if (_sourceType == SOURCE_TYPE.Network) { Bridge4DS.SetHTTPDownloadSize(_dataSource.FDVUUID, _HTTPDownloadSize); Bridge4DS.SetHTTPKeepInCache(_dataSource.FDVUUID, _HTTPKeepInCache); } Bridge4DS.SetChunkBufferMaxSize(_dataSource.FDVUUID, _chunkBufferMaxSize); Bridge4DS.SetMeshBufferMaxSize(_dataSource.FDVUUID, _meshBufferMaxSize); //Allocates geometry buffers AllocateGeometryBuffers(ref _newVertices, ref _newUVs, ref _newNormals, ref _newTriangles, _dataSource.MaxVertices, _dataSource.MaxTriangles); //Allocates texture pixel buffer int pixelBufferSize = _dataSource.TextureSize * _dataSource.TextureSize / 2; //default is 4 bpp if (_dataSource.TextureFormat == TextureFormat.PVRTC_RGB2) //pvrtc2 is 2bpp { pixelBufferSize /= 2; } if (_dataSource.TextureFormat == TextureFormat.ASTC_RGBA_8x8) { int blockSize = 8; int xblocks = (_dataSource.TextureSize + blockSize - 1) / blockSize; pixelBufferSize = xblocks * xblocks * 16; } _newTextureData = new byte[pixelBufferSize]; //Gets pinned memory handle _newVerticesHandle = GCHandle.Alloc(_newVertices, GCHandleType.Pinned); _newUVsHandle = GCHandle.Alloc(_newUVs, GCHandleType.Pinned); _newTrianglesHandle = GCHandle.Alloc(_newTriangles, GCHandleType.Pinned); _newTextureDataHandle = GCHandle.Alloc(_newTextureData, GCHandleType.Pinned); _newNormalsHandle = GCHandle.Alloc(_newNormals, GCHandleType.Pinned); //Allocates objects buffers for double buffering _meshes = new Mesh[_nbGeometryBuffers]; _textures = new Texture2D[_nbTextureBuffers]; for (int i = 0; i < _nbGeometryBuffers; i++) { //Mesh Mesh mesh = new Mesh(); if (_dataSource.MaxVertices > MAX_SHORT) { mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32; } mesh.MarkDynamic(); //Optimize mesh for frequent updates. Call this before assigning vertices. mesh.vertices = _newVertices; mesh.uv = _newUVs; mesh.triangles = _newTriangles; mesh.normals = _newNormals; Bounds newBounds = mesh.bounds; newBounds.extents = new Vector3(4, 4, 4); mesh.bounds = newBounds; _meshes[i] = mesh; } for (int i = 0; i < _nbTextureBuffers; i++) { //Texture #if UNITY_2019_1_OR_NEWER if (_dataSource.TextureFormat == TextureFormat.ASTC_RGBA_8x8) //since unity 2019 ASTC RGBA is no more supported { _dataSource.TextureFormat = TextureFormat.ASTC_8x8; } #endif Texture2D texture = new Texture2D(_dataSource.TextureSize, _dataSource.TextureSize, _dataSource.TextureFormat, false) { wrapMode = TextureWrapMode.Clamp, filterMode = FilterMode.Bilinear }; texture.Apply(); //upload to GPU _textures[i] = texture; } _currentGeometryBuffer = _currentTextureBuffer = 0; _nbFrames = Bridge4DS.GetSequenceNbFrames(_dataSource.FDVUUID); _isInitialized = true; }