public void Initialize() { //Initialize already called successfully if (_isInitialized == true) { return; } if (_dataSource == null) { if (_sourceType == SOURCE_TYPE.Network) { //Creates data source from server ip _dataSource = DataSource4DS.CreateNetworkSource(_serverAddress, _serverPort); } else { //Creates data source from the given path (directory or sequence.xml) _dataSource = DataSource4DS.CreateDataSource(_sequenceName, _dataInStreamingAssets, _mainDataPath, (int)_activeRangeMin, (int)_activeRangeMax, _outRangeMode); } if (_dataSource == null) { if (onModelNotFound != null) { onModelNotFound(); } return; } } _lastModelId = -1; _meshComponent = GetComponent <MeshFilter>(); _rendererComponent = GetComponent <Renderer>(); _meshCollider = GetComponent <MeshCollider>(); Bridge4DS.SetComputeNormals(_dataSource.FDVUUID, _computeNormals); //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 #if USE_NATIVE_LIB _newVerticesHandle = GCHandle.Alloc(_newVertices, GCHandleType.Pinned); _newUVsHandle = GCHandle.Alloc(_newUVs, GCHandleType.Pinned); _newTrianglesHandle = GCHandle.Alloc(_newTriangles, GCHandleType.Pinned); _newTextureDataHandle = GCHandle.Alloc(_newTextureData, GCHandleType.Pinned); if (_computeNormals) { _newNormalsHandle = GCHandle.Alloc(_newNormals, GCHandleType.Pinned); } #endif //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(); mesh.MarkDynamic(); //Optimize mesh for frequent updates. Call this before assigning vertices. mesh.vertices = _newVertices; mesh.uv = _newUVs; mesh.triangles = _newTriangles; if (_computeNormals) { mesh.normals = _newNormals; } Bounds newBounds = mesh.bounds; newBounds.extents = new Vector3(10, 10, 10); mesh.bounds = newBounds; _meshes[i] = mesh; } for (int i = 0; i < _nbTextureBuffers; i++) { //Texture Texture2D texture = new Texture2D(_dataSource.TextureSize, _dataSource.TextureSize, _dataSource.TextureFormat, false); texture.wrapMode = TextureWrapMode.Clamp; texture.filterMode = FilterMode.Point; texture.Apply(); //upload to GPU _textures[i] = texture; } Bridge4DS.SetBuffering(_dataSource.FDVUUID, _bufferMode, _bufferSize); //Bridge4DS.SetCachingMode(_dataSource.FDVUUID, _cachingMode); _currentGeometryBuffer = _currentTextureBuffer = 0; if (_autoPlay) { Play(true); } _isInitialized = true; }