Unity3D 根据GIS中的二维线坐标画墙

本文介绍如何使用Unity3D结合GIS的二维线坐标,通过C#脚本生成并绘制墙体的示例,涉及mesh和纹理操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近研究了一下GameObject的mesh和纹理,特地写了一个demo来实现根据线生成墙

 代码如下:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class wasd : MonoBehaviour
{
    public Material mater;
    private GameObject gameObject;
    private GameObject simpleMesh;
    private float speed = 20f;



    private float mousespeed = 200f;

    Vector3 oldMousePosition;
    Vector3 newMousePosition;

    class GISPoint  
    {
        public float x;
        public float y;
        public GISPoint(float x1,float y1) 
        {
            x = x1;
            y = y1;
        }

    }

    void createWallByPoints(List<GISPoint> points,float wall_height, Mesh mesh)
    {
        float wall_height2 = 1.0f;
        float wall_length2 = 1.0f;
        int pntCount = points.Count;
        int rectCount = pntCount - 1;
        int vertCount = rectCount * 4;
      
        Vector3[] verts= new Vector3[vertCount];
       
        for (int i = 0; i < rectCount; i++)
        {
            verts[i*4] = new Vector3(points[i].x, 0, points[i].y);
            verts[i*4+1]= new Vector3(points[i].x, wall_height, points[i].y);
            verts[i*4+2] = new Vector3(points[i+1].x, wall_height, points[i+1].y);
            verts[i*4+3] = new Vector3(points[i+1].x, 0, points[i+1].y);
        }
        mesh.vertices = verts;

        int[] triangles = new int[rectCount * 2*3];

        //n=ponitIndex;   n(2n,2n+1)
        //p (3P,3P+1,3p+2)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值