Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
Printrun
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
machinery
Printrun
Commits
f6876d40
Commit
f6876d40
authored
Apr 05, 2014
by
Guillaume Seguin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add mouse_to_plane util and use it to draw cursor indicator in stlplater
parent
140d9996
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
18 deletions
+46
-18
panel.py
printrun/gl/panel.py
+18
-0
stlview.py
printrun/stlview.py
+28
-18
No files found.
printrun/gl/panel.py
View file @
f6876d40
...
...
@@ -19,6 +19,8 @@ from threading import Lock
import
logging
import
sys
import
traceback
import
numpy
import
numpy.linalg
import
wx
from
wx
import
glcanvas
...
...
@@ -290,6 +292,22 @@ class wxGLPanel(wx.Panel):
ray_near
=
(
px
.
value
,
py
.
value
,
pz
.
value
)
return
ray_near
,
ray_far
def
mouse_to_plane
(
self
,
x
,
y
,
plane_normal
,
plane_offset
,
local_transform
=
False
):
# Ray/plane intersection
ray_near
,
ray_far
=
self
.
mouse_to_ray
(
x
,
y
,
local_transform
)
ray_near
=
numpy
.
array
(
ray_near
)
ray_far
=
numpy
.
array
(
ray_far
)
ray_dir
=
ray_far
-
ray_near
ray_dir
=
ray_dir
/
numpy
.
linalg
.
norm
(
ray_dir
)
plane_normal
=
numpy
.
array
(
plane_normal
)
q
=
ray_dir
.
dot
(
plane_normal
)
if
q
==
0
:
return
None
t
=
-
(
ray_near
.
dot
(
plane_normal
)
+
plane_offset
)
/
q
if
t
<
0
:
return
None
return
ray_near
+
t
*
ray_dir
def
zoom
(
self
,
factor
,
to
=
None
):
glMatrixMode
(
GL_MODELVIEW
)
if
to
:
...
...
printrun/stlview.py
View file @
f6876d40
...
...
@@ -18,6 +18,7 @@
import
wx
import
time
import
numpy
import
pyglet
pyglet
.
options
[
'debug_gl'
]
=
True
...
...
@@ -28,7 +29,9 @@ from pyglet.gl import GL_AMBIENT_AND_DIFFUSE, glBegin, glClearColor, \
glMultMatrixd
,
glNormal3f
,
glPolygonMode
,
glPopMatrix
,
GL_POSITION
,
\
glPushMatrix
,
glRotatef
,
glScalef
,
glShadeModel
,
GL_SHININESS
,
\
GL_SMOOTH
,
GL_SPECULAR
,
glTranslatef
,
GL_TRIANGLES
,
glVertex3f
,
\
glGetDoublev
,
GL_MODELVIEW_MATRIX
,
GLdouble
glGetDoublev
,
GL_MODELVIEW_MATRIX
,
GLdouble
,
glClearDepth
,
glDepthFunc
,
\
GL_LEQUAL
,
GL_BLEND
,
glBlendFunc
,
GL_SRC_ALPHA
,
GL_ONE_MINUS_SRC_ALPHA
,
\
GL_LINE_LOOP
,
glGetFloatv
,
GL_LINE_WIDTH
,
glLineWidth
,
glDisable
,
GL_LINE_SMOOTH
from
pyglet
import
gl
from
.gl.panel
import
wxGLPanel
...
...
@@ -110,7 +113,11 @@ class StlViewPanel(wxGLPanel):
glClearColor
(
0
,
0
,
0
,
1
)
glColor3f
(
1
,
0
,
0
)
glEnable
(
GL_DEPTH_TEST
)
glClearDepth
(
1.0
)
glDepthFunc
(
GL_LEQUAL
)
glEnable
(
GL_CULL_FACE
)
glEnable
(
GL_BLEND
)
glBlendFunc
(
GL_SRC_ALPHA
,
GL_ONE_MINUS_SRC_ALPHA
)
# Uncomment this line for a wireframe view
# glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
...
...
@@ -278,11 +285,14 @@ class StlViewPanel(wxGLPanel):
# Draw platform
glPolygonMode
(
GL_FRONT_AND_BACK
,
GL_LINE
)
self
.
platform
.
draw
()
glPolygonMode
(
GL_FRONT_AND_BACK
,
GL_FILL
)
# Draw mouse
glPolygonMode
(
GL_FRONT_AND_BACK
,
GL_FILL
)
inter
=
self
.
mouse_to_plane
(
self
.
mousepos
[
0
],
self
.
mousepos
[
1
],
plane_normal
=
(
0
,
0
,
1
),
plane_offset
=
0
,
local_transform
=
False
)
if
inter
is
not
None
:
glPushMatrix
()
x
,
y
,
z
=
self
.
mouse_to_3d
(
self
.
mousepos
[
0
],
self
.
mousepos
[
1
],
0.9
)
glTranslatef
(
x
,
y
,
z
)
glTranslatef
(
inter
[
0
],
inter
[
1
],
inter
[
2
])
glBegin
(
GL_TRIANGLES
)
glMaterialfv
(
GL_FRONT_AND_BACK
,
GL_AMBIENT_AND_DIFFUSE
,
vec
(
1
,
0
,
0
,
1
))
glNormal3f
(
0
,
0
,
1
)
...
...
@@ -293,11 +303,11 @@ class StlViewPanel(wxGLPanel):
glVertex3f
(
2
,
2
,
0
)
glVertex3f
(
-
2
,
-
2
,
0
)
glEnd
()
glMaterialfv
(
GL_FRONT_AND_BACK
,
GL_AMBIENT_AND_DIFFUSE
,
vec
(
0.3
,
0.7
,
0.5
,
1
))
glPopMatrix
()
glPushMatrix
()
# Draw objects
glPushMatrix
()
glMaterialfv
(
GL_FRONT_AND_BACK
,
GL_AMBIENT_AND_DIFFUSE
,
vec
(
0.3
,
0.7
,
0.5
,
1
))
for
i
in
self
.
parent
.
models
:
model
=
self
.
parent
.
models
[
i
]
glPushMatrix
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment