예제 #1
0
def display_str_at_pos(stri, col, line):
    brepstr = text_to_brep(stri, "Arial", Font_FA_Bold, 12., True)
    # translate the letter to the right
    brepstr_translated = translate_shp(brepstr, gp_Vec(col*8, -line*10, 0))
    brepstr_extruded = make_extrusion(brepstr_translated, 2.5)
    display.DisplayColoredShape(brepstr_extruded, 'WHITE')
    display.Repaint()
예제 #2
0
def display_str_at_pos(stri, col, line):
    brepstr = text_to_brep(stri, "Arial", Font_FA_Bold, 12., True)
    # translate the letter to the right
    brepstr_translated = translate_shp(brepstr, gp_Vec(col*8, -line*10, 0))
    brepstr_extruded = make_extrusion(brepstr_translated, 2.5)
    display.DisplayColoredShape(brepstr_extruded, 'WHITE')
    display.Repaint()
예제 #3
0
from OCC.BRepPrimAPI import BRepPrimAPI_MakeTorus
from OCC.gp import gp_Vec

from core_geometry_utils import translate_shp, rotate_shp_3_axis

my_ren = threejs_renderer.ThreejsRenderer()
n_toruses = 100

idx = 0
for i in range(n_toruses):
    torus_shp = BRepPrimAPI_MakeTorus(10 + random.random() * 10,
                                      random.random() * 10).Shape()
    # random position and orientation and color
    angle_x = random.random() * 360
    angle_y = random.random() * 360
    angle_z = random.random() * 360
    rotated_torus = rotate_shp_3_axis(torus_shp, angle_x, angle_y, angle_z,
                                      'deg')
    tr_x = random.uniform(-70, 50)
    tr_y = random.uniform(-70, 50)
    tr_z = random.uniform(-50, 50)
    trans_torus = translate_shp(rotated_torus, gp_Vec(tr_x, tr_y, tr_z))
    rnd_color = (random.random(), random.random(), random.random())
    my_ren.DisplayShape(trans_torus,
                        export_edges=True,
                        color=rnd_color,
                        transparency=random.random())
    print("%i%%" % (idx * 100 / n_toruses), end="")
    idx += 1
my_ren.render()
예제 #4
0
    "Olá mundo": "Arial",  # Portuguese
    "Здравствулте мир": "Microsoft Yahei",  # Russian
    "Hola mundo": "Arial"  # Spanish
}

arialbold_brep_string = text_to_brep("hello from pythonocc !", "Arial",
                                     Font_FA_Regular, 12., True)

## Then display the string
display.DisplayShape(arialbold_brep_string)
for hello_str in hello:
    rndm_size = random.uniform(10., 16.)
    font = hello[hello_str]
    brep_string = text_to_brep(hello_str, font, Font_FA_Regular, rndm_size,
                               True)
    rndm_extrusion_depth = random.uniform(8., 16.)
    rndm_extrusion_direction = gp_Vec(random.random(), random.random(),
                                      random.random())
    extruded_string = make_extrusion(brep_string, rndm_extrusion_depth,
                                     rndm_extrusion_direction)
    rndm_pos = gp_Vec(random.random() * 100 - 50,
                      random.random() * 100 - 50,
                      random.random() * 100 - 50)
    rndm_color = Quantity_Color(random.random(), random.random(),
                                random.random(), Quantity_TOC_RGB)
    trs_shp = translate_shp(extruded_string, rndm_pos)
    display.DisplayColoredShape(trs_shp, rndm_color)

display.FitAll()
start_display()
from __future__ import print_function

import random

from OCC.Display.WebGl import threejs_renderer
from OCC.BRepPrimAPI import BRepPrimAPI_MakeTorus
from OCC.gp import gp_Vec

from core_geometry_utils import translate_shp, rotate_shp_3_axis

my_ren = threejs_renderer.ThreejsRenderer()
n_toruses = 100

idx = 0
for i in range(n_toruses):
    torus_shp = BRepPrimAPI_MakeTorus(10 + random.random()*10, random.random()*10).Shape()
    # random position and orientation and color
    angle_x = random.random()*360
    angle_y = random.random()*360
    angle_z = random.random()*360
    rotated_torus = rotate_shp_3_axis(torus_shp, angle_x, angle_y, angle_z, 'deg')
    tr_x = random.uniform(-70, 50)
    tr_y = random.uniform(-70, 50)
    tr_z = random.uniform(-50, 50)
    trans_torus = translate_shp(rotated_torus, gp_Vec(tr_x, tr_y, tr_z))
    rnd_color = (random.random(), random.random(), random.random())
    my_ren.DisplayShape(trans_torus, export_edges=True, color=rnd_color, transparency=random.random())
    print("%i%%" % (idx * 100 / n_toruses), end="")
    idx += 1
my_ren.render()
##
##pythonOCC is distributed in the hope that it will be useful,
##but WITHOUT ANY WARRANTY; without even the implied warranty of
##MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##GNU Lesser General Public License for more details.
##
##You should have received a copy of the GNU Lesser General Public License
##along with pythonOCC.  If not, see <http://www.gnu.org/licenses/>.

from OCC.BRepPrimAPI import BRepPrimAPI_MakeBox, BRepPrimAPI_MakeSphere
from OCC.Display.SimpleGui import init_display
from OCC.gp import gp_Vec, gp_Pnt

from core_geometry_utils import translate_shp

display, start_display, add_menu, add_function_to_menu = init_display()

# Create Box
box = BRepPrimAPI_MakeBox(200, 60, 60).Shape()
# Create Sphere
sphere = BRepPrimAPI_MakeSphere(gp_Pnt(100, 20, 20), 80).Shape()
# move the sphere
moved_sphere = translate_shp(sphere, gp_Vec(0., -200., 0.))

ais_box = display.DisplayShape(box)
display.Context.SetTransparency(ais_box, 0.1)
ais_sphere = display.DisplayColoredShape(moved_sphere, color="BLUE")
display.Context.SetTransparency(ais_sphere, 0.9)
display.FitAll()
start_display()
import random

from OCC.Display.WebGl import x3dom_renderer
from OCC.BRepPrimAPI import BRepPrimAPI_MakeBox
from OCC.gp import gp_Vec

from core_geometry_utils import translate_shp, rotate_shp_3_axis

my_ren = x3dom_renderer.X3DomRenderer()

for i in range(100):
    box_shp = BRepPrimAPI_MakeBox(random.random() * 20,
                                  random.random() * 20,
                                  random.random() * 20).Shape()
    # random position and orientation and color
    angle_x = random.random() * 360
    angle_y = random.random() * 360
    angle_z = random.random() * 360
    rotated_box = rotate_shp_3_axis(box_shp, angle_x, angle_y, angle_z, 'deg')
    tr_x = random.uniform(-20, 20)
    tr_y = random.uniform(-20, 20)
    tr_z = random.uniform(-20, 20)
    trans_box = translate_shp(rotated_box, gp_Vec(tr_x, tr_y, tr_z))
    rnd_color = (random.random(), random.random(), random.random())
    my_ren.DisplayShape(trans_box,
                        export_edges=True,
                        color=rnd_color,
                        transparency=random.random())
my_ren.render()
예제 #8
0
         "Hello world": "Arial",  # English
         "Bonjour monde": "Arial",  # French
         "Hallo Welt": "Arial",  # German
         "γειά σου κόσμος": "Calibri",  # Greek
         "Ciao mondo": "Arial",  # Italian
         "こんにちは世界": "Microsoft Yahei",  # Japanese
         "여보세요 세계": "Malgun Gothic",  # Korean
         "Olá mundo": "Arial",  # Portuguese
         "Здравствулте мир": "Microsoft Yahei",  # Russian
         "Hola mundo": "Arial"  # Spanish
        }

arialbold_brep_string = text_to_brep("hello from pythonocc !", "Arial", Font_FA_Regular, 12., True)

## Then display the string
display.DisplayShape(arialbold_brep_string)
for hello_str in hello:
    rndm_size = random.uniform(10., 16.)
    font = hello[hello_str]
    brep_string = text_to_brep(hello_str, font, Font_FA_Regular, rndm_size, True)
    rndm_extrusion_depth = random.uniform(8., 16.)
    rndm_extrusion_direction = gp_Vec(random.random(), random.random(), random.random())
    extruded_string = make_extrusion(brep_string, rndm_extrusion_depth, rndm_extrusion_direction)
    rndm_pos = gp_Vec(random.random()*100-50, random.random()*100-50, random.random()*100-50)
    rndm_color = Quantity_Color(random.random(), random.random(), random.random(), Quantity_TOC_RGB)
    trs_shp = translate_shp(extruded_string, rndm_pos)
    display.DisplayColoredShape(trs_shp, rndm_color)

display.FitAll()
start_display()
import sys

from OCC.Display.SimpleGui import init_display
from OCC.BRepPrimAPI import BRepPrimAPI_MakeBox, BRepPrimAPI_MakeCone
from OCC.Graphic3d import Graphic3d_NOM_PLASTIC, Graphic3d_NOM_ALUMINIUM
from OCC.V3d import V3d_SpotLight, V3d_COMPLETE, V3d_XnegYnegZpos
from OCC.Quantity import Quantity_NOC_WHITE, Quantity_NOC_CORAL2, Quantity_NOC_BROWN
from OCC.BRepAlgoAPI import BRepAlgoAPI_Cut
from OCC.gp import gp_Vec

from core_geometry_utils import translate_shp

# first create geometry
from core_classic_occ_bottle import bottle
table = translate_shp(
    BRepPrimAPI_MakeBox(100, 100, 10).Shape(), gp_Vec(-50, -50, -10))
glass_out = BRepPrimAPI_MakeCone(7, 9, 25).Shape()
glass_in = translate_shp(
    BRepPrimAPI_MakeCone(7, 9, 25).Shape(), gp_Vec(0., 0., 0.2))
glass = BRepAlgoAPI_Cut(glass_out, glass_in).Shape()
translated_glass = translate_shp(glass, gp_Vec(-30, -30, 0))

# then inits display
display, start_display, add_menu, add_function_to_menu = init_display()

# create one spotlight
spot_light = V3d_SpotLight(display.Viewer_handle, -100, -100, 100,
                           V3d_XnegYnegZpos, Quantity_NOC_WHITE)
## display the spotlight in rasterized mode
spot_light.Display(display.View_handle, V3d_COMPLETE)
display.View.SetLightOn()
from __future__ import print_function

import random

from OCC.Display.WebGl import threejs_renderer
from OCC.BRepPrimAPI import BRepPrimAPI_MakeTorus
from OCC.gp import gp_Vec

from core_geometry_utils import translate_shp

my_ren = threejs_renderer.ThreejsRenderer()

idx = 0
torus_shp1 = BRepPrimAPI_MakeTorus(20, 5).Shape()
torus_shp2 = translate_shp(torus_shp1, gp_Vec(60, 0, 0))
torus_shp3 = translate_shp(torus_shp1, gp_Vec(-60, 0, 0))

# default quality
print("Computing RED torus: default quality")
my_ren.DisplayShape(torus_shp1, export_edges=True, color=(1,0,0))  # red

# better mesh quality, i.e. more triangles
print("Computing GREEN torus: better quality, more time to compute")
my_ren.DisplayShape(torus_shp2, export_edges=True, color=(0,1,0),  # green
                    mesh_quality = 0.2) 

# worse quality, i.e. less triangles
print("Computing BLUE torus: worse quality, faster to compute")
my_ren.DisplayShape(torus_shp3, export_edges=True, color=(0,0,1),  # blue
                    mesh_quality= 10.)
예제 #11
0
from __future__ import print_function

import random

from OCC.Display.WebGl import threejs_renderer
from OCC.BRepPrimAPI import BRepPrimAPI_MakeTorus
from OCC.gp import gp_Vec

from core_geometry_utils import translate_shp

my_ren = threejs_renderer.ThreejsRenderer()

idx = 0
torus_shp1 = BRepPrimAPI_MakeTorus(20, 5).Shape()
torus_shp2 = translate_shp(torus_shp1, gp_Vec(60, 0, 0))
torus_shp3 = translate_shp(torus_shp1, gp_Vec(-60, 0, 0))

# default quality
print("Computing RED torus: default quality")
my_ren.DisplayShape(torus_shp1, export_edges=True, color=(1, 0, 0))  # red

# better mesh quality, i.e. more triangles
print("Computing GREEN torus: better quality, more time to compute")
my_ren.DisplayShape(
    torus_shp2,
    export_edges=True,
    color=(0, 1, 0),  # green
    mesh_quality=0.2)

# worse quality, i.e. less triangles