pivy.coin (COIN3D) 箭头绘制不旋转FreeCAD - Python

如何解决pivy.coin (COIN3D) 箭头绘制不旋转FreeCAD - Python

在我看来,下面的代码是正确的。但不幸的是我无法旋转箭头。无论我赋予该功能什么角度,它都不起作用。 我不知道这段代码有什么问题。

注意: 这是我为 FreeCAD 构建的 COIN3D Widget 系统的一部分。你可以在我的 github 上找到整个项目 = https://github.com/MariwanJ/Design456/tree/devbranch

#draw an arrow 
def draw_arrow(_Points=[],_color=(0,1,0),_ArrSize=1.0,_rotation=(1.0,1.0,0.0) ):
    print("point,arrsize,rota",_Points,_ArrSize,_rotation)
    if len (_Points)!=2:
        raise ValueError('must be 2 points')
    try:
        so_separatorRoot=coin.soSeparator()
        so_separatorHead = coin.soSeparator()
        so_separatorTail = coin.soSeparator()
        
        transHead = coin.soTranslation()   # decide at which position the object will be placed
        transTail = coin.soTranslation()   # decide at which position the object will be placed
        transRoot= coin.soTranslation()    # decide at which position the whole objects will be placed
        
        coordsRoot = coin.soTransform()
        
        cone=coin.soCone()
        cone.bottomradius= 3
        cone.height= 3
        
        cylinder=coin.soCylinder()
        cylinder.height = 10
        cylinder.radius = 0.5
        p1=_Points[0]
        p2=App.Vector(p1.x,p1.y-5,p1.z)

        styleHead = coin.soDrawStyle()
        styleTail = coin.soDrawStyle()
        
        styleHead.style = coin.soDrawStyle.LInes     #draw only frame not filled
        styleHead.linewidth = 3

        styleTail.style = coin.soDrawStyle.LInes     #draw only frame not filled
        styleTail.linewidth = 2
        
        coordsRoot.scaleFactor.setValue([_ArrSize,_ArrSize])
        coordsRoot.translation.setValue(App.Vector(0,0))
        coordsRoot.rotation.Q=_rotation #  Sbrotation (const SbVec3f &axis,const float radians)

        transHead.translation.setValue(p1)
        transTail.translation.setValue(p2)
        transRoot.translation.setValue(App.Vector(0.0,0.0,0.0))
        
        color=coin.soBaseColor(); 
        color.rgb=_color
        
        so_separatorHead.addChild(color)
        so_separatorTail.addChild(color)
        
        so_separatorHead.addChild(transHead)
        so_separatorTail.addChild(transTail)

        so_separatorHead.addChild(styleHead)
        so_separatorHead.addChild(cone)
        
        so_separatorTail.addChild(styleTail)
        so_separatorTail.addChild(cylinder)
        
        so_separatorRoot.addChild(transRoot)
        so_separatorRoot.addChild(color)
        so_separatorRoot.addChild(coordsRoot)
        so_separatorRoot.addChild(so_separatorHead)
        so_separatorRoot.addChild(so_separatorTail)
        
        return so_separatorRoot

    except Exception as err:
        App.Console.PrintError("'Design456_DirectScale' Failed. "
                               "{err}\n".format(err=str(err)))
        exc_type,exc_obj,exc_tb = sys.exc_info()
        fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
        print(exc_type,fname,exc_tb.tb_lineno)

解决方法

我找到了解决方案。其实我在问题中已经有了答案。 看看这行: coordsRoot.rotation.Q=_rotation # SbRotation (const SbVec3f &axis,const float radians)

那里提到你必须给出四个浮点值..我的错。但是 Python 的问题是 .. 它不会产生任何错误。这使我的故障排除太困难了。 没有 (.Q) 作为 (SbRotation) 的子对象。 我写下正确的代码,以防其他人想使用它。

def draw_arrow(_Points=[],_color=FR_COLOR.FR_OLIVE,_ArrSize=1.0,_rotation=(1.0,1.0,0.0)):
    '''
    Draw a 3D arrow at the position given by the _Points and the color given by _color. 
    Scale it by the _ArrSize,and rotate it by the _rotation which consist of four float values(x,y,z,and Angel),angle in radians. 
    '''
    if len (_Points)!=2:
        raise ValueError('Vertices must be 2')
    try:
        so_separatorRoot=coin.SoSeparator()
        so_separatorHead = coin.SoSeparator()
        so_separatorTail = coin.SoSeparator()
        
        transHead = coin.SoTranslation()   # decide at which position the object will be placed
        transTail = coin.SoTranslation()   # decide at which position the object will be placed
        transRoot= coin.SoTranslation()    # decide at which position the whole objects will be placed
        
        coordsRoot = coin.SoTransform()
        
        cone=coin.SoCone()
        cone.bottomRadius= 3
        cone.height= 3
        
        cylinder=coin.SoCylinder()
        cylinder.height = 10
        cylinder.radius = 0.5
        p1=_Points[0]
        p2=App.Vector(p1.x,p1.y-5,p1.z)

        styleHead = coin.SoDrawStyle()
        styleTail = coin.SoDrawStyle()
        
        styleHead.style = coin.SoDrawStyle.LINES     #draw only frame not filled
        styleHead.lineWidth = 3

        styleTail.style = coin.SoDrawStyle.LINES     #draw only frame not filled
        styleTail.lineWidth = 2
        
        coordsRoot.scaleFactor.setValue([_ArrSize,_ArrSize,_ArrSize])
        coordsRoot.translation.setValue(App.Vector(0,0))
        coordsRoot.rotation.setValue(_rotation) #  SbRotation (const SbVec3f &axis,const float radians)
        

        transHead.translation.setValue(p1)
        transTail.translation.setValue(p2)
        transRoot.translation.setValue(App.Vector(0.0,0.0,0.0))
        
        color=coin.SoBaseColor(); 
        color.rgb=_color
        
        so_separatorHead.addChild(color)
        so_separatorTail.addChild(color)
        
        so_separatorHead.addChild(transHead)
        so_separatorTail.addChild(transTail)

        so_separatorHead.addChild(styleHead)
        so_separatorHead.addChild(cone)
        
        so_separatorTail.addChild(styleTail)
        so_separatorTail.addChild(cylinder)

        print("rotatin",_rotation)
        so_separatorRoot.addChild(coordsRoot)       
        so_separatorRoot.addChild(transRoot)
        so_separatorRoot.addChild(so_separatorHead)
        so_separatorRoot.addChild(so_separatorTail)

        
        return so_separatorRoot
        # we have a selected object. Try to show the dimensions. 
        
    except Exception as err:
        App.Console.PrintError("'Design456_DirectScale' Failed. "
                               "{err}\n".format(err=str(err)))
        exc_type,exc_obj,exc_tb = sys.exc_info()
        fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
        print(exc_type,fname,exc_tb.tb_lineno)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?