def loadMesh(self, mesh, scale, color): self.scale = scale x = self.Position.x y = self.Position.y z = self.Position.z with open(mesh, "r") as m: self.meshData = json.load(m) self.vertices = [] for v in self.meshData["vertices"]: self.verticesData.append(Vertex(Vector(v[0], v[1], v[2]))) self.triangles = [] for t in self.meshData["triangles"]: self.createTriangle(t[0], t[1], t[2]) #v json jsou data o barve if ("colors" in self.meshData): self.colors = [] for c in self.meshData["colors"]: self.colors.append(c) else: self.createColor(color)
def updateMesh(self): self.vertices = [] for i, v in enumerate(self.verticesData): vertex = Vector(self.Position.x + v.Position.x*self.scale, self.Position.y + v.Position.y*self.scale, self.Position.z + v.Position.z*self.scale) vertex = vertex.rotateAround(self.Position, self.Rotation) self.vertices.append(Vertex(vertex))
def drawLines(self, screen): nul = Vertex(0, 0, 0) x1 = Vertex(self.scale, 0, 0) x2 = Vertex(-self.scale, 0, 0) y1 = Vertex(0, self.scale, 0) y2 = Vertex(0, -self.scale, 0) z1 = Vertex(0, 0, self.scale) z2 = Vertex(0, 0, -self.scale) edge1 = Edge(self.engine, x1, x2).drawEdge(screen) edge2 = Edge(self.engine, y1, y2).drawEdge(screen) edge3 = Edge(self.engine, z1, z2).drawEdge(screen) """if (self.isInFrontOfCamera(self.engine.camera, x1, nul)):
def createVertices(self): self.mesh.verticesData = [] self.mesh.triangles = [] for x in range(self.width): for z in range(self.height): self.mesh.verticesData.append( Vertex( Vector(self.Position.x + x, self.Position.y, self.Position.z + z))) i = 0 for x in range(self.width - 1): for z in range(self.height): if (i + self.width + 1 < len(self.mesh.verticesData)): self.mesh.createTriangle(i + 1, i, i + self.width) self.mesh.createTriangle(i + 1, i + self.width, i + self.width + 1) i += 1 self.mesh.scale = self.scale
def drawRadius(self, screen): step = 40 for i in range(0, 360, step): radian = i*math.pi/180 x1 = self.Position.x + self.radius*math.sin(radian) y1 = self.Position.y + self.radius*math.cos(radian) radian = (i+step)*math.pi/180 x2 = self.Position.x + self.radius*math.sin(radian) y2 = self.Position.y + self.radius*math.cos(radian) a1 = Vertex(x1,y1,self.Position.z) a2 = Vertex(x2,y2,self.Position.z) edge = Edge(self.engine, a1, a2).drawEdge(screen) for i in range(0, 360, step): radian = i*math.pi/180 z1 = self.Position.z + self.radius*math.sin(radian) y1 = self.Position.y + self.radius*math.cos(radian) radian = (i+step)*math.pi/180 z2 = self.Position.z + self.radius*math.sin(radian) y2 = self.Position.y + self.radius*math.cos(radian) a1 = Vertex(self.Position.x,y1,z1) a2 = Vertex(self.Position.x,y2,z2) edge = Edge(self.engine, a1, a2).drawEdge(screen) for i in range(0, 360, step): radian = i*math.pi/180 x1 = self.Position.x + self.radius*math.sin(radian) z1 = self.Position.z + self.radius*math.cos(radian) radian = (i+step)*math.pi/180 x2 = self.Position.x + self.radius*math.sin(radian) z2 = self.Position.z + self.radius*math.cos(radian) a1 = Vertex(x1,self.Position.y,z1) a2 = Vertex(x2,self.Position.y,z2) edge = Edge(self.engine, a1, a2).drawEdge(screen)
def updateHitbox(self): try: maxmin = [ self.Position.x, self.Position.y, self.Position.z, self.Position.x, self.Position.y, self.Position.z ] #maxX,maxY,maxZ,minX,minY,minZ for face in self.Faces: for vertex in [face.A, face.B, face.C]: if (vertex.Position.x > maxmin[0]): #nejvetsi X maxmin[0] = vertex.Position.x if (vertex.Position.x < maxmin[3]): #nejmensi X maxmin[3] = vertex.Position.x if (vertex.Position.y > maxmin[1]): #nejvetsi Y maxmin[1] = vertex.Position.y if (vertex.Position.y < maxmin[4]): #nejmensi Y maxmin[4] = vertex.Position.y if (vertex.Position.z > maxmin[2]): #nejvetsi Z maxmin[2] = vertex.Position.z if (vertex.Position.z < maxmin[5]): #nejmensi Z maxmin[5] = vertex.Position.z self.hitBox = maxmin self.hitBoxEdges = [] self.hitBoxEdges.append( Edge(self.engine, Vertex(maxmin[0], maxmin[1], maxmin[2]), Vertex(maxmin[3], maxmin[1], maxmin[2]))) self.hitBoxEdges.append( Edge(self.engine, Vertex(maxmin[0], maxmin[1], maxmin[2]), Vertex(maxmin[0], maxmin[1], maxmin[5]))) self.hitBoxEdges.append( Edge(self.engine, Vertex(maxmin[3], maxmin[1], maxmin[5]), Vertex(maxmin[0], maxmin[1], maxmin[5]))) self.hitBoxEdges.append( Edge(self.engine, Vertex(maxmin[3], maxmin[1], maxmin[2]), Vertex(maxmin[3], maxmin[1], maxmin[5]))) #down self.hitBoxEdges.append( Edge(self.engine, Vertex(maxmin[0], maxmin[4], maxmin[2]), Vertex(maxmin[3], maxmin[4], maxmin[2]))) self.hitBoxEdges.append( Edge(self.engine, Vertex(maxmin[0], maxmin[4], maxmin[2]), Vertex(maxmin[0], maxmin[4], maxmin[5]))) self.hitBoxEdges.append( Edge(self.engine, Vertex(maxmin[3], maxmin[4], maxmin[5]), Vertex(maxmin[0], maxmin[4], maxmin[5]))) self.hitBoxEdges.append( Edge(self.engine, Vertex(maxmin[3], maxmin[4], maxmin[2]), Vertex(maxmin[3], maxmin[4], maxmin[5]))) #between self.hitBoxEdges.append( Edge(self.engine, Vertex(maxmin[0], maxmin[4], maxmin[2]), Vertex(maxmin[0], maxmin[1], maxmin[2]))) self.hitBoxEdges.append( Edge(self.engine, Vertex(maxmin[0], maxmin[4], maxmin[5]), Vertex(maxmin[0], maxmin[1], maxmin[5]))) self.hitBoxEdges.append( Edge(self.engine, Vertex(maxmin[3], maxmin[4], maxmin[2]), Vertex(maxmin[3], maxmin[1], maxmin[2]))) self.hitBoxEdges.append( Edge(self.engine, Vertex(maxmin[3], maxmin[4], maxmin[5]), Vertex(maxmin[3], maxmin[1], maxmin[5]))) return maxmin except: return None
def updateVertices(self, mesh): self.V = [] for i in range(0, len(self.v)): vector = self.v[i].addVectorReturn(mesh.Position) self.V.append(Vertex(vector.x, vector.y, vector.z))
def Draw(self, screen): end = self.Position.addVectorReturn(self.v) edge = Edge(self.engine, Vertex(self.Position.x, self.Position.y, self.Position.z), Vertex(end.x, end.y, end.z))