我正在为Unity创建地球的3D球面,并且每个国家/地区都需要有一个多边形。每个国家/地区都有一组2D点,这些2D点会根据生成的内容转换为3D点。但是,当我创建多边形时,某些顶点连接不正确。 我用Maya用此代码创建了多边形
with open("C:\\Users\\patilanz\\Downloads\\geo_countries_medium.json") as f:
d = json.load(f)
def to_3d(x,y):
#convert from degrees to radians
longitude = math.radians(x)
latitude = math.radians(y)
# select a radius:
radius = 10
# project to 3d
return (
radius * math.cos(latitude) * math.cos(longitude),
radius * math.cos(latitude) * math.sin(longitude),
radius * math.sin(latitude)
)
for feat in d.get("features"):
r = []
coords = feat.get("geometry").get("coordinates")
type = feat.get("geometry").get("type")
for coord in coords:
for c in coord:
if type == "MultiPolygon":
r = []
for a in c:
r.append(to_3d(a[0],a[1]))
poly = cmds.polyCreateFacet(p=r)
poly = cmds.rename(feat.get("properties").get("name"))
else:
r.append(to_3d(c[0],c[1]))
if not type == "MultiPoligon":
poly = cmds.polyCreateFacet(p=r)
poly = cmds.rename(feat.get("properties").get("name"))
cmds.polySphere(r = 10 * 0.98)
The problem of incorrect joining vertices
我发现这个人正试图做同样的思考https://forum.processing.org/one/topic/drawing-countries-on-top-of-a-3d-sphere-from-set-of-boundaries.html
但是我不知道如何在Maya或Unity中实现它。