Ejemplo n.º 1
0
 def test_three_jsshaders(self):
     '''Test: point from curve'''
     torus_shp = BRepPrimAPI_MakeBox(20., 10., 30.).Shape()
     vertex_shader = """
         attribute vec3 center;
         varying vec3 vCenter;
         void main() {
             vCenter = center;
             gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
         }
     """
     fragment_shader = """
         #extension GL_OES_standard_derivatives : enable
         varying vec3 vCenter;
         float edgeFactorTri() {
             vec3 d = fwidth( vCenter.xyz );
             vec3 a3 = smoothstep( vec3( 0.0 ), d * 1.5, vCenter.xyz );
             return min( min( a3.x, a3.y ), a3.z );
         }
         void main() {
             gl_FragColor.rgb = mix( vec3( 1.0 ), vec3( 0.2 ), edgeFactorTri() );
             gl_FragColor.a = 1.0;
         }
         """
     my_renderer = threejs_renderer.ThreejsRenderer("#123345",
                                                    vertex_shader,
                                                    fragment_shader,
                                                    path="./test_io")
     js_file, html_file = my_renderer.create_files(torus_shp)
     assert os.path.isfile(js_file)
     assert os.path.isfile(html_file)
Ejemplo n.º 2
0
 def test_threejs_render_torus(self):
     """ Render a simple torus in threejs
     """
     my_threejs_renderer = threejs_renderer.ThreejsRenderer()
     dict_shape, dict_edge = my_threejs_renderer.DisplayShape(torus_shp)
     self.assertTrue(dict_shape)
     self.assertTrue(not dict_edge)
Ejemplo n.º 3
0
 def test_threejs_render_torus(self):
     '''Test: point from curve'''
     torus_shp = BRepPrimAPI_MakeTorus(20., 10.).Shape()
     my_renderer = threejs_renderer.ThreejsRenderer(background_color="#123345")
     my_renderer.DisplayShape(torus_shp)
     assert os.path.isfile('./shape.js')
     assert os.path.isfile('./webgl_topods_shape.html')
Ejemplo n.º 4
0
 def test_threejs_render_torus(self):
     '''Test: point from curve'''
     torus_shp = BRepPrimAPI_MakeTorus(20., 10.).Shape()
     my_renderer = threejs_renderer.ThreejsRenderer(
         background_color="#123345")
     js_file, html_file = my_renderer.create_files(torus_shp)
     assert os.path.isfile(js_file)
     assert os.path.isfile(html_file)
 def test_x3dom_random_mesh_quality(self):
     """ Test: threejs 10 random boxes
     """
     my_threejs_renderer = threejs_renderer.ThreejsRenderer()
     torus_shp = BRepPrimAPI_MakeTorus(20., 10.).Shape()
     my_threejs_renderer.DisplayShape(torus_shp, mesh_quality=1.0)
     my_threejs_renderer.DisplayShape(torus_shp, mesh_quality=0.8)
     my_threejs_renderer.DisplayShape(torus_shp, mesh_quality=2.0)
Ejemplo n.º 6
0
 def test_threejs_wire(self):
     """Test: threejs 10 random boxes"""
     my_threejs_renderer = threejs_renderer.ThreejsRenderer()
     for wire in TopologyExplorer(torus_shp).wires():
         dict_shape, dict_edge = my_threejs_renderer.DisplayShape(
             wire, mesh_quality=1.0)
         self.assertTrue(not dict_shape)
         self.assertTrue(dict_edge)
Ejemplo n.º 7
0
 def test_threejs_random_boxes(self):
     """ Test: threejs 10 random boxes
     """
     my_threejs_renderer = threejs_renderer.ThreejsRenderer()
     for i in range(10):
         box_shp = BRepPrimAPI_MakeBox(random.random()*20, random.random()*20, random.random()*20).Shape()
         rnd_color = (random.random(), random.random(), random.random())
         rnd_export_edges = bool(random.random() > 0.5)
         my_threejs_renderer.DisplayShape(box_shp, export_edges=True, color=rnd_color, transparency=random.random())
Ejemplo n.º 8
0
 def test_x3dom_random_mesh_quality(self):
     """Test: threejs 10 random boxes"""
     my_threejs_renderer = threejs_renderer.ThreejsRenderer()
     # torus_shp = BRepPrimAPI_MakeTorus(20., 10.).Shape()
     dict_shape, dict_edge = my_threejs_renderer.DisplayShape(
         torus_shp, mesh_quality=1.0)
     self.assertTrue(dict_shape)
     self.assertTrue(not dict_edge)
     dict_shape, dict_edge = my_threejs_renderer.DisplayShape(
         torus_shp, mesh_quality=0.8)
     self.assertTrue(dict_shape)
     self.assertTrue(not dict_edge)
     dict_shape, dict_edge = my_threejs_renderer.DisplayShape(
         torus_shp, mesh_quality=2.0)
     self.assertTrue(dict_shape)
     self.assertTrue(not dict_edge)
Ejemplo n.º 9
0
    def view(self, node_index=-1, jupyter=False):
        """ view assembly

        Parameters
        ----------

        node_index : a list of Assembly nodes (-1 : all nodes)

        Notes
        -----

        An Assembly is a graph
        Each node of an assembly has attached
            + a filename describing a solid in its own local frame
            + a translation vector for solid placement in the global frame

        This function produces the view of the assembly in the global frame.

        """
        # if type(node_index) == int:
        if isinstance(node_index, int):
            if node_index == -1:
                node_index = self.node.keys()
            else:
                node_index = [node_index]

        # assert(max(node_index) <= max(self.node.keys())), "Wrong node index"
        if max(node_index) > max(self.node.keys()):
            raise AssertionError("Wrong node index")

        if self.serialized:
            s.unserialize()

        solid = self.get_solid_from_nodes(node_index)

        # solid.to_html('assembly.html')
        if jupyter:
            j = jupyter_renderer.JupyterRenderer()
            j.DisplayShape(solid.shape, update=True)
            return solid, j
        else:
            my_renderer = threejs_renderer.ThreejsRenderer()
            my_renderer.DisplayShape(solid.shape)
            my_renderer.render()

            return solid
Ejemplo n.º 10
0
##the Free Software Foundation, either version 3 of the License, or
##(at your option) any later version.
##
##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 math import pi

from OCC.Core.gp import gp_Pnt2d, gp_XOY, gp_Lin2d, gp_Ax3, gp_Dir2d
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeEdge
from OCC.Core.Geom import Geom_CylindricalSurface
from OCC.Core.GCE2d import GCE2d_MakeSegment

from OCC.Display.WebGl import threejs_renderer

# First build a helix
aCylinder = Geom_CylindricalSurface(gp_Ax3(gp_XOY()), 6.0)
aLine2d = gp_Lin2d(gp_Pnt2d(0.0, 0.0), gp_Dir2d(1.0, 1.0))
aSegment = GCE2d_MakeSegment(aLine2d, 0.0, pi * 2.0)

helix_edge = BRepBuilderAPI_MakeEdge(aSegment.Value(), aCylinder, 0.0,
                                     6.0 * pi).Edge()

display = threejs_renderer.ThreejsRenderer()
display.DisplayShape(helix_edge, color=(1, 0, 0), line_width=1.)
display.render()
#!/usr/bin/python
# coding: utf-8
r"""
"""
from OCC.Display.WebGl import threejs_renderer
from OCC.BRepPrimAPI import BRepPrimAPI_MakeTorus

# create box
cube_shp = BRepPrimAPI_MakeTorus(25., 15.).Shape()
# load shaders
vs = open('shaders/pink.vs', 'r').read()
fs = open('shaders/pink.fs', 'r').read()
u = open('shaders/pink.uniforms', 'r').read()
my_renderer = threejs_renderer.ThreejsRenderer(vertex_shader=vs,
                                               fragment_shader=fs,
                                               uniforms=u)
my_renderer.DisplayShape(cube_shp)
##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 __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 OCC.Extend.ShapeFactory 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)
#!/usr/bin/python
# coding: utf-8
r"""
"""

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

torus_shp = BRepPrimAPI_MakeTorus(20., 10.).Shape()
my_renderer = threejs_renderer.ThreejsRenderer(background_color="#123345")
my_renderer.DisplayShape(torus_shp)
 def test_threejs_render_torus(self):
     """ Render a simple torus in threejs
     """
     torus_shp = BRepPrimAPI_MakeTorus(20., 10.).Shape()
     my_threejs_renderer = threejs_renderer.ThreejsRenderer()
     my_threejs_renderer.DisplayShape(torus_shp)
Ejemplo n.º 15
0
 def test_threejs_wire(self):
     """ Test: threejs 10 random boxes
     """
     my_threejs_renderer = threejs_renderer.ThreejsRenderer()
     for wire in TopologyExplorer(torus_shp).wires():
         my_threejs_renderer.DisplayShape(wire, mesh_quality=1.0)
Ejemplo n.º 16
0
 def test_threejs_render_torus(self):
     """ Render a simple torus in threejs
     """
     my_threejs_renderer = threejs_renderer.ThreejsRenderer()
     my_threejs_renderer.DisplayShape(torus_shp)