コード例 #1
0
        private void CreateResources(LoadedModelResources?modelResources, string?modelPath)
        {
            var isModelCached = _cachedResources.TryGetValue(modelPath ?? string.Empty, out var cachedResources);

            if (isModelCached)
            {
                _loadedResources = cachedResources.LoadedResources;
                _sharedResources = cachedResources.SharedResources;
            }
            else
            {
                if (modelResources is null)
                {
                    using (var modelStream = GraphicsProvider.Path2ModelStream(modelPath))
                    {
                        if (modelStream is null)
                        {
                            throw new FileNotFoundException(modelPath);
                        }

                        _loadedResources = ModelLoader.LoadModel(modelStream);
                    }
                }
                else
                {
                    _loadedResources = modelResources;
                }

                _sharedResources = CreateSharedResources(_loadedResources);

                if (!string.IsNullOrEmpty(modelPath))
                {
                    _cachedResources.Add(modelPath, new CachedModelResources
                    {
                        LoadedResources = _loadedResources,
                        SharedResources = _sharedResources,
                    });
                }
            }

            _instanceResources = CreateInstanceResources();
        }
コード例 #2
0
ファイル: ModelInstance.cs プロジェクト: ihaiucom/War3Net
        private void CreateResources(LoadedModelResources?modelResources, string?modelPath)
        {
            var isModelCached = _cachedResources.TryGetValue(modelPath ?? string.Empty, out var cachedResources);

            if (isModelCached)
            {
                _loadedResources = cachedResources.LoadedResources;
                _sharedResources = cachedResources.SharedResources;

                _batch = _modelBatches[cachedResources];
            }
            else
            {
                if (modelResources is null)
                {
                    using (var modelStream = GraphicsProvider.Path2ModelStream(modelPath !))
                    {
                        if (modelStream is null)
                        {
                            throw new FileNotFoundException(modelPath);
                        }

                        try
                        {
                            _loadedResources = ModelLoader.LoadModel(modelStream);
                        }
                        catch (Exception e)
                        {
                            throw new InvalidDataException($"Unable to load model: {modelPath}", e);
                        }
                    }
                }
                else
                {
                    _loadedResources = modelResources;
                }

                _sharedResources = CreateSharedResources(_loadedResources);

                cachedResources = new CachedModelResources
                {
                    LoadedResources = _loadedResources,
                    SharedResources = _sharedResources,
                };

                _batch = new ModelBatch
                {
                    Models = new HashSet <ModelInstance>(),
                };

                _modelBatches.Add(cachedResources, _batch);

                if (!string.IsNullOrEmpty(modelPath))
                {
                    _cachedResources.Add(modelPath, cachedResources);
                }
            }

            _instanceResources = CreateInstanceResources();

            _batch.Models.Add(this);
        }