我希望能够使用OpenGL内部的QuarterWidget,FreeCAD用胶水Coin3D到OpenCascade场景。我可以通过python检索以下对象:
def GetQuarterWidget(self): #From FreeCAD forum
views = []
self.mainWindow=Gui.getMainWindow()
for w in self.mainWindow.findChild(QtGui.QMdiArea).findChildren(QtGui.QWidget):
if w.inherits("SIM::Coin3D::Quarter::QuarterWidget"):
views.append(w)
return views
def getMdiWindow(self) #From FreeCAD forum
mw = Gui.getMainWindow()
mdi = mw.findChild(PySide2.QtWidgets.QMdiArea)但是我不知道如何用OpenGL代码来画场景.打个招呼世界代码(只画一个三角形)?
我的目标是能够链接到场景,这样我就可以直接使用OpenGL,而不是COIN3D,或者使用SDL2库..etc来绘制我所有的新对象。
我很感激任何能做到这一点的暗示。我使用python,但我也接受获得cpp代码。
非常感谢
编辑:我在场景中画了个世界三角。密码有多好?我还不确定。下面是密码。
from OpenGL.GL import *
from OpenGL.GLU import *
import PySide2
import FreeCADGui as Gui
import pivy.coin as coin
import PySide.QtCore as QtCore
import PySide.QtGui as QtGui
from PySide2.QtOpenGL import * #as QtOPENGL
from OpenGL.WGL import *
def drawOpenGl(arg1,arg2):
glTranslatef(-2.5, 0.5, -6.0)
glColor3f( 1.0, 1.5, 0.0 )
glPolygonMode(GL_FRONT, GL_FILL)
glBegin(GL_TRIANGLES)
glVertex3f(2.0,-1.2,0.0)
glVertex3f(2.6,0.0,0.0)
glVertex3f(2.9,-1.2,0.0)
glEnd()
def drawsomething():
w_view = Gui.ActiveDocument.ActiveView
Root_SceneGraph = w_view.getSceneGraph()
calback_=coin.SoCallback()
calback_.setCallback(drawOpenGl)
Root_SceneGraph.addChild(calback_)
drawsomething()请注意,通过运行freecad的python,您需要在FreeCAD中安装pyopengl (而不是pc/linux/mac版本的pip或python)。
FREECAD_DIR/bin/Scripts/pip install pyopengl发布于 2022-12-04 20:45:19
您的代码看起来非常类似于逆变器导师中的样本书。我认为您应该使用glPushMatrix和glPopMatrix存储当前状态。否则,转换的行为可能会不正确。
def drawOpenGl(arg1,arg2):
glPushMatrix()
glTranslatef(-2.5, 0.5, -6.0)
glColor3f( 1.0, 1.5, 0.0 )
glPolygonMode(GL_FRONT, GL_FILL)
glBegin(GL_TRIANGLES)
glVertex3f(2.0,-1.2,0.0)
glVertex3f(2.6,0.0,0.0)
glVertex3f(2.9,-1.2,0.0)
glEnd()
glPopMatrix()不确定这对您是否有任何用处,但是有一个C++示例,它混合了一个纯OpenGL几何(一个矩形)和一个Coin3D几何(一个圆锥体),并使用了四分之一:
#include <QApplication>
#include <Inventor/nodes/SoBaseColor.h>
#include <Inventor/nodes/SoCone.h>
#include <Inventor/nodes/SoSeparator.h>
#include <Inventor/nodes/SoCallback.h>
#include <Quarter/Quarter.h>
#include <Quarter/QuarterWidget.h>
#include <GL/gl.h>
using namespace SIM::Coin3D::Quarter;
// Callback routine to render using OpenGL
void
myCallbackRoutine(void *, SoAction *)
{
glPushMatrix();
glTranslatef(0.0, -3.0, 0.0);
glColor3f(1.0, 0.0, 0.0);
glDisable(GL_LIGHTING); // so we don't have to set normals
glBegin(GL_POLYGON);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(0.5, 0.0, 0.0);
glVertex3f(0.5, 0.5, 0.0);
glVertex3f(0.0, 0.5, 0.0);
glEnd();
glEnable(GL_LIGHTING);
glPopMatrix();
}
int
main(int argc, char ** argv)
{
QApplication app(argc, argv);
// Initializes Quarter library (and implicitly also the Coin and Qt
// libraries).
Quarter::init();
// Make a dead simple scene graph by using the Coin library, only
// containing a single yellow cone under the scenegraph root.
SoSeparator * root = new SoSeparator;
root->ref();
SoBaseColor * col = new SoBaseColor;
col->rgb = SbColor(1, 1, 0);
root->addChild(col);
root->addChild(new SoCone);
SoCallback *myCallback = new SoCallback;
myCallback->setCallback(myCallbackRoutine);
root->addChild(myCallback);
// Create a QuarterWidget for displaying a Coin scene graph
QuarterWidget * viewer = new QuarterWidget;
viewer->setSceneGraph(root);
// make the viewer react to input events similar to the good old
// ExaminerViewer
viewer->setNavigationModeFile(QUrl("coin:///scxml/navigation/examiner.xml"));
// Pop up the QuarterWidget
viewer->show();
// Loop until exit.
app.exec();
// Clean up resources.
root->unref();
delete viewer;
Quarter::clean();
return 0;
}https://stackoverflow.com/questions/74500493
复制相似问题