private void gpu_generateGrassOnObject(GameObject superficie) { Mesh meshSuperficie = superficie.GetComponent <MeshFilter>().sharedMesh; ComputeBuffer i_trisBuffer = new ComputeBuffer(meshSuperficie.triangles.Length, sizeof(int), ComputeBufferType.Structured); ComputeBuffer i_verticesBuffer = new ComputeBuffer(meshSuperficie.vertices.Length, sizeof(float) * 3, ComputeBufferType.Structured); ComputeBuffer o_pastoBuffer = new ComputeBuffer((meshSuperficie.triangles.Length / 3) * pastoPorMetro * 2, sizeof(float) * 3 * 4, ComputeBufferType.Append); int kernel = compute.FindKernel("crearPastito"); uint threadGroupSize; int dispatchSize; i_verticesBuffer.SetData(meshSuperficie.vertices); i_trisBuffer.SetData(meshSuperficie.triangles); configComputeShader(i_trisBuffer, i_verticesBuffer, o_pastoBuffer, kernel); compute.GetKernelThreadGroupSizes(kernel, out threadGroupSize, out _, out _); dispatchSize = Mathf.CeilToInt(((float)meshSuperficie.triangles.Length) / threadGroupSize); Debug.Log("dispatchSize: " + dispatchSize); compute.Dispatch(kernel, dispatchSize, 1, 1); Pasto[] pastos = new Pasto[o_pastoBuffer.count]; o_pastoBuffer.GetData(pastos, 0, 0, o_pastoBuffer.count); foreach (Pasto pasto in pastos) { if (!float.IsNaN(pasto.a.x)) { agregarPastoAMesh(pasto); } } Debug.Log("Cantidad de pasto: " + pastos.Length); }
public ActionResult Index(Pasto pasto) { PastoMessageId message = PastoMessageId.Error; int id = 0; try { if (pasto != null) { if (pasto.Id > 0) { pasto.Save(); id = pasto.Id; message = PastoMessageId.SaveSucess; } else { pasto.Fazenda = SysPec.App.Helpers.Current.FazendaId; pasto.Add(); id = pasto.Id; message = PastoMessageId.AddSuccess; } } } catch (Exception) { return(RedirectToAction("Index", new { message = PastoMessageId.Error })); } return(RedirectToAction("Index", new { PastoId = id, message = message })); }
private void agregarPastoAMesh(Pasto pasto) { int iA = mesh.addVertice(pasto.a); int iB = mesh.addVertice(pasto.b); int iC = mesh.addVertice(pasto.c); int iD = mesh.addVertice(pasto.d); mesh.addTriangle(iA, iB, iD); mesh.addTriangle(iB, iC, iD); mesh.addTriangle(iC, iA, iD); }
public Pasto ConsultaPorID(int PastoID) { try { //Limpa e adiciona os parâmetros acessoDadosSqlServer.LimparParametros(); acessoDadosSqlServer.AdicionarParametros("@TipoProcedure", "ID"); acessoDadosSqlServer.AdicionarParametros("@PastoID", PastoID); acessoDadosSqlServer.AdicionarParametros("@PastoDescricao", ""); acessoDadosSqlServer.AdicionarParametros("@CidadeID", 0); acessoDadosSqlServer.AdicionarParametros("@ContratoAluguelID ", 0); //Cria uma DataTable pois a store procedure returna uma tabela de dados DataTable dataTable = acessoDadosSqlServer.ExecutarConsulta(CommandType.StoredProcedure, "uspConsultaPasto"); PiqueteNegocios piqueteNegocios = new PiqueteNegocios(); foreach (DataRow row in dataTable.Rows) { Pasto pasto = new Pasto(); pasto.Cidade = new Cidade(); pasto.ContratoAluguel = new ContratoAluguel(); pasto.PastoID = Convert.ToInt32(row["PastoID"]); pasto.PastoDescricao = row["PastoDescricao"].ToString(); pasto.PastoTamanho = Convert.ToDecimal(row["PastoTamanho"]); pasto.PastoAtivo = Convert.ToBoolean(row["PastoAtivo"]); if (int.TryParse(row["ContratoAluguelID"].ToString(), out int ContratoAluguel)) { pasto.ContratoAluguel.ContratoAluguelID = ContratoAluguel; } pasto.Cidade.CidadeID = Convert.ToInt32(row["CidadeID"]); pasto.Cidade.CidadeNome = row["CidadeNome"].ToString(); pasto.Cidade.EstadoID = Convert.ToInt32(row["EstadoID"]); pasto.Cidade.EstadoNome = row["EstadoNome"].ToString(); pasto.Cidade.EstadoSigla = row["EstadoSigla"].ToString(); pasto.Piquetes = new PiqueteCollection(); pasto.Piquetes = piqueteNegocios.ConsultarPorPasto(pasto.PastoID); return(pasto); } return(null); } catch (Exception ex) { throw new Exception(ex.Message); } }
public int Alterar(Pasto pasto, PiqueteCollection piquetesRemocao) { try { //Limpa todos os parâmetros acessoDadosSqlServer.LimparParametros(); //Adiciona os parâmetros para chamar a store procedure acessoDadosSqlServer.AdicionarParametros("@TipoProcedure", "Alterar"); acessoDadosSqlServer.AdicionarParametros("@PastoID", pasto.PastoID); acessoDadosSqlServer.AdicionarParametros("@PastoDescricao", pasto.PastoDescricao); acessoDadosSqlServer.AdicionarParametros("@PastoTamanho", pasto.PastoTamanho); acessoDadosSqlServer.AdicionarParametros("@PastoAtivo", pasto.PastoAtivo); acessoDadosSqlServer.AdicionarParametros("@CidadeID", pasto.Cidade.CidadeID); if (pasto.ContratoAluguel.ContratoAluguelID != 0) { acessoDadosSqlServer.AdicionarParametros("@ContratoAluguelID", pasto.ContratoAluguel.ContratoAluguelID); } else { acessoDadosSqlServer.AdicionarParametros("@ContratoAluguelID", null); } acessoDadosSqlServer.ExecutarManipulacao(CommandType.StoredProcedure, "uspManterPasto"); if (pasto.Piquetes != null) { PiqueteNegocios piqueteNegocios = new PiqueteNegocios(); foreach (Piquete piquete in pasto.Piquetes) { if (piquete.PiqueteID == 0) { piqueteNegocios.Cadastrar(piquete, pasto.PastoID); } } foreach (Piquete piquete in piquetesRemocao) { piqueteNegocios.Excluir(piquete.PiqueteID); } } return(pasto.PastoID); } catch (Exception ex) { throw new Exception(ex.Message); } }
public ActionResult Index(int?PastoId, PastoMessageId?message) { ViewBag.StatusMessage = message == PastoMessageId.AddSuccess ? "Pasto adicionado com sucesso." : message == PastoMessageId.SaveSucess ? "Pasto atualizado com sucesso." : message == PastoMessageId.Error ? "Ocorreu um erro durante a operação. Tente novamente mais tarde." : ""; ViewBag.PastoExiste = PastoId.HasValue && PastoId > 0; if (ViewBag.PastoExiste) { return(View(Pasto.Get(PastoId.Value))); } return(View()); }
public int Cadastrar(Pasto pasto) { try { //Limpa todos os parâmetros acessoDadosSqlServer.LimparParametros(); //Adiciona os parâmetros para chamar a store procedure acessoDadosSqlServer.AdicionarParametros("@TipoProcedure", "Inserir"); acessoDadosSqlServer.AdicionarParametros("@PastoID", 0); acessoDadosSqlServer.AdicionarParametros("@PastoDescricao", pasto.PastoDescricao); acessoDadosSqlServer.AdicionarParametros("@PastoTamanho", pasto.PastoTamanho); acessoDadosSqlServer.AdicionarParametros("@PastoAtivo", true); acessoDadosSqlServer.AdicionarParametros("@CidadeID", pasto.Cidade.CidadeID); if (pasto.ContratoAluguel.ContratoAluguelID != 0) { acessoDadosSqlServer.AdicionarParametros("@ContratoAluguelID", pasto.ContratoAluguel.ContratoAluguelID); } else { acessoDadosSqlServer.AdicionarParametros("@ContratoAluguelID", null); } int ID = int.Parse(acessoDadosSqlServer.ExecutarManipulacao(CommandType.StoredProcedure, "uspManterPasto")); PiqueteNegocios piqueteNegocios = new PiqueteNegocios(); foreach (Piquete piquete in pasto.Piquetes) { piqueteNegocios.Cadastrar(piquete, ID); } return(ID); } catch (Exception ex) { throw new Exception(ex.Message); } }
public ActionResult Index(Fazenda fazenda, [Bind(Prefix = "Pasto")] Pasto pasto) { FazendaMessageId message = FazendaMessageId.Error; int id = 0; try { if (fazenda != null) { if (fazenda.Id > 0) { fazenda.Save(); id = fazenda.Id; message = FazendaMessageId.SaveSucess; } else { fazenda.Criador = Helpers.Current.CriadorId; fazenda.Add(); id = fazenda.Id; message = FazendaMessageId.AddSuccess; Helpers.Current.Fazendas = Fazendas.List(Helpers.Current.CriadorId); Helpers.Current.FazendaId = id; } if (pasto != null && !string.IsNullOrEmpty(pasto.Nome) && pasto.QtdAnimaisSuporte > 0) { pasto.Fazenda = fazenda.Id; pasto.Add(); } } } catch (Exception) { return(RedirectToAction("Index", new { message = FazendaMessageId.Error })); } return(RedirectToAction("Index", new { FazendaId = id, message = message })); }