コード例 #1
0
ファイル: test_805_pycsg.py プロジェクト: vshu3000/ezdxf
def test_sphere_cylinder_subtract():
    a = sphere(count=8, stacks=4, radius=0.5).translate(0.5, 0.5, 0.5)
    b = cylinder_2p(count=16,
                    base_center=(0, 0, 0),
                    top_center=(1, 0, 0),
                    radius=0.3)
    CSG(a) - CSG(b)
コード例 #2
0
ファイル: test_805_pycsg.py プロジェクト: vshu3000/ezdxf
def test_bolt():
    shaft = cylinder_2p(count=32,
                        base_center=(0, 0, 0),
                        top_center=(1, 0, 0),
                        radius=0.1)
    head = cone_2p(base_center=(-0.12, 0, 0), apex=(0.1, 0, 0), radius=0.25)
    notch1 = cube().translate(-0.1, 0, 0).scale(0.02, 0.20, 0.02)
    notch2 = cube().translate(-0.1, 0, 0).scale(0.02, 0.02, 0.20)
    bolt = CSG(shaft) + CSG(head) - CSG(notch1) - CSG(notch2)
コード例 #3
0
from pathlib import Path
from time import perf_counter
import ezdxf

from ezdxf.render.forms import sphere
from ezdxf.addons import MengerSponge
from ezdxf.addons.pycsg import CSG

DIR = Path('~/Desktop/Outbox').expanduser()

doc = ezdxf.new()
doc.layers.new('sponge', dxfattribs={'color': 5})
doc.layers.new('sphere', dxfattribs={'color': 6})

doc.set_modelspace_vport(6, center=(5, 0))
msp = doc.modelspace()

sponge1 = MengerSponge(level=3).mesh()
sphere1 = sphere(count=32, stacks=16, radius=.5,
                 quads=True).translate(.25, .25, 1)

t0 = perf_counter()
subtract = (CSG(sponge1, meshid=1) - CSG(sphere1, meshid=2))
t1 = perf_counter()
# get mesh result by id
subtract.mesh(1).render(msp, dxfattribs={'layer': 'sponge'})
subtract.mesh(2).render(msp, dxfattribs={'layer': 'sphere'})

print(f'runtime: {t1-t0:.3f}s')
doc.saveas(DIR / 'csg_sphere_vs_menger_sponge.dxf')
コード例 #4
0
ファイル: pycsg_sphere.py プロジェクト: yening2020/ezdxf
from ezdxf.render.forms import sphere, cube
from ezdxf.addons.pycsg import CSG

DIR = Path('~/Desktop/Outbox').expanduser()
NLENGTH = .05

doc = ezdxf.new()
doc.layers.new('csg', dxfattribs={'color': 1})
doc.layers.new('normals', dxfattribs={'color': 6})

doc.set_modelspace_vport(6, center=(5, 0))
msp = doc.modelspace()

cube1 = cube().translate(-.5, -.5, -.5)
sphere1 = sphere(count=32, stacks=16, radius=.5, quads=True)

union = (CSG(cube1) + CSG(sphere1)).mesh()
union.render_mesh(msp, dxfattribs={'layer': 'csg', 'color': 1})
union.render_normals(msp, length=NLENGTH, relative=False, dxfattribs={'layer': 'normals'})

subtract = (CSG(cube1) - CSG(sphere1)).mesh().translate(2.5)
subtract.render_mesh(msp, dxfattribs={'layer': 'csg', 'color': 3})
subtract.render_normals(msp, length=NLENGTH, relative=False, dxfattribs={'layer': 'normals'})

intersection = (CSG(cube1) * CSG(sphere1)).mesh().translate(4)
intersection.render(msp, dxfattribs={'layer': 'csg', 'color': 5})
intersection.render_normals(msp, length=NLENGTH, relative=False, dxfattribs={'layer': 'normals'})

doc.saveas(DIR / 'csg_sphere.dxf')
コード例 #5
0
from pathlib import Path
from time import perf_counter
import ezdxf

from ezdxf.render.forms import sphere
from ezdxf.addons import MengerSponge
from ezdxf.addons.pycsg import CSG

DIR = Path("~/Desktop/Outbox").expanduser()

doc = ezdxf.new()
doc.layers.new("sponge", dxfattribs={"color": 5})
doc.layers.new("sphere", dxfattribs={"color": 6})

doc.set_modelspace_vport(6, center=(5, 0))
msp = doc.modelspace()

sponge1 = MengerSponge(level=3).mesh()
sphere1 = sphere(count=32, stacks=16, radius=0.5,
                 quads=True).translate(0.25, 0.25, 1)

t0 = perf_counter()
subtract = CSG(sponge1, meshid=1) - CSG(sphere1, meshid=2)
t1 = perf_counter()
# get mesh result by id
subtract.mesh(1).render_mesh(msp, dxfattribs={"layer": "sponge"})
subtract.mesh(2).render_mesh(msp, dxfattribs={"layer": "sphere"})

print(f"runtime: {t1-t0:.3f}s")
doc.saveas(DIR / "csg_sphere_vs_menger_sponge.dxf")
コード例 #6
0
ファイル: test_805_pycsg.py プロジェクト: vshu3000/ezdxf
def test_cube_intersect():
    a = cube()
    b = cube().translate(0.5, 0.5)
    c = CSG(mesh=a) * CSG(mesh=b)
コード例 #7
0
ファイル: test_805_pycsg.py プロジェクト: vshu3000/ezdxf
def test_cube_subtract():
    a = cube()
    b = cube().translate(0.5, 0.5)
    _ = CSG(a) - CSG(b)
コード例 #8
0
ファイル: test_805_pycsg.py プロジェクト: vshu3000/ezdxf
def test_cube_union():
    a = cube()
    b = cube().translate(0.5, 0.5)
    c = CSG(mesh=a) + CSG(mesh=b)
コード例 #9
0
ファイル: pycsg.py プロジェクト: Rahulghuge94/ezdxf
from ezdxf.render.forms import cube, cylinder_2p

DIR = Path("~/Desktop/Outbox").expanduser()

cube1 = cube()
cylinder1 = cylinder_2p(count=32,
                        base_center=(0, -1, 0),
                        top_center=(0, 1, 0),
                        radius=0.25)

doc = ezdxf.new()
doc.set_modelspace_vport(6, center=(5, 0))
msp = doc.modelspace()

# build solid union
union = CSG(cube1) + CSG(cylinder1)
# convert to mesh and render mesh to modelspace
union.mesh().render_mesh(msp, dxfattribs={"color": 1})

# build solid difference
difference = CSG(cube1) - CSG(cylinder1)
# convert to mesh, translate mesh and render mesh to modelspace
difference.mesh().translate(1.5).render(msp, dxfattribs={"color": 3})

# build solid intersection
intersection = CSG(cube1) * CSG(cylinder1)
# convert to mesh, translate mesh and render mesh to modelspace
intersection.mesh().translate(2.75).render(msp, dxfattribs={"color": 5})

doc.saveas(DIR / "pycsg01.dxf")