Some cleaning
This commit is contained in:
parent
7e7ad309c7
commit
da582944ea
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from ..conv.model import Vertex
|
||||
from .conv.model import Vertex
|
||||
|
||||
from OpenGL.GL import *
|
||||
from OpenGL.GLU import *
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from ..conv.model import Vertex
|
||||
from .conv.model import Vertex
|
||||
|
||||
import pygame
|
||||
|
|
@ -2,58 +2,9 @@
|
|||
|
||||
from math import sqrt
|
||||
|
||||
class Vertex:
|
||||
def __init__(self, x = 0.0, y = 0.0, z = 0.0):
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.z = z
|
||||
|
||||
def from_array(self, arr):
|
||||
self.x = float(arr[0]) if len(arr) > 0 else None
|
||||
self.y = float(arr[1]) if len(arr) > 1 else None
|
||||
self.z = float(arr[2]) if len(arr) > 2 else None
|
||||
return self
|
||||
|
||||
def __add__(self, other):
|
||||
return Vertex(self.x + other.x, self.y + other.y, self.z + other.z)
|
||||
|
||||
def __mul__(self, other):
|
||||
return Vertex(self.x * other, self.y * other, self.z * other)
|
||||
|
||||
def __rmul__(self, other):
|
||||
return self.__mul__(other)
|
||||
|
||||
def norm2(self):
|
||||
return self.x * self.x + self.y * self.y + self.z * self.z
|
||||
|
||||
def norm(self):
|
||||
return sqrt(self.norm2())
|
||||
|
||||
def normalize(self):
|
||||
norm = self.norm()
|
||||
if abs(norm) > 0.0001:
|
||||
self.x /= norm
|
||||
self.y /= norm
|
||||
self.z /= norm
|
||||
|
||||
def cross_product(v1, v2):
|
||||
return Vertex(
|
||||
v1.y * v2.z - v1.z * v2.y,
|
||||
v1.z * v2.x - v1.x * v2.z,
|
||||
v1.x * v2.y - v1.y * v2.x)
|
||||
|
||||
def from_points(v1, v2):
|
||||
return Vertex(
|
||||
v2.x - v1.x,
|
||||
v2.y - v1.y,
|
||||
v2.z - v1.z)
|
||||
|
||||
def __str__(self):
|
||||
return '(' + ", ".join([str(self.x), str(self.y), str(self.z)]) + ")"
|
||||
|
||||
def dot(self, other):
|
||||
return self.x * other.x + self.y * other.y + self.z * other.z
|
||||
from ..geometry import Vector
|
||||
|
||||
Vertex = Vector
|
||||
Normal = Vertex
|
||||
TexCoord = Vertex
|
||||
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from math import sqrt
|
||||
|
||||
class Vector:
|
||||
def __init__(self, x = 0.0, y = 0.0, z = 0.0):
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.z = z
|
||||
|
||||
def from_array(self, arr):
|
||||
self.x = float(arr[0]) if len(arr) > 0 else None
|
||||
self.y = float(arr[1]) if len(arr) > 1 else None
|
||||
self.z = float(arr[2]) if len(arr) > 2 else None
|
||||
return self
|
||||
|
||||
def __add__(self, other):
|
||||
return Vector(self.x + other.x, self.y + other.y, self.z + other.z)
|
||||
|
||||
def __mul__(self, other):
|
||||
return Vector(self.x * other, self.y * other, self.z * other)
|
||||
|
||||
def __rmul__(self, other):
|
||||
return self.__mul__(other)
|
||||
|
||||
def norm2(self):
|
||||
return self.x * self.x + self.y * self.y + self.z * self.z
|
||||
|
||||
def norm(self):
|
||||
return sqrt(self.norm2())
|
||||
|
||||
def normalize(self):
|
||||
norm = self.norm()
|
||||
if abs(norm) > 0.0001:
|
||||
self.x /= norm
|
||||
self.y /= norm
|
||||
self.z /= norm
|
||||
|
||||
def cross_product(v1, v2):
|
||||
return Vector(
|
||||
v1.y * v2.z - v1.z * v2.y,
|
||||
v1.z * v2.x - v1.x * v2.z,
|
||||
v1.x * v2.y - v1.y * v2.x)
|
||||
|
||||
def from_points(v1, v2):
|
||||
return Vector(
|
||||
v2.x - v1.x,
|
||||
v2.y - v1.y,
|
||||
v2.z - v1.z)
|
||||
|
||||
def __str__(self):
|
||||
return '(' + ", ".join([str(self.x), str(self.y), str(self.z)]) + ")"
|
||||
|
||||
def dot(self, other):
|
||||
return self.x * other.x + self.y * other.y + self.z * other.z
|
||||
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
v 0.5 -0.5 -0.5
|
||||
v 0.5 0.5 -0.5
|
||||
v -0.5 0.5 -0.5
|
||||
v -0.5 -0.5 -0.5
|
||||
v 0.5 -0.5 0.5
|
||||
v 0.5 0.5 0.5
|
||||
v -0.5 0.5 0.5
|
||||
v -0.5 -0.5 0.5
|
||||
|
||||
f 1 2 5
|
||||
f 2 6 5
|
||||
f 2 3 6
|
||||
f 3 7 6
|
||||
f 2 1 4
|
||||
f 2 4 3
|
||||
f 5 6 8
|
||||
f 6 7 8
|
||||
f 3 4 8
|
||||
f 3 8 7
|
||||
f 4 1 5
|
||||
f 4 5 8
|
15645
models/link.obj
15645
models/link.obj
File diff suppressed because it is too large
Load Diff
|
@ -1,14 +0,0 @@
|
|||
varying vec3 fNormal;
|
||||
|
||||
vec3 ambientLight = vec3(0.2,0.2,0.2);
|
||||
vec3 directionnalLight = normalize(vec3(10,5,7));
|
||||
vec3 directionnalLightFactor = vec3(0.5,0.5,0.5);
|
||||
|
||||
|
||||
void main() {
|
||||
|
||||
vec3 ambientFactor = ambientLight;
|
||||
vec3 lambertFactor = max(vec3(0.0,0.0,0.0), dot(directionnalLight, fNormal) * directionnalLightFactor);
|
||||
|
||||
gl_FragColor = vec4(ambientFactor + lambertFactor, 1.0);
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
varying vec3 fNormal;
|
||||
|
||||
void main() {
|
||||
fNormal = gl_Normal;
|
||||
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
|
||||
}
|
|
@ -14,8 +14,8 @@ from OpenGL.GLU import *
|
|||
|
||||
from d3.conv.loadmodel import load_model
|
||||
from d3.conv.model import Vertex
|
||||
from d3.controls.controls import TrackBallControls
|
||||
from d3.cameras.camera import Camera
|
||||
from d3.controls import TrackBallControls
|
||||
from d3.camera import Camera
|
||||
|
||||
WINDOW_WIDTH = 1024
|
||||
WINDOW_HEIGHT = 768
|
||||
|
@ -53,9 +53,9 @@ def main(args):
|
|||
|
||||
VERTEX_SHADER = None
|
||||
FRAGMENT_SHADER = None
|
||||
with open('shaders/shader.vert') as f:
|
||||
with open('assets/shaders/shader.vert') as f:
|
||||
VERTEX_SHADER = compileShader(f.read(), GL_VERTEX_SHADER)
|
||||
with open('shaders/shader.frag') as f:
|
||||
with open('assets/shaders/shader.frag') as f:
|
||||
FRAGMENT_SHADER = compileShader(f.read(), GL_FRAGMENT_SHADER)
|
||||
|
||||
SHADER = compileProgram(VERTEX_SHADER, FRAGMENT_SHADER)
|
||||
|
|
Loading…
Reference in New Issue