Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example 6.3: no beveled text [includes proposed fix] #11

Closed
InventorMentor opened this issue Apr 11, 2017 · 1 comment
Closed

Example 6.3: no beveled text [includes proposed fix] #11

InventorMentor opened this issue Apr 11, 2017 · 1 comment
Milestone

Comments

@InventorMentor
Copy link

Example 6.3 includes several mistakes, however, I'm not sure whether the setValue() calls, e.g. as in

color[0].setValue(1, 1, 1)

and in

coords[0].setValue(0.25, 0.25)

should work Pivy-wise (as in the original C++ and the current Python example). In the current example they insert unexpected values into the scenegraph and the datatype of the elements in the colors list is changed from SbColor to SbVec3f. Anyhow, (otherwise?), I've included a working alternative for this example below. Best wishes, Peter

"""
This is an example from the Inventor Mentor,
chapter 6, example 3.

This example renders arguments as text within an
ExaminerViewer.  It is a little fancier than 6.2.
"""

import sys

from PySide.QtGui import *
from pivy.coin import *
from pivy.quarter import *

def main():
    # Initialize Inventor and Qt
    app = QApplication(sys.argv)
    viewer = QuarterWidget()

    root = SoGroup()

    # Set up camera
    myCamera = SoPerspectiveCamera()
    myCamera.position = (0, -(len(sys.argv) - 1) / 2, 10)
    myCamera.nearDistance = 5.0
    myCamera.farDistance = 15.0
    root += myCamera

    # Let's make the front of the text white,
    # and the sides and back shiny yellow
    myMaterial = SoMaterial()
    # diffuse
    colors = [SbColor()] * 3
    colors[0] = SbColor(1, 1, 1)
    colors[1] = SbColor(1, 1, 0)
    colors[2] = SbColor(1, 1, 0)
    myMaterial.diffuseColor.setValues(0, 3, colors)

    # specular
    colors[0].setValue(1, 1, 1)
    """
    # Note: Inventor 2.1 doesn't support multiple specular colors.
    # colors[1].setValue(1, 1, 0)
    # colors[2].setValue(1, 1, 0)
    # myMaterial.specularColor.setValues(0, 3, colors)
    """
    myMaterial.specularColor.setValue(colors[0])
    myMaterial.shininess.setValue(.1)
    root += myMaterial

    # Choose a font likely to exist.
    myFont = SoFont()
    myFont.name = "Times" # "Times-Roman"
    root += myFont

    # Specify a beveled cross-section for the text
    myProfileCoords = SoProfileCoordinate2()
    coords = [SbVec2f()] * 4
    coords[0] = SbVec2f(.00, .00)
    coords[1] = SbVec2f(.25, .25)
    coords[2] = SbVec2f(1.25, .25)
    coords[3] = SbVec2f(1.50, .00)
    myProfileCoords.point.setValues(0, 4, coords)
    root += myProfileCoords

    myLinearProfile = SoLinearProfile()
    index = (0, 1, 2, 3)
    myLinearProfile.index.setValues(0, 4, index)
    root += myLinearProfile

    # Set the material binding to PER_PART
    myMaterialBinding = SoMaterialBinding()
    myMaterialBinding.value = SoMaterialBinding.PER_PART
    root += myMaterialBinding

    # Add the text
    myText3 = SoText3()
    myText3.string = "Beveled Text"
    myText3.justification = SoText3.CENTER
    myText3.parts = SoText3.ALL

    root += myText3
	
    viewer.setSceneGraph(root)
    viewer.setWindowTitle("Complex 3D Text")
    viewer.show()
    viewer.viewAll()

    sys.exit(app.exec_())

if __name__ == "__main__":
    main()

@looooo
Copy link
Collaborator

looooo commented Apr 11, 2017

@looooo looooo added this to the 0.6.2 milestone Apr 19, 2017
@looooo looooo modified the milestones: 0.6.2, 0.7 May 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants