private async Task LoadModel(ModelId modelId) { try { models[modelId.Id].LoadState = LoadState.Loading; var data = await loader.Load(modelId.Name); if (data == null) { await LoadModel(ModelId.Missing); models[modelId.Id].Slice = models[TextureId.Missing.Id].Slice; models[modelId.Id].LoadState = LoadState.Missing; return; } models[modelId.Id].Slice = CreateModel(data); models[modelId.Id].LoadState = LoadState.Loaded; } catch { // TODO: StackOverflow // await LoadModel(ModelId.Error); models[modelId.Id].Slice = models[ModelId.Error.Id].Slice; models[modelId.Id].LoadState = LoadState.Failed; } }
public async Task <IModel> GetModel(string modelName, CancellationToken ct) { var cachedModel = _cache.Get(modelName); if (cachedModel != null) { return(cachedModel); } var model = _modelLoader.Load(await _metaRepository.GetModel(modelName, ct)); _cache.Put(model); return(model); }
public override void Load(XmlElement xmlNode) { base.Load(xmlNode); if (xmlNode.HasAttribute("Occluder")) { isOccluder = bool.Parse(xmlNode.GetAttribute("Occluder")); } if (xmlNode.HasAttribute("IgnoreDepth")) { ignoreDepth = bool.Parse(xmlNode.GetAttribute("IgnoreDepth")); } if (xmlNode.HasAttribute("AddToPhysicsEngine")) { AddToPhysicsEngine = bool.Parse(xmlNode.GetAttribute("AddToPhysicsEngine")); } int i = 0; if (xmlNode.ChildNodes[i].Name.Equals("ModelCreationInfo")) { XmlElement modelInfo = (XmlElement)xmlNode.ChildNodes[i]; if (modelInfo.HasAttribute("ResourceName")) { if (!modelInfo.HasAttribute("ModelLoaderName")) { throw new GoblinException("ModelLoaderName attribute is required if " + "ResourceName attribute is specified"); } String assetName = Path.ChangeExtension(modelInfo.GetAttribute("ResourceName"), null); IModelLoader loader = (IModelLoader)Activator.CreateInstance(Type.GetType( modelInfo.GetAttribute("ModelLoaderName"))); model = (IModel)loader.Load("", assetName); } else { if (!modelInfo.HasAttribute("CustomShapeParameters")) { throw new GoblinException("CustomShapeParameters attribute must be " + "specified if ResourceName is not specified"); } String[] primShapeParams = modelInfo.GetAttribute("CustomShapeParameters").Split(','); model = (IModel)Activator.CreateInstance(Type.GetType(xmlNode.ChildNodes[i + 1].Name), primShapeParams); } model.Load((XmlElement)xmlNode.ChildNodes[i + 1]); i += 2; } material = (Material)Activator.CreateInstance(Type.GetType(xmlNode.ChildNodes[i].Name)); material.Load((XmlElement)xmlNode.ChildNodes[i]); physicsProperties = (IPhysicsObject)Activator.CreateInstance(Type.GetType( xmlNode.ChildNodes[i + 1].Name)); physicsProperties.Load((XmlElement)xmlNode.ChildNodes[i + 1]); physicsProperties.Container = this; if (model is IPhysicsMeshProvider) { physicsProperties.MeshProvider = (IPhysicsMeshProvider)model; } physicsProperties.Model = model; }