public static VPObjectInstance AddObjectInstance(VPModel obj, OpenTK.Vector3 pos, OpenTK.Quaternion rot, OpenTK.Vector3 scale, object customData = null) { return(AddObjectInstance(obj, new VPObjectInstance( pos, rot, scale, customData))); }
public static VPObjectInstance AddTransform(VPModel obj, float unitMultiplier, SetObjectTransform child, Vector3 posOffset) { return(AddObjectInstance(obj, (child.Position * unitMultiplier) + posOffset, child.Rotation, child.Scale, child)); }
public static VPObjectInstance AddObjectInstance(VPModel obj, Vector3 pos, Quaternion rot, Vector3 scale, object customData = null) { return(AddObjectInstance(obj, new VPObjectInstance( Types.ToOpenTK(pos), Types.ToOpenTK(rot), Types.ToOpenTK(scale), customData))); }
// Methods public static VPObjectInstance GetInstance(VPModel model, object obj) { foreach (var instance in model.Instances) { if (instance.CustomData == obj) { return(instance); } } return(null); }
public static VPModel AddObjectModel(Model mdl, string name) { // Add/Replace Model var obj = new VPModel(mdl, true); if (!Objects.ContainsKey(name)) { Objects.Add(name, obj); } else { Objects[name] = obj; } return(obj); }
public static void GetObject(object obj, out VPModel mdl, out VPObjectInstance inst) { foreach (var model in Objects) { var instance = GetInstance(model.Value, obj); if (instance != null) { mdl = model.Value; inst = instance; return; } } mdl = DefaultCube; inst = GetInstance(DefaultCube, obj); }
public static VPModel AddModel(Model mdl, Dictionary <string, VPModel> dict) { // Add/Replace Model var m = new VPModel(mdl); if (!dict.ContainsKey(mdl.Name)) { dict.Add(mdl.Name, m); } else { dict[mdl.Name] = m; } return(m); }
// Methods public static void LoadDefaults() { // Load default model var watch = System.Diagnostics.Stopwatch.StartNew(); string cubePth = Path.Combine(Program.StartupPath, Program.ResourcesPath, $"DefaultCube{Model.MDLExtension}"); var mdl = new Model(); mdl.Load(cubePth); // Load default texture string defaultTexPath = Path.Combine(Program.StartupPath, Program.ResourcesPath, $"DefaultTexture{DDS.Extension}"); Texture defaultTex; if (File.Exists(defaultTexPath)) { defaultTex = new DDS(); defaultTex.Load(defaultTexPath); } else { defaultTex = new Texture() { Width = 1, Height = 1, PixelFormat = Texture.PixelFormats.RGB, MipmapCount = 1, ColorData = new byte[][] { new byte[] { 255, 255, 255 } } }; } // Setup default texture/material/model DefaultTexture = GenTexture(defaultTex); DefaultMaterial = new GensMaterial(); DefaultCube = new VPModel(mdl, true); watch.Stop(); Console.WriteLine("Default assets init time: {0}", watch.ElapsedMilliseconds); }
// Methods public static void SpawnObject(SetObject obj, VPModel mdl, Vector3 posOffset, float unitMultiplier = 1) { Program.MainUIInvoke(() => { var instance = AddObjectInstance(mdl, (obj.Transform.Position * unitMultiplier) + posOffset, obj.Transform.Rotation, obj.Transform.Scale, obj); if (obj.Children == null) { return; } foreach (var child in obj.Children) { if (child == null) { continue; } AddTransform(mdl, unitMultiplier, child, posOffset); } }); }
public static VPObjectInstance AddObjectInstance(VPModel obj, object customData = null) { return(AddObjectInstance(obj, new VPObjectInstance(customData))); }
public static VPObjectInstance AddObjectInstance(VPModel obj, VPObjectInstance instance) { obj.Instances.Add(instance); return(instance); }
public static VPModel LoadModel(string path, string resDir = null, bool isTerrain = false, bool loadMats = false, string group = null, bool nonEditable = true, GensTerrainInstanceInfo instInfo = null, bool spawnInstance = true) { // Figure out what type of model to use Model mdl; switch (Types.CurrentDataType) { case Types.DataTypes.Forces: case Types.DataTypes.LW: case Types.DataTypes.Gens: case Types.DataTypes.SU: mdl = new GensModel(); break; // TODO: Add Storybook Support case Types.DataTypes.Storybook: throw new NotImplementedException( "Could not load, Storybook terrain is not yet supported!"); // TODO: Add Colors Support case Types.DataTypes.Colors: throw new NotImplementedException( "Could not load, Colors terrain is not yet supported!"); // TODO: Add 06 Support case Types.DataTypes.S06: throw new NotImplementedException( "Could not load, '06 terrain is not yet supported!"); // TODO: Add Heroes/Shadow Support case Types.DataTypes.Shadow: case Types.DataTypes.Heroes: throw new NotImplementedException( "Could not load, Heroes/Shadow terrain is not yet supported!"); // TODO: Add SA2 Support case Types.DataTypes.SA2: throw new NotImplementedException( "Could not load, SA2 terrain is not yet supported!"); default: throw new Exception( "Could not load, game type has not been set!"); } // Get some information about the model string dir = Path.GetDirectoryName(path); string shortName = Path.GetFileNameWithoutExtension(path); Dictionary <string, VPModel> dict = null; VPObjectInstance instance = null; // Load the model if (mdl.GetType() == typeof(GensModel)) { if (isTerrain) { // Terrain Instance Info Program.MainUIInvoke(() => { dict = GetTerrainGroup(group, true); }); if (spawnInstance) { instance = (instInfo == null) ? new VPObjectInstance(shortName) : new VPObjectInstance(instInfo.TransformMatrix, instInfo.FileName); } // Don't bother loading the model again if we've // already loaded a model with the same name. if (dict.ContainsKey(shortName)) { if (spawnInstance) { Program.MainUIInvoke(() => { AddTerrainInstance(shortName, instance, group); }); } return(dict[shortName]); } } else { dict = Objects; } } // Model if (dict == null) { return(null); } if (dict.ContainsKey(shortName)) { LuaTerminal.LogWarning(string.Format( "WARNING: Skipped model \"{0}\" as a model with that {1}", shortName, "name has already been loaded!")); return(dict[shortName]); } else { mdl.Load(path); mdl.Name = shortName; } // Materials if (loadMats) { bool useResDirs = string.IsNullOrEmpty(resDir); var matExt = Types.MaterialExtension; foreach (var mesh in mdl.Meshes) { string pth = (useResDirs) ? null : Path.Combine(resDir, $"{mesh.MaterialName}{matExt}"); if (!useResDirs && File.Exists(pth)) { var mat = LoadMaterial(pth, mesh.MaterialName, nonEditable); if (mat != null) { continue; } } GetMaterial(mesh.MaterialName, nonEditable); } } VPModel vpMdl = null; Program.MainUIInvoke(() => { if (isTerrain) { vpMdl = (spawnInstance) ? AddModelInstance(mdl, instance, dict) : AddModel(mdl, dict); } else { vpMdl = AddObjectModel(mdl, shortName); } }); return(vpMdl); }