-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path17.2.GLCallback.py
169 lines (134 loc) · 5.21 KB
/
17.2.GLCallback.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/usr/bin/env python
###
# Copyright (c) 2002-2007 Systems in Motion
#
# Permission to use, copy, modify, and distribute this coin.software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE coin.SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS coin.SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATcoin.SOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS coin.SOFTWARE.
#
###
# This is an example from The Inventor Mentor,
# chapter 17, example 2.
#
# Example of combining Inventor and OpenGL rendering.
# Create an Inventor render area and draw a red cube
# and a blue sphere. Render the floor with OpenGL
# through a Callback node.
#
####################################################################
# Modified to be compatible with FreeCAD #
# #
# Author : Mariwan Jalal mariwan.jalal@gmail.com #
####################################################################
#Warning: This doesn't work on freecad .. no OpenGl support
# import os
# import sys
# import FreeCAD as App
# import FreeCADGui as Gui
# import pivy.coin as coin
# from PySide import QtGui, QtCore # https://www.freecadweb.org/wiki/PySide
# from OpenGL.GL import *
# floorObj = []
# # Build a scene with two objects and some light
# def buildScene(root):
# # coin.Some light
# root.addChild(coin.SoLightModel())
# root.addChild(coin.SoDirectionalLight())
# # A red cube translated to the left and down
# myTrans = coin.SoTransform()
# myTrans.translation = (-2.0, -2.0, 0.0)
# root.addChild(myTrans)
# myMtl = coin.SoMaterial()
# myMtl.diffuseColor = (1.0, 0.0, 0.0)
# root.addChild(myMtl)
# root.addChild(coin.SoCube())
# # A blue sphere translated right
# myTrans = coin.SoTransform()
# myTrans.translation = (4.0, 0.0, 0.0)
# root.addChild(myTrans)
# myMtl = coin.SoMaterial()
# myMtl.diffuseColor = (0.0, 0.0, 1.0)
# root.addChild(myMtl)
# root.addChild(coin.SoSphere())
# # Build the floor that will be rendered using OpenGL.
# def buildFloor():
# global floorObj
# a = 0
# for i in range(9):
# for j in range(9):
# floorObj.append([-5.0 + j*1.25, 0.0, -5.0 + i*1.25])
# a += 1
# # Draw the lines that make up the floor, using OpenGL
# def drawFloor():
# global floorObj
# glBegin(GL_LINES)
# for i in range(4):
# glVertex3fv(floorObj[i*18])
# glVertex3fv(floorObj[(i*18)+8])
# glVertex3fv(floorObj[(i*18)+17])
# glVertex3fv(floorObj[(i*18)+9])
# i += 1
# glVertex3fv(floorObj[i*18])
# glVertex3fv(floorObj[(i*18)+8])
# glEnd()
# glBegin(GL_LINES)
# for i in range(4):
# glVertex3fv(floorObj[i*2])
# glVertex3fv(floorObj[(i*2)+72])
# glVertex3fv(floorObj[(i*2)+73])
# glVertex3fv(floorObj[(i*2)+1])
# i += 1
# glVertex3fv(floorObj[i*2])
# glVertex3fv(floorObj[(i*2)+72])
# glEnd()
# # Callback routine to render the floor using OpenGL
# def myCallbackRoutine(void, action):
# # only render the floor during GLRender actions:
# if not action.icoin.sOfType(coin.SoGLRenderAction.getClassTypeId()):
# return
# glPushMatrix()
# glTranslatef(0.0, -3.0, 0.0)
# glColor3f(0.0, 0.7, 0.0)
# glLineWidth(2)
# glDisable(GL_LIGHTING) # coin.so we don't have to set normals
# drawFloor()
# glEnable(GL_LIGHTING)
# glLineWidth(1)
# glPopMatrix()
# # With Inventor 2.1, it's necessary to reset coin.SoGLLazyElement after
# # making calls (such as glColor3f()) that affect material state.
# # In this case, the diffuse color and light model are being modified,
# # coin.so the logical-or of DIFFUSE_MASK and LIGHT_MODEL_MASK is passed
# # to coin.SoGLLazyElement::reset().
# # Additional information can be found in the publication
# # "Open Inventor 2.1 Porting and Performance Tips"
# # state = action.getState()
# # lazyElt = coin.SoLazyElement.getInstance(state)
# # lazyElt.reset(state, (coin.SoLazyElement.DIFFUSE_MASK)|(coin.SoLazyElement.LIGHT_MODEL_MASK))
# def main():
# buildFloor()
# # Build a simple scene graph, including a camera and
# # a coin.SoCallback node for performing coin.some GL rendering.
# root = coin.SoSeparator()
# myCamera = coin.SoPerspectiveCamera()
# myCamera.position = (0.0, 0.0, 5.0)
# myCamera.heightAngle = 22/7/2.0 # 90 degrees
# myCamera.nearDistance = 2.0
# myCamera.farDistance = 12.0
# root.addChild(myCamera)
# myCallback = coin.SoCallback()
# myCallback.setCallback(myCallbackRoutine)
# root.addChild(myCallback)
# buildScene(root)
# drawFloor()
# view = Gui.ActiveDocument.ActiveView
# sg = view.getSceneGraph()
# sg.addChild(root)