void LoadModels(string VideoFile) { StartedLoadingPrefabsEvent?.Invoke(); int total = CloudModels.Length; int cntr = 0; SceneModels = new List <SceneModel>(); var modelInstances = ModelInstances.Load(VideoFile); foreach (var cloudModel in CloudModels) { cntr += 1; var model = CloudAPI.Instance.GetModel(cloudModel.model); if (model.defaultPosition == null) { Log.Wrn($"no position for {cloudModel}, ignoring"); continue; } var pos = model.defaultPosition.GpsPos; var prefab = ModelAssets.LoadAsset(cloudModel.model); /* set trackable name to aid in debugging */ MainThreadRunner.Run(() => prefab.name = cloudModel.ToString()); var sceneModel = modelInstances.GetModel(cloudModel.model, cloudModel.name, prefab, pos); SceneModels.Add(sceneModel); PrefabLoadedEvent?.Invoke(cntr, total); } FinishedLoadingPrefabsEvent?.Invoke(); }
public static DateTimeModel GetModel(string culture, bool fallbackToDefaultCulture = true) { if (!ModelInstances.ContainsKey(culture)) { if (fallbackToDefaultCulture) { culture = DefaultCulture; } else { throw new Exception($"ERROR: The Culture {culture} is not supported now."); } } var model = ModelInstances[culture]; return(model); }
public static IModel GetModel <TModel>(string culture, bool fallbackToDefaultCulture = true) { if (!ModelInstances.ContainsKey(culture) || !ModelInstances[culture].ContainsKey(typeof(TModel))) { if (fallbackToDefaultCulture) { culture = DefaultCulture; } else { throw new Exception($"ERROR: No IModel instance for {typeof(TModel)}"); } } var model = ModelInstances[culture][typeof(TModel)]; return(model); }
public override void DrawModel(GameModel model, GameTime time) { //Overlay.Profiler ["DrawModel1"] += Knot3.Core.Game.Time (() => { string key = string.Join (";", (string)model.Info.Modelname, model.BaseColor.R, model.BaseColor.B, model.BaseColor.G, model.Alpha, model.HighlightColor.R, model.HighlightColor.B, model.HighlightColor.G, model.HighlightIntensity); if (!instanceHash.ContainsKey (key)) { instanceHash [key] = new ModelInstances { Model = model, WorldMatrices = new Matrix[200], Count = 0 }; Console.WriteLine ("new ModelInstances(" + key + ")"); } ModelInstances instances = instanceHash [key] as ModelInstances; if (instances.Count + 1 >= instances.WorldMatrices.Length) { Array.Resize (ref instances.WorldMatrices, instances.WorldMatrices.Length * 2); Console.WriteLine ("Resize: " + instances.WorldMatrices.Length); } instances.Model = model; instances.WorldMatrices [instances.Count++] = model.WorldMatrix; //}).TotalMilliseconds; }
public bool UpdatePtypes(List <AnnotatedNode> annotations, List <Ptype> newLib) { bool anyRemoved = RemoveDeletedAnnotations(annotations, ptypeData); bool needsUpdate = LoadDataFromAnnotations(annotations, ptypeData) || anyRemoved; Dictionary <string, Bitmap> images = new Dictionary <string, Bitmap>(); foreach (AnnotatedNode n in annotations) { if (!images.ContainsKey(n.ImageId)) { images.Add(n.ImageId, (Bitmap)n.Root["capturedpixels"]); } } List <BuildPrototypeArgs> buildargs = new List <BuildPrototypeArgs>(); List <Ptype.Mutable> ptypes = new List <Ptype.Mutable>(); foreach (PtypeMetadata data in ptypeData.Values) { if (data.NeedsUpdate) { List <Bitmap> positives = new List <Bitmap>(); List <Bitmap> negatives = new List <Bitmap>(); foreach (Example e in data.Examples) { Bitmap example = Bitmap.Crop(images[e.ImageId], e.Region); if (e.IsPositive) { positives.Add(example); } else { negatives.Add(example); } } Examples examples = new Examples(positives, negatives); BuildPrototypeArgs args = new BuildPrototypeArgs(examples, ModelInstances.Get(data.Ptype.Model), data.Ptype.Id); buildargs.Add(args); } else { ptypes.Add(data.Ptype); } } ptypes.AddRange(Ptype.BuildFromExamples(buildargs)); foreach (Ptype.Mutable ptype in ptypes) { PtypeMetadata data = ptypeData[ptype.Id]; data.Ptype.Features = ptype.Features; data.Ptype.Regions = ptype.Regions; data.Ptype.Model = ptype.Model; } SavePtypesToIntent(intent, ptypeData.Values); newLib.AddRange(Ptype.CreatePrototypeLibrary(ptypes)); return(needsUpdate); }