diff --git a/README.md b/README.md index c5a8a7f..2c3c378 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ dependencies, you'll need : - pip (to install the other dependencies) `sudo apt-get install python3-pip` for example + - PIL `sudo pip install pillow` - numpy `sudo pip install numpy` - pygame `sudo pip install pygame` - PyOpenGL `sudo pip install pyopengl` diff --git a/d3/model/formats/obj.py b/d3/model/formats/obj.py index b64dfd6..f131bd5 100644 --- a/d3/model/formats/obj.py +++ b/d3/model/formats/obj.py @@ -2,7 +2,6 @@ from ..basemodel import ModelParser, Exporter, Vertex, TexCoord, Normal, FaceVer from ..mesh import Material, MeshPart from functools import reduce import os.path -import PIL.Image import sys @@ -89,7 +88,11 @@ class MTLParser: elif first == 'Ks': self.current_mtl.Ks = Vertex().from_array(split) elif first == 'map_Kd': - self.current_mtl.map_Kd = PIL.Image.open(os.path.join(os.path.dirname(self.parent.path), split[0])) + try: + import PIL.Image + self.current_mtl.map_Kd = PIL.Image.open(os.path.join(os.path.dirname(self.parent.path), split[0])) + except: + pass def parse_file(self, path): diff --git a/d3/model/mesh.py b/d3/model/mesh.py index e91118d..c9c32cc 100644 --- a/d3/model/mesh.py +++ b/d3/model/mesh.py @@ -50,13 +50,16 @@ class Material: gl.glDisable(gl.GL_TEXTURE_2D) -import PIL.Image - Material.DEFAULT_MATERIAL=Material('') Material.DEFAULT_MATERIAL.Ka = 1.0 Material.DEFAULT_MATERIAL.Kd = 0.0 Material.DEFAULT_MATERIAL.Ks = 0.0 -Material.DEFAULT_MATERIAL.map_Kd = PIL.Image.new("RGBA", (1,1), "white") + +try: + import PIL.Image + Material.DEFAULT_MATERIAL.map_Kd = PIL.Image.new("RGBA", (1,1), "white") +except: + pass class MeshPart: def __init__(self, parent): diff --git a/viewer.py b/viewer.py index e2c94f2..84832c6 100755 --- a/viewer.py +++ b/viewer.py @@ -6,13 +6,13 @@ import argparse import os import math -from d3.model.tools import load_model -from d3.geometry import Vector -from d3.controls import TrackBallControls, OrbitControls -from d3.camera import Camera -from d3.shader import DefaultShader - # Test dependencies +try: + import PIL +except: + print('You need to install PIL', file=sys.stderr) + sys.exit(-1) + try: import pygame as pg import pygame.locals as pgl @@ -33,6 +33,12 @@ except: print('You need to install numpy', file=sys.stderr) sys.exit(-1) +from d3.model.tools import load_model +from d3.geometry import Vector +from d3.controls import TrackBallControls, OrbitControls +from d3.camera import Camera +from d3.shader import DefaultShader + WINDOW_WIDTH = 1024 WINDOW_HEIGHT = 1024