#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Thu Aug 22 19:46:36 2019 @author: mysaa """ import numpy as np from data import CollageWorldChunk from perlin import CavernedNoise2,TestNoise def getTriangles(x0,y0,chunk,xp,yp,xy): nx,ny = chunk.size newChunk = CollageWorldChunk(chunk,xp,yp,xy) # pointIndexes = np.zeros((nx+1,ny+1),dtype=np.uint32) # pointLengthes = np.zeros((nx+1,ny+1),dtype=np.uint32) # points = [] # # # pos = 0 # for j in range(ny): # for i in range(nx): # carotte = [(x0+i/nx,y0+j/ny,z) for z in sorted([0.]+list(chunk.getColumn(i,j)))] # points += carotte # pointLengthes[i,j] = len(carotte) # pointIndexes[i,j] = pos # pos+=len(carotte) # carotte = [(x0+1,y0+j/ny,z) for z in sorted([0.]+list(xp.getColumn(0,j)))] # points += carotte # pointLengthes[nx,j]= len(carotte) # pointIndexes[nx,j] = pos # pos+=len(carotte) # for i in range(nx): # carotte = [(x0+i/nx,y0+1,z) for z in sorted([0.]+list(yp.getColumn(i,0)))] # points += carotte # pointLengthes[i,ny] = len(carotte) # pointIndexes[i,ny] = pos # pos+=len(carotte) # carotte = [(x0+1,y0+1,z) for z in sorted([0.]+list(xy.getColumn(0,0)))] # points += carotte # pointLengthes[nx,ny] = len(carotte) # pointIndexes[nx,ny] = pos points,pointIndexes = newChunk.getIndexed(fullCoords=True,addZero=True) points=[(p[0]/nx+x0,p[1]/ny+y0,p[2]) for p in points] pointLengthes = np.reshape([pointIndexes[i+1]-pointIndexes[i] for i in range(len(pointIndexes)-1)],(nx+1,ny+1)) pointIndexes = np.reshape(pointIndexes[:-1],(nx+1,ny+1)) print(points,pointIndexes,pointLengthes) triangles = [] for x in range(nx*2): for y in range(ny): # On récupère les coordonées entières du triangle indicé (x,y) if(x%2==0): col0=(x//2 ,y ) col1=(x//2+1,y ) col2=(x//2 ,y+1) else: col0=(x//2+1,y+1) col1=(x//2+1,y ) col2=(x//2 ,y+1) # On récupère la liste des points dans la colonne colonne0 = points[pointIndexes[col0[0],col0[1]]:pointIndexes[col0[0],col0[1]]+pointLengthes[col0[0],col0[1]]] colonne1 = points[pointIndexes[col1[0],col1[1]]:pointIndexes[col1[0],col1[1]]+pointLengthes[col1[0],col1[1]]] colonne2 = points[pointIndexes[col2[0],col2[1]]:pointIndexes[col2[0],col2[1]]+pointLengthes[col2[0],col2[1]]] #print("colonne:",colonne1) # st contient des triplets (numéro de colonne,index interne dans la colonne,coordonée z) st = [(0,i,colonne0[i][2]) for i in range(len(colonne0))] st += [(1,i,colonne1[i][2]) for i in range(len(colonne1))] st += [(2,i,colonne2[i][2]) for i in range(len(colonne2))] # On y trie par coordonée z st = sorted(st,key=lambda c:c[2]) #Liste des coordonées des colonnes, pour pouvoir sélectionner les coordonées selon l'index de la colonne cols = [col0,col1,col2] # Là, tout est bon à peu près i=0 try: while i