public Terrain(Device device, String texture, int pitch, Renderer renderer) { HeightMap = new System.Drawing.Bitmap(@"Data/Textures/"+texture); WaterShader = new WaterShader(device); TerrainShader = new TerrainShader(device); _width = HeightMap.Width-1; _height = HeightMap.Height-1; _pitch = pitch; _terrainTextures = new ShaderResourceView[4]; _terrainTextures[0] = new Texture(device, "Sand.png").TextureResource; _terrainTextures[1] = new Texture(device, "Grass.png").TextureResource; _terrainTextures[2] = new Texture(device, "Ground.png").TextureResource; _terrainTextures[3] = new Texture(device, "Rock.png").TextureResource; _reflectionClippingPlane = new Vector4(0.0f, 1.0f, 0.0f, 0.0f); _refractionClippingPlane = new Vector4(0.0f, -1.0f, 0.0f, 0.0f); _noClippingPlane = new Vector4(0.0f, 1.0f, 0.0f, 10000); _reflectionTexture = new RenderTexture(device, renderer.ScreenSize); _refractionTexture = new RenderTexture(device, renderer.ScreenSize); _renderer = renderer; _bitmap = new Bitmap(device,_refractionTexture.ShaderResourceView,renderer.ScreenSize, new Vector2I(100, 100), 0); _bitmap.Position = new Vector2I(renderer.ScreenSize.X - 100, 0); _bitmap2 = new Bitmap(device, _reflectionTexture.ShaderResourceView, renderer.ScreenSize, new Vector2I(100, 100), 0); _bitmap2.Position = new Vector2I(renderer.ScreenSize.X - 100, 120); _bumpMap = _renderer.TextureManager.Create("OceanWater.png"); _skydome = new ObjModel(device, "skydome.obj", renderer.TextureManager.Create("Sky.png")); BuildBuffers(device); WaveTranslation = new Vector2(0,0); }
private static void FillPolygon(ObjModel model, IList <string> args) { if (args.Count <= 2) { return; } var polygon = new Polygon(); foreach (var a in args) { var numStrs = a.Trim().Split('/'); var vIndex = FindIndex(model.Positions, numStrs[0]); uint?vtIndex = null; if (numStrs.Length >= 2) { if (!String.IsNullOrEmpty(numStrs[1])) { vtIndex = FindIndex(model.TextureCoords, numStrs[1]); } } uint?vnIndex = null; if (numStrs.Length == 3) { if (!String.IsNullOrEmpty(numStrs[2])) { vnIndex = FindIndex(model.Normals, numStrs[2]); } } polygon.Vertices.Add(new PolygonVertex(vIndex, vtIndex, vnIndex)); } if (polygon.Vertices.Count > 0) { model.Polygons.Add(polygon); } }
public Terrain(Device device, String texture, int pitch, Renderer renderer) { HeightMap = new System.Drawing.Bitmap(@"Data/Textures/" + texture); WaterShader = new WaterShader(device); TerrainShader = new TerrainShader(device); _width = HeightMap.Width - 1; _height = HeightMap.Height - 1; _pitch = pitch; _terrainTextures = new ShaderResourceView[4]; _terrainTextures[0] = new Texture(device, "Sand.png").TextureResource; _terrainTextures[1] = new Texture(device, "Grass.png").TextureResource; _terrainTextures[2] = new Texture(device, "Ground.png").TextureResource; _terrainTextures[3] = new Texture(device, "Rock.png").TextureResource; _reflectionClippingPlane = new Vector4(0.0f, 1.0f, 0.0f, 0.0f); _refractionClippingPlane = new Vector4(0.0f, -1.0f, 0.0f, 0.0f); _noClippingPlane = new Vector4(0.0f, 1.0f, 0.0f, 10000); _reflectionTexture = new RenderTexture(device, renderer.ScreenSize); _refractionTexture = new RenderTexture(device, renderer.ScreenSize); _renderer = renderer; _bitmap = new Bitmap(device, _refractionTexture.ShaderResourceView, renderer.ScreenSize, new Vector2I(100, 100), 0); _bitmap.Position = new Vector2I(renderer.ScreenSize.X - 100, 0); _bitmap2 = new Bitmap(device, _reflectionTexture.ShaderResourceView, renderer.ScreenSize, new Vector2I(100, 100), 0); _bitmap2.Position = new Vector2I(renderer.ScreenSize.X - 100, 120); _bumpMap = _renderer.TextureManager.Create("OceanWater.png"); _skydome = new ObjModel(device, "skydome.obj", renderer.TextureManager.Create("Sky.png")); BuildBuffers(device); WaveTranslation = new Vector2(0, 0); }
/// <summary> /// 创建jsonObject /// </summary> /// <param name="jsonObject"></param> /// <returns></returns> private ObjModel CreateJsonObject(object jsonObject) { ObjModel obj = new ObjModel(); if (jsonObject is JArray) { obj.FieldN = ""; obj.Opt = ""; obj.Value = ""; obj.Leaives = false; obj.JsonType = JsonType.Array; } else if (jsonObject is JObject) { obj.FieldN = ""; obj.Opt = ""; obj.Leaives = true; obj.JsonType = JsonType.Value; obj.Value = jsonObject; } else { obj.Leaives = true; obj.JsonType = JsonType.Value; obj.Value = jsonObject; } return(obj); }
/// <summary> /// /// </summary> /// <param name="objModel">Parsed ObjModel</param> /// <param name="objFolder">where the obj file resides</param> /// <param name="options"></param> public Converter(ObjModel objModel, string objFolder, GltfOptions options) { _objModel = objModel; _objFolder = objFolder; _options = options ?? new GltfOptions(); _buffers = new BufferState(_options.WithBatchTable); }
private static void FillLineSegments(ObjModel model, IList <string> args) { if (args.Count < 2) { return; } var segments = new LineSegments(); foreach (var a in args) { var numStrs = a.Trim().Split('/'); var vIndex = FindIndex(model.Positions, numStrs[0]); uint?vtIndex = null; if (numStrs.Length == 2) { if (!String.IsNullOrEmpty(numStrs[1])) { vtIndex = FindIndex(model.TextureCoords, numStrs[1]); } } segments.Vertices.Add(new LineVertex(vIndex, vtIndex)); } if (segments.Vertices.Count > 0) { model.Lines.Add(segments); } }
/// <summary> /// 添加树节点 /// </summary> /// <param name="obj"></param> /// <param name="jsonObject"></param> private void AddChildren(ObjModel obj, object jsonObject) { JObject javaScriptObject = jsonObject as JObject; if (javaScriptObject != null) { if (javaScriptObject.Count > 0 || obj.JsonType == JsonType.Value) { foreach (KeyValuePair <string, JToken> pair in javaScriptObject) { ParentModel = obj; obj.Nodes.Add(ConvertToObject(pair.Key, pair.Value)); } } } else { JArray javaScriptArray = jsonObject as JArray; if (javaScriptArray != null) { for (int i = 0; i < javaScriptArray.Count; i++) { JObject javaScriptObjectChild = javaScriptArray[i] as JObject; foreach (KeyValuePair <string, JToken> pair in javaScriptObjectChild) { ParentModel = obj; obj.Nodes.Add(ConvertToObject(pair.Key, pair.Value)); } } } } }
static void Main(string[] args) { using (var window = new Window(800, 800, "Rasteriser")) { var draw = new Drawer(window); var obj = new ObjModelRenderer(ObjModel.FromFile("E:/triangle.obj"), draw); var timer = new Stopwatch(); var frametime = 0f; while (true) { timer.Restart(); window.Clear(); obj.Draw(frametime); draw.End(); if (window.DispatchMessages()) { break; } timer.Stop(); frametime = (float)timer.Elapsed.TotalMilliseconds; window.SetTitle($"Rasteriser ({Math.Round(1 / timer.Elapsed.TotalSeconds, 2):0.00} FPS)"); } } }
public override void LoadContent(bool firstLoad) { // Check if the current input GUI override is still valid. If so, apply it. if (!string.IsNullOrEmpty(Settings.InputGui)) { string inputGuiPath = $"controls/{Settings.InputGui}/"; if (GFX.Gui.GetTextures().Any(kvp => kvp.Key.StartsWith(inputGuiPath))) { Input.OverrideInputPrefix = Settings.InputGui; } else { Settings.InputGui = ""; } } if (firstLoad && !Everest.Flags.AvoidRenderTargets) { SubHudRenderer.Buffer = VirtualContent.CreateRenderTarget("subhud-target", 1922, 1082); } if (Everest.Flags.AvoidRenderTargets && Celeste.HudTarget != null) { Celeste.HudTarget.Dispose(); Celeste.HudTarget = null; } if (GFX.MountainTerrain == null && Settings.NonThreadedGL) { GFX.MountainTerrain = ObjModel.Create(Path.Combine(Engine.ContentDirectory, "Overworld", "mountain.obj")); GFX.MountainBuildings = ObjModel.Create(Path.Combine(Engine.ContentDirectory, "Overworld", "buildings.obj")); GFX.MountainCoreWall = ObjModel.Create(Path.Combine(Engine.ContentDirectory, "Overworld", "mountain_wall.obj")); } // Otherwise loaded in GameLoader.LoadThread }
public bool RoundResetRoomF1(int round) { lock (this._lock) { if (this.LastRound != round) { if (Config.isTestMode) { Logger.warning("Reseting room. [Last: " + (object)this.LastRound + "; New: " + (object)round + "]", false); } DateTime now = DateTime.Now; this.LastRound = round; this._hasC4 = false; this.BombPosition = new Half3(); this._dropCounter = 0; this._objsSyncRound = 0; this._sourceToMap = this._mapId; if (!this._isBotMode) { for (int index = 0; index < 16; ++index) { Player player = this._players[index]; player._life = player._maxLife; } this.LastPlayersSync = now; this.Map = MappingXML.getMapById(this._mapId); List <ObjModel> objModelList = this.Map != null ? this.Map._objects : (List <ObjModel>)null; if (objModelList != null) { for (int index = 0; index < objModelList.Count; ++index) { ObjModel objModel = objModelList[index]; ObjectInfo objectInfo = this._objects[objModel._id]; objectInfo._life = objModel._life; if (!objModel._noInstaSync) { objModel.SetRandomAnimToObj(this, objectInfo); } else { objectInfo._anim = new AnimModel() { _nextAnim = 1 }; objectInfo.lastInteractionTime = now; } objectInfo._model = objModel; objectInfo.DestroyState = 0; MappingXML.SetObjectives(objModel, this); } } this.LastObjsSync = now; this._objsSyncRound = round; } return(true); } } return(false); }
/// <summary>Load resources here.</summary> protected override void OnLoad(EventArgs e) { base.OnLoad(e); GL.ClearColor(System.Drawing.Color.Blue); GL.Enable(EnableCap.DepthTest); GL.Enable(EnableCap.Texture2D); GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest); GL.Enable(EnableCap.CullFace); GL.ShadeModel(ShadingModel.Smooth); Light.Enable(); light.Position = new Vector3(10, 100, 10); light.UpdateColor(); light.SetLight(true); world.Add(light); skybox.LoadSkybox("sky/sky_", "jpg", 100); world.Add(skybox); carinfo.up = 0.2f; carinfo.down = 0.1f; carinfo.max = 5; car = new ObjModel("car", "car.obj", 2, 2, 2); car.FixRotation.Y = -90; car.Rotation.Y = 90; mesprite[0] = new ObjModel("sprite1", "ball.obj", 1, 1, 1); SetupSprite(mesprite[0]); mesprite[1] = new ObjModel("sprite2", "ball.obj", 1, 1, 1); SetupSprite(mesprite[1]); mesprite[2] = new ObjModel("sprite3", "ball.obj", 1, 1, 1); SetupSprite(mesprite[2]); mesprite[3] = new ObjModel("sprite4", "ball.obj", 1, 1, 1); SetupSprite(mesprite[3]); mesprite[4] = new ObjModel("sprite5", "ball.obj", 1, 1, 1); SetupSprite(mesprite[4]); meslock[0] = new ObjModel("lock1", "truck.obj", 1, 1, 1); SetupLock(meslock[0]); meslock[1] = new ObjModel("lock2", "truck.obj", 1, 1, 1); SetupLock(meslock[1]); meslock[2] = new ObjModel("lock3", "truck.obj", 1, 1, 1); SetupLock(meslock[2]); meslock[3] = new ObjModel("lock4", "truck.obj", 1, 1, 1); SetupLock(meslock[3]); meslock[4] = new ObjModel("lock5", "truck.obj", 1, 1, 1); SetupLock(meslock[4]); groundPlane.Load("2.jpg"); groundPlane.Position = new Vector3(0, -0.2f, 0); groundPlane.Rotation = new Vector3(90, 0, 0); world.Add(groundPlane); world.Add(car); Util.Set3DMode(); // Fog.CreateFog(FogMode.Exp, 20, 200, 0.02f); }
/// <summary> /// Reseta as informações da sala, caso a rodada seja válida. /// </summary> /// <param name="round">Rodada</param> /// <returns></returns> public bool RoundResetRoomF1(int round) { lock (_lock) { if (LastRound != round) { if (Config.isTestMode) { Printf.warning("Reseting room. [Last: " + LastRound + "; New: " + round + "]"); } DateTime now = DateTime.Now; LastRound = round; _hasC4 = false; BombPosition = new Half3(); _dropCounter = 0; _objsSyncRound = 0; _sourceToMap = _mapId; if (!_isBotMode) { for (int i = 0; i < 16; i++) { Player player = _players[i]; player._life = player._maxLife; } LastPlayersSync = now; Map = MappingXML.getMapById(_mapId); List <ObjModel> objsm = Map != null ? Map._objects : null; if (objsm != null) { for (int i = 0; i < objsm.Count; i++) { ObjModel ob = objsm[i]; ObjectInfo obj = _objects[ob._id]; obj._life = ob._life; if (!ob._noInstaSync) { ob.GetARandomAnim(this, obj); } else { obj._anim = new AnimModel { _nextAnim = 1 }; obj._useDate = now; } obj._model = ob; obj.DestroyState = 0; MappingXML.SetObjectives(ob, this); } } LastObjsSync = now; _objsSyncRound = round; } return(true); } } return(false); }
public bool RoundResetRoomS1(int round) { lock (this._lock) { if (this.LastRound != round) { if (Config.isTestMode) { Logger.warning("Reseting room. [Last: " + (object)this.LastRound + "; New: " + (object)round + "]", false); } this.LastRound = round; this._hasC4 = false; this._dropCounter = 0; this.BombPosition = new Half3(); if (!this._isBotMode) { for (int index = 0; index < 16; ++index) { Player player = this._players[index]; player._life = player._maxLife; } DateTime now = DateTime.Now; this.LastPlayersSync = now; for (int index = 0; index < this._objects.Length; ++index) { ObjectInfo objectInfo = this._objects[index]; ObjModel model = objectInfo._model; if (model != null) { objectInfo._life = model._life; if (!model._noInstaSync) { model.SetRandomAnimToObj(this, objectInfo); } else { objectInfo._anim = new AnimModel() { _nextAnim = 1 }; objectInfo.lastInteractionTime = now; } objectInfo.DestroyState = 0; } } this.LastObjsSync = now; this._objsSyncRound = round; if (this.stageType == 3 || this.stageType == 5) { this._bar1 = this._default1; this._bar2 = this._default2; } } return(true); } } return(false); }
/// <summary> /// Reseta as informações da sala, caso a rodada seja válida. /// </summary> /// <param name="round">Rodada</param> /// <returns></returns> public bool RoundResetRoomS1(int round) { lock (_lock) { if (LastRound != round) { if (Config.isTestMode) { Printf.warning("Reseting room. [Last: " + LastRound + "; New: " + round + "]"); } LastRound = round; _hasC4 = false; _dropCounter = 0; BombPosition = new Half3(); if (!_isBotMode) { for (int i = 0; i < 16; i++) { Player player = _players[i]; player._life = player._maxLife; } DateTime now = DateTime.Now; LastPlayersSync = now; for (int i = 0; i < _objects.Length; i++) { ObjectInfo obj = _objects[i]; ObjModel ob = obj._model; if (ob != null) { obj._life = ob._life; if (!ob._noInstaSync) { ob.GetARandomAnim(this, obj); } else { obj._anim = new AnimModel { _nextAnim = 1 }; obj._useDate = now; } obj.DestroyState = 0; } } LastObjsSync = now; _objsSyncRound = round; if ((stageType == 3 || stageType == 5)) { _bar1 = _default1; _bar2 = _default2; } } return(true); } } return(false); }
/// <summary> /// /// </summary> /// <param name="objs"></param> /// <param name="type">1 = Obj|2 = Players</param> public void SyncInfo(List <ObjectHitInfo> objs, int type) { lock (_lock2) { if (_isBotMode || !ObjectsIsValid()) { return; } DateTime now = DateTime.Now; double value = (now - LastObjsSync).TotalSeconds; double value2 = (now - LastPlayersSync).TotalSeconds; if (value >= 2.5 && (type & 1) == 1) { LastObjsSync = now; for (int i = 0; i < _objects.Length; i++) { ObjectInfo rObj = _objects[i]; ObjModel mObj = rObj._model; if (mObj != null && (mObj.isDestroyable && rObj._life != mObj._life || mObj._needSync)) { float SyncingTime = AllUtils.GetDuration(rObj._useDate); AnimModel anim = rObj._anim; if (anim != null && anim._duration > 0 && SyncingTime >= anim._duration) { mObj.GetAnim(anim._nextAnim, SyncingTime, anim._duration, rObj); } objs.Add(new ObjectHitInfo(mObj._updateId) { objSyncId = mObj._needSync ? 1 : 0, _animId1 = mObj._anim1, _animId2 = rObj._anim != null ? rObj._anim._id : 255, _destroyState = rObj.DestroyState, objId = mObj._id, objLife = rObj._life, _specialUse = SyncingTime }); } } } if (value2 >= 6.5 && (type & 2) == 2) { LastPlayersSync = now; for (int i = 0; i < _players.Length; i++) { Player pl = _players[i]; if (!pl.Immortal && (pl._maxLife != pl._life || pl.isDead)) { objs.Add(new ObjectHitInfo(4) { objId = pl._slot, objLife = pl._life }); } } } } }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { if (DialogResult.OK == openFileDialog1.ShowDialog()) { var model = ObjModel.FromFile(openFileDialog1.FileName); GlMain.Model = model; glControl1.Invalidate(); } }
public void Execute(List <string> param, ObjModel model) { foreach (var kv in model.meshDict) { Console.WriteLine("mesh: " + kv.Key); string[] names = param.Count > 0 ? param.ToArray() : null; Console.WriteLine(Utils.Dump(model.CurrentMesh, " ", names)); } }
/// <summary> /// run converter /// </summary> public void Run() { if (_model == null) { _model = new GltfModel(); //TODO: if (_objModel == null) { using (_objParser) { _objModel = _objParser.GetModel(); } } _model.Scenes.Add(new Scene()); var u32IndicesEnabled = RequiresUint32Indices(_objModel); var meshes = _objModel.Geometries; var meshesLength = meshes.Count; for (var i = 0; i < meshesLength; i++) { var mesh = meshes[i]; var meshIndex = AddMesh(_objModel, mesh, u32IndicesEnabled); AddNode(mesh.Id, meshIndex, null); } if (_model.Images.Count > 0) { _model.Samplers.Add(new Sampler { MagFilter = MagFilter.Linear, MinFilter = MinFilter.NearestMipmapLinear, WrapS = WrappingMode.Repeat, WrapT = WrappingMode.Repeat }); } var allBuffers = AddBuffers(_options.Name); _model.Buffers.Add(new Gltf.Buffer { Name = _options.Name, ByteLength = allBuffers.Count }); var boundary = 4; FillImageBuffers(allBuffers, boundary); if (!_options.Binary) { _model.Buffers[0].Uri = "data:application/octet-stream;base64," + Convert.ToBase64String(allBuffers.ToArray()); } else { _glb = GltfToGlb(allBuffers); } _model.Clean(); } }
/// <summary> /// when converted, generate tileset.json /// </summary> /// <param name="objModel">Parsed obj Model</param> /// <param name="outputPath">output folder</param> /// <param name="gisPosition">where the obj model positioned</param> /// <returns></returns> public static string WriteTilesetFile(ObjModel objModel, string objFolder, string outputPath, GisPosition gisPosition) { var singleTileset = WriteTileset(objModel, objFolder, outputPath, gisPosition); var tilesetFile = Path.Combine(outputPath, "tileset.json"); WriteTilesetJsonFile(tilesetFile, singleTileset); return(tilesetFile); }
private static ObjModel loadModelFile(ModAsset asset, string path) { if (ObjModelCache.TryGetValue(path, out ObjModel cached)) { return(cached); } ObjModel loaded = ObjModelExt.CreateFromStream(asset.Stream, path); ObjModelCache[path] = loaded; return(loaded); }
public void Start() { level = new ObjModel(@"ExportedObj;GameDA_3096.obj"); settings.AgentRadius = 0.2f; settings.AgentHeight = 1.0f; GenerateNavMesh(); //TargetPosition = ExportNavMeshToObj.ToUnityVector(smoothPath[CurrentNode]); //transform.position = TargetPosition; }
// Start is called before the first frame update void Start() { level = new ObjModel(@"ExportedObj;TestNavMesh_5.obj"); settings.AgentRadius = 0.5f; settings.AgentHeight = 1.0f; GenerateNavMesh(); TargetPosition = ExportNavMeshToObj.ToUnityVector(smoothPath[CurrentNode]); transform.position = TargetPosition; }
public static void TestObjModelOctreeMultiThread(int width, int height, EventHandler taskEndEventHandler) { UnionGeometry geometries = new UnionGeometry(); ObjModel objModel = new ObjModel("models/dinosaur.2k.obj"); Octree octree = new Octree(objModel.Triangles); geometries.Add(octree); Scene scene = new Scene(geometries, DefaultLight, ObjCamera); scene.Initialize(); scene.GetImage(width, height, taskEndEventHandler, 8, false, 3); }
/// <summary> /// json组装成ListMode /// </summary> /// <param name="rootObject"></param> public JsonObjectTree(object rootObject) { JObject javaScriptObject = rootObject as JObject; if (javaScriptObject != null) { foreach (KeyValuePair <string, JToken> pair in javaScriptObject) { ObjModel model = ConvertToObject(pair.Key, pair.Value); ListMode.Add(model); } } }
public FleetRenderer(IContext context) { _context = context; _shader = context.Shaders.Get<LightShader>(); _model = new ObjModel(context.DirectX.Device, "BasicBoat.obj", context.TextureManager.Create("Metal.png")); _baseOverlay = new TexturedRectangle(context, context.TextureManager.Create("fleet_overlay.dds", "Data/UI/")); _enemySubOverlay = new TexturedRectangle(context, context.TextureManager.Create("fleet_overlay_relation_enemy.dds", "Data/UI/")); _allySubOverlay = new TexturedRectangle(context, context.TextureManager.Create("fleet_overlay_relation_ally.dds", "Data/UI/")); _neutralSubOverlay = new TexturedRectangle(context, context.TextureManager.Create("fleet_overlay_relation_neutral.dds", "Data/UI/")); _mineSubOverlay = new TexturedRectangle(context, context.TextureManager.Create("fleet_overlay_relation_mine.dds", "Data/UI/")); foreach (Fleet fleet in context.World.FleetManager.Fleets) OnNewFleet(context, fleet); context.NotificationResolver.FleetMoved += f => OnFleetUpdate(context, f); }
private int AddMesh(ObjModel objModel, Geometry mesh, bool uint32Indices) { var ps = AddVertexAttributes(objModel, mesh, uint32Indices); var m = new Mesh { Name = mesh.Id, Primitives = ps }; var meshIndex = _model.Meshes.Count; _model.Meshes.Add(m); return(meshIndex); }
public Model(ObjModel model, string texturePath) { _meshes = new(); _texture = new(texturePath); List <Vertex> vertices = new(); List <uint> meshIndices = new(); List <uint[]> totalIndices = new(); long baseN = Math.Max(model.Positions.Count, Math.Max(model.TextureCoordinates.Count, model.Normals.Count)); Dictionary <long, uint> vertexLookup = new(); uint indexCounter = 0; foreach (ObjMesh mesh in model.Meshes) { meshIndices.Clear(); foreach (Vector3i vertex in mesh.Indices) { int posIndex = vertex[0] - 1; int texIndex = vertex[1] - 1; int norIndex = vertex[2] - 1; long encodedVertex = posIndex * baseN * baseN + texIndex * baseN + norIndex; if (vertexLookup.TryGetValue(encodedVertex, out uint index)) { meshIndices.Add(index); } else { vertices.Add(new Vertex( model.Positions[posIndex][0], model.Positions[posIndex][1], model.Positions[posIndex][2], model.TextureCoordinates[texIndex][0], model.TextureCoordinates[texIndex][1], model.Normals[norIndex][0], model.Normals[norIndex][1], model.Normals[norIndex][2] )); vertexLookup.Add(encodedVertex, indexCounter); meshIndices.Add(indexCounter); indexCounter++; } } totalIndices.Add(meshIndices.ToArray()); } _vbo = new(vertices, new() {
public static void TestObjModel(int width, int height, EventHandler taskEndEventHandler) { UnionGeometry geometries = new UnionGeometry(); ObjModel objModel = new ObjModel("models/dinosaur.2k.obj"); foreach (var triangle in objModel.Triangles) { geometries.Add(triangle); } Scene scene = new Scene(geometries, DefaultLight, ObjCamera); scene.Initialize(); scene.GetImage(width, height, taskEndEventHandler, 8, false, 3); }
static void GenerateNavMesh(string fileName) { NavMeshConfigurationFile file = new NavMeshConfigurationFile(); file.GenerationSettings.AgentRadius = 0.31f; file.ExportPath = fileName + ".snj"; NavMeshConfigurationFile.MeshSettings loadMesh = new NavMeshConfigurationFile.MeshSettings() { Path = fileName + ".obj", Position = new float[3], Scale = 1.0f }; file.InputMeshes.Add(loadMesh); List <string> meshes = new List <string>(); List <ObjModel> models = new List <ObjModel>(); foreach (var mesh in file.InputMeshes) { //Log.("Path: " + mesh.Path, 2); //Log.Debug("Scale: " + mesh.Scale, 2); //Log.Debug("Position: " + mesh.Position.ToString(), 2); meshes.Add(mesh.Path); SharpNav.Geometry.Vector3 position = new SharpNav.Geometry.Vector3(mesh.Position[0], mesh.Position[1], mesh.Position[2]); if (File.Exists(mesh.Path)) { ObjModel obj = new ObjModel(mesh.Path); float scale = mesh.Scale; //TODO SCALE THE OBJ FILE models.Add(obj); } else { //Log.Error("Mesh file does not exist."); return; } } var tris = Enumerable.Empty <SharpNav.Geometry.Triangle3>(); foreach (var model in models) { tris = tris.Concat(model.GetTriangles()); } TiledNavMesh navmesh = NavMesh.Generate(tris, file.GenerationSettings); new NavMeshJsonSerializer().Serialize(file.ExportPath, navmesh); }
public static void SabotageDestroy(Room room, Player pl, ObjModel objM, ObjectInfo obj, int damage) { if (objM._ultraSYNC > 0 && (room.stageType == 3 || room.stageType == 5)) { if (objM._ultraSYNC == 1 || objM._ultraSYNC == 3) { room._bar1 = obj._life; } else if (objM._ultraSYNC == 2 || objM._ultraSYNC == 4) { room._bar2 = obj._life; } Battle_SyncNet.SendSabotageSync(room, pl, damage, objM._ultraSYNC == 4 ? 2 : 1); } }
void Start() { string path = Application.dataPath + "/../Model/" + ObjName + ".obj"; string objText = File.ReadAllText(path); //解析obj文件 obj文件其实就是一个文本文件 ObjModel mode = ObjParse.ParseObj(objText); //加载材质球 if (!string.IsNullOrEmpty(mode.MtlName)) { string mtlPath = path.Substring(0, path.LastIndexOf('/') + 1) + mode.MtlName; mode.MatsDict = ObjParse.ParseMtl(File.ReadAllText(mtlPath)); } mode.CreateGameObject(); }
private void LoadThread() { Console.WriteLine("GAME DISPLAYED : " + Stopwatch.ElapsedMilliseconds + "ms"); MInput.Disabled = true; Audio.Init(); // Original code loads audio banks here. /* * Audio.Banks.Master = Audio.Banks.Load("Master Bank", true); * Audio.Banks.Music = Audio.Banks.Load("music", false); * Audio.Banks.Sfxs = Audio.Banks.Load("sfx", false); * Audio.Banks.UI = Audio.Banks.Load("ui", false); * Audio.Banks.NewContent = Audio.Banks.Load("new_content", false); */ Settings.Instance.ApplyVolumes(); audioLoaded = true; Fonts.Load(); // Luckily, the textures for the fonts are preloaded. Dialog.Load(); dialogLoaded = true; MInput.Disabled = false; if (!GFX.LoadedMainContent) { throw new Exception("GFX not loaded!"); } GFX.LoadData(); // Load all related GFX metadata. AreaData.Load(); if (!CoreModule.Settings.NonThreadedGL) { GFX.MountainTerrain = ObjModel.Create(Path.Combine(Engine.ContentDirectory, "Overworld", "mountain.obj")); GFX.MountainBuildings = ObjModel.Create(Path.Combine(Engine.ContentDirectory, "Overworld", "buildings.obj")); GFX.MountainCoreWall = ObjModel.Create(Path.Combine(Engine.ContentDirectory, "Overworld", "mountain_wall.obj")); } // Otherwise loaded in CoreModule.LoadContent Console.WriteLine("LOADED : " + Stopwatch.ElapsedMilliseconds + "ms"); Stopwatch.Stop(); Stopwatch = null; loaded = true; }
public Airplane(World world, State state, Game game, Renderer renderer, bool isPlayer, Airplane playerPlane, String name, String modelName) : base(game, renderer, isPlayer ? -1000 : 0) { IsPlayer = isPlayer; World = world; CurrentState = state; Name = name; ModelName = modelName; if (isPlayer) Commands = new PlayerAirplaneCommands(game.Input); else Commands = new ComputerAirplaneCommands(); PhysicalModel = new AirplanePhysicalModel(this, Commands); Model = new ObjModel(renderer.DirectX.Device, "Airplane.obj", Renderer.TextureManager.Create("Metal.png")); if(!isPlayer && ConfigurationManager.Config.DisplayOverlay) game.Register(new AirplaneOverlay(game, renderer, this, playerPlane)); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch (GraphicsDevice); AwesomeAsteroid = ObjModelLoader.LoadFromFile("Models/rock.obj"); asteroid = Texture2D.FromFile(graphics.GraphicsDevice,"Models/rock.jpg",256,256); gamePadTexture = Content.Load<Texture2D> ("gamepad.png"); var ship1t = gameType == GameType.Retro ? "Content/Retro/ship.pdf" : "Content/ship.pdf"; var ship2t = gameType == GameType.Retro ? "Content/Retro/ship.pdf" : "Content/ship-thrust.pdf"; var ship1 = Texture2D.FromFile(graphics.GraphicsDevice,ship1t,35,35); var ship2 = Texture2D.FromFile(graphics.GraphicsDevice,ship2t,35,35); ship = new Ship (ship1,ship2); //ship.Scale = .05f; bullet = new Sprite (Content.Load<Texture2D> ("shot-frame1")); //bullet.Scale = .05f; ReloadAsteroids(); myFont = Content.Load<SpriteFont> ("Fonts/SpriteFont1"); banner = Content.Load<Texture2D> ("BANNER"); var gamePadH = ScreenHeight - 100; var gamePadLeft = ScreenWidth -80; //Console.WriteLine (gamePadH); // Set the virtual GamePad ButtonDefinition BButton = new ButtonDefinition (); BButton.Texture = gamePadTexture; BButton.Position = new Vector2 (gamePadLeft, gamePadH + 10); BButton.Type = Buttons.B; BButton.TextureRect = new Rectangle (72, 77, 36, 36); ButtonDefinition AButton = new ButtonDefinition (); AButton.Texture = gamePadTexture; AButton.Position = new Vector2 (gamePadLeft - 75, gamePadH + 10); AButton.Type = Buttons.A; AButton.TextureRect = new Rectangle (73, 114, 36, 36); GamePad.ButtonsDefinitions.Add (BButton); GamePad.ButtonsDefinitions.Add (AButton); ThumbStickDefinition thumbStick = new ThumbStickDefinition (); thumbStick.Position = new Vector2 (50, gamePadH); thumbStick.Texture = gamePadTexture; thumbStick.TextureRect = new Rectangle (2, 2, 68, 68); GamePad.LeftThumbStickDefinition = thumbStick; }
public Sky(IContext context) { _skydome = new ObjModel(context.DirectX.Device, "skydome.obj", context.TextureManager.Create("Sky.png")); _shader = context.Shaders.Get<LightShader>(); }