internal void UpdateBatchInformation(BatchInformation BatchInformation) { BatchInformation.VertexBuffer = _buffers.VertexBuffer; BatchInformation.IndexBuffer = _buffers.IndexBuffer; BatchInformation.PrimitiveCount = IndexCount / 3; BatchInformation.NumVertices = _vertices.Vertices.Length; }
public IActionResult SaveBatch() { int id = Request.Form["ID"].TryToInt(0); if (id > 0) { var info = _batchInformationService.GetBatchInfoById(id); info.Name = Request.Form["Name"].TryToString(); _batchInformationService.UpdateBatchInfo(info); return(Json(new { code = 1, msg = "OK", id = info.Id })); } else { BatchInformation batchInfo = new BatchInformation(); batchInfo.Name = Request.Form["Name"].TryToString(); batchInfo.CreateTime = DateTime.Now; id = _batchInformationService.AddBatchInfo(batchInfo); if (id > 0) { return(Json(new { code = 1, msg = "OK", id = id })); } else { return(Json(new { code = 0, msg = "保存失败" })); } } }
protected override void Draw(GameTime gt, IObject obj, RenderHelper render, ICamera cam, IList <ILight> lights) { _shader.Parameters["amplitude"].SetValue(amplitude); _shader.Parameters["gTime"].SetValue((float)gt.TotalGameTime.TotalMilliseconds); _shader.Parameters["timeScale"].SetValue(movimentSpeedControl); _shader.Parameters["xCamPos"].SetValue(cam.Position); _shader.Parameters["scaleX"].SetValue(scale.X); _shader.Parameters["scaleY"].SetValue(scale.Y); _shader.Parameters["xWorld"].SetValue(obj.PhysicObject.WorldMatrix); _shader.Parameters["xView"].SetValue(cam.View); _shader.Parameters["xProjection"].SetValue(cam.Projection); //_shader.Parameters["xBillboardTexture"].SetValue(obj.Modelo.getTexture(TextureType.DIFFUSE,0,0)); render.Textures[0] = obj.Modelo.getTexture(TextureType.DIFFUSE, 0, 0); _shader.Parameters["atenuation"].SetValue(atenuation); _shader.Parameters["xAllowedRotDir"].SetValue(allowRotDir); render.PushRasterizerState(RasterizerState.CullNone); BatchInformation batchInfo = obj.Modelo.GetBatchInformation(0)[0]; { _shader.Parameters["alphaTest"].SetValue(alphaTestLimit); render.RenderBatch(batchInfo, _shader); } render.PopRasterizerState(); }
public IActionResult Index() { var productViewModelList = new List <ProductInformationViewModel>(); var products = _productInformationService.GetAll(); foreach (var product in products) { BatchInformation batchInfo = _batchInformationService.GetBatchInfoById(product.BatchId); productViewModelList.Add(new ProductInformationViewModel { ProductId = product.Id, ProductCode = product.ProductCode, ProductName = product.ProductName, StockStatusName = GetStockStatusDisplayName((int)product.StockType), ProductStatusName = GetProductStatusDisplayName((int)product.ProductStatus), ClassTypeName = GetClassTypeDisplayName((int)product.Type), StockStatusType = product.StockType, ProductStatusType = product.ProductStatus, ClassType = product.Type, BatchId = product.BatchId, BatchName = batchInfo.Name }); } return(View(productViewModelList)); }
protected override void Draw(GameTime gt, IObject obj, RenderHelper render, ICamera cam, IList <ILight> lights) { Vector3 dir = cam.Target - cam.Position; dir.Normalize(); _shader.Parameters["forward"].SetValue(dir); _shader.Parameters["camUp"].SetValue(cam.Up); _shader.Parameters["scaleX"].SetValue(scale.X); _shader.Parameters["scaleY"].SetValue(scale.Y); _shader.Parameters["xWorld"].SetValue(obj.PhysicObject.WorldMatrix); _shader.Parameters["xView"].SetValue(cam.View); _shader.Parameters["xProjection"].SetValue(cam.Projection); //_shader.Parameters["xBillboardTexture"].SetValue(obj.Modelo.getTexture(TextureType.DIFFUSE,0,0)); render.Textures[0] = obj.Modelo.getTexture(TextureType.DIFFUSE, 0, 0); _shader.Parameters["atenuation"].SetValue(atenuation); render.PushRasterizerState(RasterizerState.CullNone); BatchInformation batchInfo = obj.Modelo.GetBatchInformation(0)[0]; { _shader.Parameters["alphaTest"].SetValue(alphaTestLimit); render.RenderBatch(batchInfo, _shader); } render.PopRasterizerState(); }
/// <summary> /// 新增界面 /// </summary> /// <returns></returns> public IActionResult AddNewBatch(int id) { BatchInformation batchInfo = new BatchInformation(); if (id > 0) { batchInfo = _batchInformationService.GetBatchInfoById(id); } return(View(batchInfo)); }
/// <summary> /// Loads the model. /// </summary> /// <param name="factory">The factory.</param> /// <param name="BatchInformations">The batch informations.</param> /// <param name="TextureInformations">The texture informations.</param> protected override void LoadModel(GraphicFactory factory, out BatchInformation[][] BatchInformations, out TextureInformation[][] TextureInformations) { skinnedModel = factory.GetAnimatedModel(Name); ModelBuilderHelper.Extract(factory, out BatchInformations, out TextureInformations, skinnedModel.Model,_diffuseName,_bumpName,_specularName,_glowName,isInternal); BoundingSphere sphere = new BoundingSphere(); foreach (var item in skinnedModel.Model.Meshes) { sphere = BoundingSphere.CreateMerged(sphere, item.BoundingSphere); } modelRadius = sphere.Radius; }
public IActionResult EditSave(BatchViewModel model) { BatchInformation batchInfo = new BatchInformation { Id = model.Id, Name = model.Name }; _batchInformationService.UpdateBatchInfo(batchInfo); return(RedirectToAction(nameof(Index))); }
public ActionResult Edit(int?id) { BatchViewModel model = new BatchViewModel(); if (id != null) { BatchInformation batchInfo = _batchInformationService.GetBatchInfoById((int)id); model = new BatchViewModel { Id = batchInfo.Id, Name = batchInfo.Name, BatchId = batchInfo.Id }; } return(View(model)); }
public IActionResult CreateSave(BatchViewModel model) { if (ModelState.IsValid) { BatchInformation batchInfo = new BatchInformation { Id = model.BatchId, Name = model.Name, CreateTime = DateTime.Now, }; _batchInformationService.CreateNew(batchInfo); return(RedirectToAction(nameof(Index))); } return(View()); }
protected override void Draw(GameTime gt, IObject obj, RenderHelper render, ICamera cam, IList <ILight> lights) { _shader.Parameters["size"].SetValue(size); _shader.Parameters["amplitude"].SetValue(amplitude); _shader.Parameters["timeScale"].SetValue(movimentSpeedControl); _shader.Parameters["scaleX"].SetValue(scale.X); _shader.Parameters["scaleY"].SetValue(scale.Y); _shader.Parameters["xWorld"].SetValue(obj.PhysicObject.WorldMatrix); //_shader.Parameters["xBillboardTexture"].SetValue(aniTex); render.device.Textures[0] = aniTex; _shader.Parameters["atenuation"].SetValue(atenuation); _shader.Parameters["forward"].SetValue(Vector3.Normalize(cam.Target - cam.Position)); if (bilboardType == BilboardType.Cilindric) { _shader.Parameters["xAllowedRotDir"].SetValue(allowRotDir); _shader.Parameters["cilindric"].SetValue(true); } else { _shader.Parameters["cilindric"].SetValue(false); _shader.Parameters["xAllowedRotDir"].SetValue(cam.Up); } _shader.Parameters["xProjection"].SetValue(cam.Projection); _shader.Parameters["start"].SetValue(start); _shader.Parameters["gTime"].SetValue((float)gt.TotalGameTime.TotalMilliseconds); _shader.Parameters["xView"].SetValue(cam.View); _shader.Parameters["xCamPos"].SetValue(cam.Position); render.PushRasterizerState(RasterizerState.CullNone); BatchInformation batchInfo = obj.Modelo.GetBatchInformation(0)[0]; { _shader.Parameters["alphaTest"].SetValue(alphaTestLimit); render.RenderBatch(batchInfo, _shader); } render.PopRasterizerState(); }
protected override void Draw(GameTime gt, IObject obj, RenderHelper render, ICamera cam, IList <ILight> lights) { _shader.Parameters["scaleX"].SetValue(scale.X); _shader.Parameters["scaleY"].SetValue(scale.Y); _shader.Parameters["xWorld"].SetValue(obj.PhysicObject.WorldMatrix); _shader.Parameters["xView"].SetValue(cam.View); _shader.Parameters["xProjection"].SetValue(cam.Projection); _shader.Parameters["xCamPos"].SetValue(cam.Position); _shader.Parameters["xAllowedRotDir"].SetValue(allowRotationDirection); //_shader.Parameters["xBillboardTexture"].SetValue(obj.Modelo.getTexture(TextureType.DIFFUSE,0,0)); render.device.Textures[0] = obj.Modelo.getTexture(TextureType.DIFFUSE, 0, 0); _shader.Parameters["atenuation"].SetValue(atenuation); BatchInformation batchInfo = obj.Modelo.GetBatchInformation(0)[0]; { _shader.Parameters["alphaTest"].SetValue(alphaTestLimit); SamplerState s7 = render.SetSamplerState(SamplerState.LinearClamp, 7); render.RenderBatch(batchInfo, _shader); render.SetSamplerState(s7, 7); } }
protected override void Draw(GameTime gt, IObject obj, RenderHelper render, ICamera cam, IList <ILight> lights) { System.Diagnostics.Debug.Assert(obj.Modelo is TerrainModel, "This shader expects a TerrainModel"); this._shader.Parameters["id"].SetValue(shaderId); this._shader.Parameters["BaseTexture"].SetValue(obj.Modelo.getTexture(TextureType.MULTITEX1, 0, 0)); this._shader.Parameters["blendDistance"].SetValue(blendDistance); this._shader.Parameters["blendWidth"].SetValue(blendWidth); this._shader.Parameters["nearTextureEspalhamento"].SetValue(nearTextureEspalhamento); this._shader.Parameters["farTextureEspalhamento"].SetValue(farTextureEspalhamento); Matrix World = obj.WorldMatrix; this._shader.Parameters["World"].SetValue(World); if (terrainType == TerrainType.MULTITEXTURE) { this._shader.Parameters["NivelAlto"].SetValue(obj.Modelo.getTexture(TextureType.MULTITEX4, 0, 0)); this._shader.Parameters["NivelMedio"].SetValue(obj.Modelo.getTexture(TextureType.MULTITEX3, 0, 0)); this._shader.Parameters["NivelBaixo"].SetValue(obj.Modelo.getTexture(TextureType.MULTITEX2, 0, 0)); this._shader.Parameters["nivelBaixoAltura"].SetValue(nivelBaixoAltura); this._shader.Parameters["nivelBaixoEspalhamento"].SetValue(nivelBaixoEspalhamento); this._shader.Parameters["nivelMedioAltura"].SetValue(nivelMedioAltura); this._shader.Parameters["nivelMedioEspalhamento"].SetValue(nivelMedioEspalhamento); this._shader.Parameters["nivelAltoAltura"].SetValue(nivelAltoAltura); this._shader.Parameters["nivelAltoEspalhamento"].SetValue(nivelAltoEspalhamento); this._shader.Parameters["nivelBaseAltura"].SetValue(nivelBaseAltura); this._shader.Parameters["nivelBaseEspalhamento"].SetValue(nivelBaseEspalhamento); } this._shader.Parameters["ViewProjection"].SetValue(cam.ViewProjection); BatchInformation batchInfo = obj.Modelo.GetBatchInformation(0)[0]; render.SetSamplerStates(SamplerState.LinearWrap, 6); //render.PushRasterizerState(RasterizerState.CullNone); render.RenderBatch(batchInfo, this._shader); //render.PopRasterizerState(); render.SetSamplerStates(ginfo.SamplerState, 6); }
/// <summary> /// 商品页面 /// </summary> /// <returns></returns> public IActionResult QueryProductList() { var productViewModelList = new List <ProductInformationViewModel>(); var products = _productInformationService.GetAll(); foreach (var product in products) { BatchInformation batchInfo = _batchInformationService.GetBatchInfoById(product.BatchId); productViewModelList.Add(new ProductInformationViewModel { ProductId = product.Id, ProductCode = product.ProductCode, ProductName = product.ProductName, StockStatusType = product.StockType, ProductStatusType = product.ProductStatus, ClassType = product.Type, BatchId = product.BatchId, BatchName = batchInfo != null?batchInfo.Name:string.Empty }); } return(View(productViewModelList)); }
protected override void Draw(GameTime gt, IObject obj, RenderHelper render, ICamera cam, IList <ILight> lights) { System.Diagnostics.Debug.Assert(obj.Modelo is InstancedBilboardModel, "This shader expects a InstancedBilboardModel"); _shader.Parameters["xWorld"].SetValue(obj.PhysicObject.WorldMatrix); //_shader.Parameters["xBillboardTexture"].SetValue(obj.Modelo.getTexture(TextureType.DIFFUSE,0,0)); render.device.Textures[0] = obj.Modelo.getTexture(TextureType.DIFFUSE, 0, 0); _shader.Parameters["atenuation"].SetValue(atenuation); _shader.Parameters["forward"].SetValue(Vector3.Normalize(cam.Target - cam.Position)); if (bilboardType == BilboardType.Cilindric) { _shader.Parameters["xAllowedRotDir"].SetValue(allowRotDir); _shader.Parameters["cilindric"].SetValue(true); } else { _shader.Parameters["cilindric"].SetValue(false); _shader.Parameters["xAllowedRotDir"].SetValue(cam.Up); } _shader.Parameters["xProjection"].SetValue(cam.Projection); _shader.Parameters["xView"].SetValue(cam.View); _shader.Parameters["xCamPos"].SetValue(cam.Position); render.PushRasterizerState(RasterizerState.CullNone); //render.PushDepthStencilState(DepthStencilState.None); BatchInformation batchInfo = obj.Modelo.GetBatchInformation(0)[0]; { _shader.Parameters["alphaTest"].SetValue(alphaTestLimit); render.RenderBatch(batchInfo, _shader); } //render.PopDepthStencilState(); render.PopRasterizerState(); }
protected override void LoadModel(GraphicFactory factory, out BatchInformation[][] BatchInformations, out TextureInformation[][] TextureInformation) { vertexBufferS = factory.CreateDynamicVertexBuffer(VertexPositionTexture.VertexDeclaration, vertices.Count(), BufferUsage.None); vertexBufferS.SetData(vertices); int noVertices = vertices.Count(); int noTriangles = indices.Count() / 3; indexBufferS = factory.CreateDynamicIndexBuffer(IndexElementSize.ThirtyTwoBits, indices.Count(), BufferUsage.None); indexBufferS.SetData(indices); BatchInformations = new BatchInformation[1][]; BatchInformation[] b = new BatchInformation[1]; b[0] = new BatchInformation(0, noVertices, noTriangles, 0, 0, VertexPositionTexture.VertexDeclaration, VertexPositionTexture.VertexDeclaration.VertexStride, BatchType.INDEXED); b[0].VertexBuffer = vertexBufferS; b[0].IndexBuffer = indexBufferS; BatchInformations[0] = b; TextureInformation = new TextureInformation[1][]; TextureInformation[0] = new TextureInformation[1]; TextureInformation[0][0] = new TextureInformation(false, factory); TextureInformation[0][0].SetTexture(diffuseName, TextureType.DIFFUSE); }
public IActionResult ProductListData(int page, int limit) { List <ProductInformationViewModel> productList = new List <ProductInformationViewModel>(); var productinfos = _productInformationService.GetList(page, limit); if (productinfos.Item1 != null && productinfos.Item1.Count > 0) { foreach (var product in productinfos.Item1) { BatchInformation batchInfo = _batchInformationService.GetBatchInfoById(product.BatchId); ProductInformationViewModel vm = new ProductInformationViewModel(); vm.Id = product.Id; vm.Code = product.ProductCode; vm.Name = product.ProductName; vm.StockStatusType = product.StockType; vm.ProductStatusType = product.ProductStatus; vm.ClassType = product.Type; vm.BatchId = product.BatchId; vm.BatchName = batchInfo != null ? batchInfo.Name : string.Empty; productList.Add(vm); } } return(Json(new { code = 0, msg = "", count = productinfos.Item2, data = productList.ToArray() })); }
public void CreateNew(BatchInformation batchInfo) { _batchInformationRepository.CreateNew(batchInfo); _unitOfWork.SaveChanges(); }
/// <summary> /// Computes the loss error gradient w.r.t the output. /// </summary> /// <param name="colTop">top output blob vector, /// providing the error gradient with respect to the outputs. /// </param> /// <param name="rgbPropagateDown">see Layer::Backward. propagate_down[1] must be false as /// we can't compute gradients with respect to the labels.</param> /// <param name="colBottom">bottom input blob vector /// </param> protected override void backward(BlobCollection <T> colTop, List <bool> rgbPropagateDown, BlobCollection <T> colBottom) { if (!rgbPropagateDown[0]) { return; } // Get input which should be a list of int's where // each entry is the input image index for each // batch item input. BatchInput bi = m_fnGetInput(); List <int> rgLastInput = bi.InputData as List <int>; m_log.CHECK(rgLastInput != null, "The last input should be of type List<int> and should not be null!"); m_log.CHECK_EQ(colTop[0].num, rgLastInput.Count, "The last input should have the same number of items in top[0]."); int nBatchSize = colTop[0].num; int nNumOutput = colTop[0].channels; T[] rgTop = colTop[0].update_cpu_data(); T[] rgBottom = new T[rgTop.Length]; for (int i = 0; i < nBatchSize; i++) { // Get the maximum output float fPreQ = -float.MaxValue; int nPreQIdx = -1; for (int j = 0; j < nNumOutput; j++) { int nIdx = (i * nNumOutput) + j; float fOutput = (float)Convert.ChangeType(rgTop[nIdx], typeof(float)); if (fOutput > fPreQ) { nPreQIdx = nIdx; fPreQ = fOutput; } } // Get the reinforcement info. BatchInformationCollection col = m_param.reinforcement_loss_param.BatchInfoCollection; // Set the maximum output to: maxout = (terminal) ? R : R + lambda * qmax1 // Set all other outputs to zero. float fTarget = (float)Convert.ChangeType(rgTop[nPreQIdx], typeof(float)); if (col != null) { BatchInformation batchInfo = col[bi.BatchIndex]; BatchItem batchItem = batchInfo[i]; // clip to range of -1,1 fTarget = clip((float)batchItem.Reward, -0.9f, 0.9f); if (!batchItem.Terminal) { fTarget += (float)(m_param.reinforcement_loss_param.discount_rate * batchItem.QMax1); } } float fDiff = fTarget - fPreQ; float fDelta = clip(fDiff, -0.9f, 0.9f); rgBottom[nPreQIdx] = (T)Convert.ChangeType(fDelta, typeof(T)); } colBottom[0].mutable_cpu_diff = rgBottom; }
public void UpdateBatchInfo(BatchInformation batchInfo) { _batchInformationRepository.UpdateBatchInfo(batchInfo); _unitOfWork.SaveChanges(); }
protected override void LoadContent(Engine.GraphicInfo GraphicInfo, GraphicFactory factory) { base.LoadContent(GraphicInfo, factory); effect = factory.GetEffect("skybox", false, true); this.factory = factory; cubeVertices = new VertexPositionNormalTexture[36]; Vector3 topLeftFront = new Vector3(-1.0f, 1.0f, 1.0f); Vector3 bottomLeftFront = new Vector3(-1.0f, -1.0f, 1.0f); Vector3 topRightFront = new Vector3(1.0f, 1.0f, 1.0f); Vector3 bottomRightFront = new Vector3(1.0f, -1.0f, 1.0f); Vector3 topLeftBack = new Vector3(-1.0f, 1.0f, -1.0f); Vector3 topRightBack = new Vector3(1.0f, 1.0f, -1.0f); Vector3 bottomLeftBack = new Vector3(-1.0f, -1.0f, -1.0f); Vector3 bottomRightBack = new Vector3(1.0f, -1.0f, -1.0f); Vector2 textureTopLeft = new Vector2(0.0f, 0.0f); Vector2 textureTopRight = new Vector2(1.0f, 0.0f); Vector2 textureBottomLeft = new Vector2(0.0f, 1.0f); Vector2 textureBottomRight = new Vector2(1.0f, 1.0f); Vector3 frontNormal = new Vector3(0.0f, 0.0f, 1.0f); Vector3 backNormal = new Vector3(0.0f, 0.0f, -1.0f); Vector3 topNormal = new Vector3(0.0f, 1.0f, 0.0f); Vector3 bottomNormal = new Vector3(0.0f, -1.0f, 0.0f); Vector3 leftNormal = new Vector3(-1.0f, 0.0f, 0.0f); Vector3 rightNormal = new Vector3(1.0f, 0.0f, 0.0f); // Front face cubeVertices[0] = new VertexPositionNormalTexture( topLeftFront, frontNormal, textureTopLeft); cubeVertices[1] = new VertexPositionNormalTexture( bottomLeftFront, frontNormal, textureBottomLeft); cubeVertices[2] = new VertexPositionNormalTexture( topRightFront, frontNormal, textureTopRight); cubeVertices[3] = new VertexPositionNormalTexture( bottomLeftFront, frontNormal, textureBottomLeft); cubeVertices[4] = new VertexPositionNormalTexture( bottomRightFront, frontNormal, textureBottomRight); cubeVertices[5] = new VertexPositionNormalTexture( topRightFront, frontNormal, textureTopRight); // Back face cubeVertices[6] = new VertexPositionNormalTexture( topLeftBack, backNormal, textureTopRight); cubeVertices[7] = new VertexPositionNormalTexture( topRightBack, backNormal, textureTopLeft); cubeVertices[8] = new VertexPositionNormalTexture( bottomLeftBack, backNormal, textureBottomRight); cubeVertices[9] = new VertexPositionNormalTexture( bottomLeftBack, backNormal, textureBottomRight); cubeVertices[10] = new VertexPositionNormalTexture( topRightBack, backNormal, textureTopLeft); cubeVertices[11] = new VertexPositionNormalTexture( bottomRightBack, backNormal, textureBottomLeft); // Top face cubeVertices[12] = new VertexPositionNormalTexture( topLeftFront, topNormal, textureBottomLeft); cubeVertices[13] = new VertexPositionNormalTexture( topRightBack, topNormal, textureTopRight); cubeVertices[14] = new VertexPositionNormalTexture( topLeftBack, topNormal, textureTopLeft); cubeVertices[15] = new VertexPositionNormalTexture( topLeftFront, topNormal, textureBottomLeft); cubeVertices[16] = new VertexPositionNormalTexture( topRightFront, topNormal, textureBottomRight); cubeVertices[17] = new VertexPositionNormalTexture( topRightBack, topNormal, textureTopRight); // Bottom face cubeVertices[18] = new VertexPositionNormalTexture( bottomLeftFront, bottomNormal, textureTopLeft); cubeVertices[19] = new VertexPositionNormalTexture( bottomLeftBack, bottomNormal, textureBottomLeft); cubeVertices[20] = new VertexPositionNormalTexture( bottomRightBack, bottomNormal, textureBottomRight); cubeVertices[21] = new VertexPositionNormalTexture( bottomLeftFront, bottomNormal, textureTopLeft); cubeVertices[22] = new VertexPositionNormalTexture( bottomRightBack, bottomNormal, textureBottomRight); cubeVertices[23] = new VertexPositionNormalTexture( bottomRightFront, bottomNormal, textureTopRight); // Left face cubeVertices[24] = new VertexPositionNormalTexture( topLeftFront, leftNormal, textureTopRight); cubeVertices[25] = new VertexPositionNormalTexture( bottomLeftBack, leftNormal, textureBottomLeft); cubeVertices[26] = new VertexPositionNormalTexture( bottomLeftFront, leftNormal, textureBottomRight); cubeVertices[27] = new VertexPositionNormalTexture( topLeftBack, leftNormal, textureTopLeft); cubeVertices[28] = new VertexPositionNormalTexture( bottomLeftBack, leftNormal, textureBottomLeft); cubeVertices[29] = new VertexPositionNormalTexture( topLeftFront, leftNormal, textureTopRight); // Right face cubeVertices[30] = new VertexPositionNormalTexture( topRightFront, rightNormal, textureTopLeft); cubeVertices[31] = new VertexPositionNormalTexture( bottomRightFront, rightNormal, textureBottomLeft); cubeVertices[32] = new VertexPositionNormalTexture( bottomRightBack, rightNormal, textureBottomRight); cubeVertices[33] = new VertexPositionNormalTexture( topRightBack, rightNormal, textureTopRight); cubeVertices[34] = new VertexPositionNormalTexture( topRightFront, rightNormal, textureTopLeft); cubeVertices[35] = new VertexPositionNormalTexture( bottomRightBack, rightNormal, textureBottomRight); vertexBuffer = factory.CreateVertexBuffer(VertexPositionNormalTexture.VertexDeclaration, 36, BufferUsage.None); vertexBuffer.SetData <VertexPositionNormalTexture>(cubeVertices); bi = new BatchInformation(0, 36, 23, 0, 0, VertexPositionNormalTexture.VertexDeclaration, VertexPositionNormalTexture.VertexDeclaration.VertexStride, BatchType.NORMAL); bi.VertexBuffer = vertexBuffer; }
public static IObject[] CreateOBJ(IWorld world, GraphicFactory factory, GraphicInfo ginfo, ObjectInformation[] mi) { IModelo model = new CustomModel(factory, mi); MaterialDescription material; if (mi[0].staticfriction == -1 || mi[0].dinamicfriction == -1 || mi[0].ellasticity == -1) { material = MaterialDescription.DefaultBepuMaterial(); } else { material = new MaterialDescription(mi[0].staticfriction, mi[0].dinamicfriction, mi[0].ellasticity); } IPhysicObject po; bool massflag = false; if (mi[0].mass == 0) { massflag = true; mi[0].mass = 0.5f; } BatchInformation binf = model.GetBatchInformation(0)[0]; BoundingBox bb; switch (mi[0].collisionType) { case "Ghost": po = new GhostObject(mi[0].position, Matrix.CreateFromQuaternion(mi[0].rotation), mi[0].scale); break; case "Cylinder": binf.ModelLocalTransformation = Matrix.Identity; bb = ModelBuilderHelper.CreateBoundingBoxFromModel(binf); Vector3 len = bb.Max - bb.Min; po = new CylinderObject(mi[0].position, len.Y, len.X / 2, Vector3.Up, mi[0].mass, Matrix.CreateFromQuaternion(mi[0].rotation), material); break; case "Sphere": binf.ModelLocalTransformation = Matrix.Identity; po = new SphereObject(mi[0].position, model.GetModelRadius(), mi[0].mass, mi[0].scale.X, material); po.Rotation = Matrix.CreateFromQuaternion(mi[0].rotation); break; case "Box": bb = ModelBuilderHelper.CreateBoundingBoxFromModel(binf); len = bb.Max - bb.Min; po = new BoxObject(mi[0].position, len.X, len.Y, len.Z, mi[0].mass, mi[0].scale, Matrix.CreateFromQuaternion(mi[0].rotation), material); break; case "Water": po = new GhostObject(mi[0].position, Matrix.CreateFromQuaternion(mi[0].rotation), mi[0].scale); break; case "TriangleMesh": default: po = new TriangleMeshObject(model, Vector3.Zero, Matrix.Identity, new Vector3(1), material); break; } po.isMotionLess = massflag; IShader shader = null; #if !REACH && !WINDOWS_PHONE if (mi[0].HasTexture(TextureType.ENVIRONMENT)) { shader = new DeferredEMReflectiveShader(); (shader as DeferredEMReflectiveShader).TextureCube = mi[0].textureInformation.getCubeTexture(TextureType.ENVIRONMENT); } else if (mi[0].collisionType != null && mi[0].collisionType.Contains("Water")) { Vector3 position = (Vector3)(mi[0].extra["position"]); var width = (mi[0].extra["width"]); var height = (mi[0].extra["length"]); shader = new DeferredWaterCompleteShader((int)width, (int)height, new Plane(position.X, position.Y, position.Z, 1), 10.0f); } else { shader = new DeferredCustomShader(mi[0].HasTexture(TextureType.GLOW), mi[0].HasTexture(TextureType.BUMP), mi[0].HasTexture(TextureType.SPECULAR), mi[0].HasTexture(TextureType.PARALAX)); } DeferredMaterial dm = new DeferredMaterial(shader); #else shader = new ForwardXNABasicShader(); ForwardMaterial dm = new ForwardMaterial(shader); #endif IObject ob = new IObject(dm, model, po); ob.Name = mi[0].modelName; return(new IObject[] { ob }); }
/// <summary> /// Helper to get the vertex and index List from the model. /// </summary> /// <param name="vert">The vert.</param> /// <param name="ind">The ind.</param> /// <param name="model">The model.</param> private void ExtractData(ref Vector3[] vert, ref int[] ind, IModelo model) { List <Vector3> vertices = new List <Vector3>(); List <int> indices = new List <int>(); for (int i = 0; i < model.MeshNumber; i++) { BatchInformation[] bi = model.GetBatchInformation(i); for (int j = 0; j < bi.Length; j++) { BatchInformation info = bi[j]; int offset = vertices.Count; Vector3[] a = new Vector3[info.NumVertices]; // Read the format of the vertex buffer VertexDeclaration declaration = bi[j].VertexBuffer.VertexDeclaration; VertexElement[] vertexElements = declaration.GetVertexElements(); // Find the element that holds the position VertexElement vertexPosition = new VertexElement(); foreach (VertexElement elem in vertexElements) { if (elem.VertexElementUsage == VertexElementUsage.Position && elem.VertexElementFormat == VertexElementFormat.Vector3) { vertexPosition = elem; // There should only be one break; } } // Check the position element found is valid if (vertexPosition == null || vertexPosition.VertexElementUsage != VertexElementUsage.Position || vertexPosition.VertexElementFormat != VertexElementFormat.Vector3) { throw new Exception("Model uses unsupported vertex format!"); } // This where we store the vertices until transformed // Read the vertices from the buffer in to the array bi[j].VertexBuffer.GetData <Vector3>( bi[j].BaseVertex * declaration.VertexStride + vertexPosition.Offset, a, 0, bi[j].NumVertices, declaration.VertexStride); for (int k = 0; k != a.Length; ++k) { Vector3.Transform(ref a[k], ref info.ModelLocalTransformation, out a[k]); } vertices.AddRange(a); if (info.IndexBuffer.IndexElementSize != IndexElementSize.SixteenBits) { int[] s = new int[info.PrimitiveCount * 3]; info.IndexBuffer.GetData <int>(info.StartIndex * 2, s, 0, info.PrimitiveCount * 3); for (int k = 0; k != info.PrimitiveCount; ++k) { indices.Add(s[k * 3 + 2] + offset); indices.Add(s[k * 3 + 1] + offset); indices.Add(s[k * 3 + 0] + offset); } } else { short[] s = new short[info.PrimitiveCount * 3]; info.IndexBuffer.GetData <short>(info.StartIndex * 2, s, 0, info.PrimitiveCount * 3); for (int k = 0; k != info.PrimitiveCount; ++k) { indices.Add(s[k * 3 + 2] + offset); indices.Add(s[k * 3 + 1] + offset); indices.Add(s[k * 3 + 0] + offset); } } } } ind = indices.ToArray(); vert = vertices.ToArray(); }
public int AddBatchInfo(BatchInformation batchInfo) { return(_batchInformationRepository.AddBatchInfo(batchInfo)); }