예제 #1
0
    def __init__(self, lines):
        self.camera = None
        self.settings = None
        self.materials = []
        self.planes = []
        self.spheres = []
        self.boxes = []
        self.lights = []

        for line in lines:
            if line[0] != '#' and not line.isspace():
                split_line = line.split()

                if split_line[0] == 'cam':
                    self.camera = Camera(split_line[1:])
                elif split_line[0] == 'set':
                    self.settings = Settings(split_line[1:])
                elif split_line[0] == 'mtl':
                    material = Material(split_line[1:],
                                        len(self.materials) + 1)
                    self.materials.append(material)
                elif split_line[0] == 'pln':
                    self.planes.append(Plane(split_line[1:], self.materials))
                elif split_line[0] == 'sph':
                    self.spheres.append(Sphere(split_line[1:], self.materials))
                elif split_line[0] == 'box':
                    self.boxes.append(Box(split_line[1:], self.materials))
                elif split_line[0] == 'lgt':
                    self.lights.append(Light(split_line[1:]))

        self.objects = self.spheres + self.planes + self.boxes
예제 #2
0
import xml.etree.ElementTree as ET
from modules.box import Box
from modules.exportXML import export

root = ET.Element('root')

# Plane
plane = ET.SubElement(root, 'body')
plane.set('type', 'plane')
plane.set('p', '0 -1 0')
plane.set('n', '0 1 0')
plane.set('name', 'plane')

# Bodies pile
x = 0
for i in range(5):
    x += 8.1
    Box(root, name='box' + str(i), position=str(x) + " 0.0 0.0", dim='8 2 2')

export(root, "../line.xml")
예제 #3
0
    x0 += 25
    y = 0.

    for i in range(nbFloor):
        y += cardSizey - shifty
        x = x0 + (cardSizey / 2. - shiftx) * i + cardSizey / 2. + shiftx

        # Floor cards
        for j in range(nbFloor - i - 1):
            y += cardSizex if (j % 2) else -cardSizex
            if (j > 0): x += 2.4
            orientation = "0 0 -1 " + str(math.pi / 2.)
            Box(root,
                name='book' + str(j),
                position=str(x) + " " + str(y) + " " + str(z),
                dim=dim,
                color="0. 0. 0.5 1.",
                orientation=orientation,
                friction="0.3",
                density="1")

        y -= (cardSizey - shifty) / 2.
        x = x0 + (cardSizey / 2. - shiftx) * i

        # Orientide Cards
        for j in range((nbFloor - i) * 2):
            if (j > 0): x += 1.2
            orientation = "0 0 -1 0.4" if (j % 2 == 0) else "0 0 1 0.4"
            Box(root,
                name='book' + str(j),
                position=str(x) + " " + str(y) + " " + str(z),
                dim=dim,
예제 #4
0
# spinnery=6.5
# dist=2.1
# dx=dy=dz=0
# for i in range(2):
#     dx+=dist
#     dz=0
#     for j in range(2):
#         dz+=dist
#         Sphere(root, position=str(dx+0.75)+" "+str(dy+spinnery)+" "+str(dz+0.75), radius="1", color="0.8 0.6 0.6 1.", density="0.00001", friction="0.1")
#         Sphere(root, position=str(dx-6.75)+" "+str(dy+spinnery)+" "+str(dz-6.75), radius="1", color="0.6 0.8 0.6 1.", density="0.00001", friction="0.1")
#         Box(root, position=str(dx-6.75)+" "+str(dy+spinnery)+" "+str(dz+0.75), orientation="0 -1 0 0", dim="2 2 2", color="0.6 0.8 0.8 1.", density="0.00001", friction="0.1")
#         Box(root, position=str(dx+0.75)+" "+str(dy+spinnery)+" "+str(dz-6.75), orientation="0 -1 0 0", dim="2 2 2", color="0.8 0.8 0.6 1.", density="0.00001", friction="0.1")
# export(root, "../spinnerMultiple.xml")

# spinnery=7
# dx=dy=dz=0
# Sphere(root, position=str(dx+3.75)+" "+str(dy+spinnery)+" "+str(dz+3.75), radius="2", color="0.8 0.6 0.6 1.", density="0.0001")
# Sphere(root, position=str(dx-3.75)+" "+str(dy+spinnery)+" "+str(dz-3.75), radius="2", color="0.6 0.8 0.6 1.", density="0.0001")
# Box(root, position=str(dx-3.75)+" "+str(dy+spinnery)+" "+str(dz+3.75), orientation="0 -1 0 0", dim="3 3 3", color="0.6 0.8 0.8 1.", density="0.0001")
# Box(root, position=str(dx+3.75)+" "+str(dy+spinnery)+" "+str(dz-3.75), orientation="0 -1 0 0", dim="3 3 3", color="0.8 0.8 0.6 1.", density="0.0001")
# export(root, "../spinnerHighRotMassRatio.xml")

spinnery=7
dx=dy=dz=0
Sphere(root, position=str(dx+3.75)+" "+str(dy+spinnery)+" "+str(dz+3.75), radius="2", color="0.8 0.6 0.6 1.", density="0.1")
Sphere(root, position=str(dx-3.75)+" "+str(dy+spinnery)+" "+str(dz-3.75), radius="2", color="0.6 0.8 0.6 1.", density="0.1")
Box(root, position=str(dx-3.75)+" "+str(dy+spinnery)+" "+str(dz+3.75), orientation="0 -1 0 0", dim="3 3 3", color="0.6 0.8 0.8 1.", density="0.1")
Box(root, position=str(dx+3.75)+" "+str(dy+spinnery)+" "+str(dz-3.75), orientation="0 -1 0 0", dim="3 3 3", color="0.8 0.8 0.6 1.", density="0.1")
export(root, "../spinner.xml")
예제 #5
0
dimz = 1
dist = 0.01
for i in range(27):
    y += dimy + dist
    if (i % 3 == 0):
        x += dimx + dist
        y = y0
    if (i % 9 == 0):
        x = x0
        y = y0
        z += dimz + dist
    orientation = "0 -1 0 0.03" if (i % 2) else "0 -1 0 0"
    #color = str(random.uniform(0, 1)) + " " + str(random.uniform(0, 1)) + " " + str(random.uniform(0, 1)) + " 1."
    Box(root,
        name='box' + str(i),
        position=str(x) + " " + str(y) + " " + str(z),
        dim=str(dimx) + " " + str(dimy) + " " + str(dimz),
        density="2.5")

Sphere(root,
       name='ball',
       position="-17.5 3.7 0",
       radius="1.",
       color="0.8 0.8 0. 1.")

# Houses background
composite = Composite(root,
                      obj="data/house2.obj",
                      scale="12",
                      name="house1",
                      position="0 -16.5 -100",
platformDimx = 29  #better impair

nbPlatforms = 3
nbDominos = 33

for k in range(nbPlatforms):
    y += dy
    x = x0
    x += dx / 2 if (k % 2) else -dx / 2
    xp = x
    for i in range(nbDominos):
        x += dx
        Box(root,
            name='domino' + str(i + nbDominos * k),
            position=str(x) + " " + str(y + 1.2) + " " + str(z),
            dim="0.25 2 1",
            density="2")
        if (i == nbDominos / 2):
            v = "-0.22 0 0" if (k % 2) else "0.22 0 0"
            platform = Box(root,
                           name="platform" + str(k),
                           dim=str(platformDimx) + " 0.5 3",
                           position=str(x) + " " + str(y) + " " + str(z),
                           velocity=v)
            height = 3
            platform.addSpring(
                positionB="-" + str(platformDimx / 2) + " 0 1.5",
                positionW=str(-(platformDimx - 1) / 2. + x) + " " +
                str(y + height) + " 1.5")
            platform.addSpring(
예제 #7
0
from modules.composite import Composite
from modules.exportXML import export

import random

root = ET.Element('root')

# Collision
collision = ET.SubElement(root, 'collision')
collision.set('feedbackStiffness', '0')
collision.set('enableCompliance', 'false')

Box(root,
    name='dock',
    position="0. -5. -40.",
    dim="100 5 70",
    color="0.1 0.1 0.1 1.",
    pinned="true",
    friction="0.")

# Containers
dimx = 3
dimy = 1
dimz = 1
dist = 0.1
colors = [
    "0.5 0.3 0.3 1.", "0.3 0.5 0.3 1.", "0.3 0.3 0.5 1.", "0.7 0.7 0.5 1."
]

# Trains
disp = 0
예제 #8
0
import xml.etree.ElementTree as ET
from modules.box import Box
from modules.exportXML import export

root = ET.Element('root')

# Plane
plane = ET.SubElement(root, 'body')
plane.set('type', 'plane')
plane.set('p', '0 -1 0')
plane.set('n', '0 1 0')
plane.set('name', 'plane')

# Bodies pile
y = 0
for i in range(15):
    y += 2.5
    Box(root,
        name='box' + str(i),
        position="0.0 " + str(y) + " 0.0",
        dim='8 2 2')

export(root, "../pile.xml")
예제 #9
0
import xml.etree.ElementTree as ET
from modules.box import Box
from modules.exportXML import export

root = ET.Element('root')

# Fixed bodies
x = 0
for i in range(2):
    if i == 1: x += 18
    Box(root,
        name='box' + str(i),
        position=str(x) + " 0.0 0.0",
        dim='8 2 8',
        pinned="true")

# Pile bodies
y = 0
x = 4
for i in range(8):
    y += 2.5
    if i == 4:
        x += 10
        y = 2.5
    Box(root,
        name='box' + str(i),
        position=str(x) + " " + str(y) + " 0.0",
        dim='8 2 8')

export(root, "../cycle.xml")
예제 #10
0
from modules.sphere import Sphere
from modules.mesh import Mesh
from modules.stand import Stand
from modules.composite import Composite
from modules.exportXML import export

root = ET.Element('root')

# Plane
plane = ET.SubElement(root, 'body')
plane.set('type','plane')
plane.set('p','0 0 0')
plane.set('n','0. 1. 0.0')
plane.set('name','plane')

Box(root, name='wall1', position="0. 1 -50", orientation="0 0 1 0", dim="100 10 1", pinned="true")
Box(root, name='wall2', position="0. 1 50", orientation="0 0 1 0", dim="100 10 1", pinned="true")
Box(root, name='wall3', position="-50 1 0.", orientation="0 0 1 0", dim="1 10 100", pinned="true")
Box(root, name='wall4', position="50 1 0.", orientation="0 0 1 0", dim="1 10 100", pinned="true")

# Default Box
Box(root, name='box1', position="0 100 0", orientation="0 0 1 0", dim="1.8 1.8 1.8")
Box(root, name='box2', position="0 100 0", orientation="0 0 1 0", dim="1.8 1.8 1.8")
Box(root, name='box3', position="0 100 0", orientation="0 0 1 0", dim="1.8 1.8 1.8")
# Sphere(root, name='sphere', position="0 100 0", orientation="0 0 1 0", radius="1")
# Mesh(root, name='venus', obj="data/scaletorso10.obj", st="data/torso_flux.sph", position="0 100 0", orientation="0 0 1 0", scale="0.1")

# Funnel
composite = Composite(root, obj="data/funnel.obj", scale="1", name="funnel", position="0. 50. 0.", velocity="0. 0. 0.", color="0.5 0. 0. 1.", omega="0 0 -0.05")
composite.addBox(name='wall1', position="0. -0.5 -13.5", orientation="-1 0 0 1.07", dim='48 22 1')
composite.addBox(name='wall3', position="0. -0.5 13.5", orientation="1 0 0 1.07", dim='48 22 1')
예제 #11
0
import xml.etree.ElementTree as ET
from modules.box import Box
from modules.exportXML import export

root = ET.Element('root')

# Spring Default
body = Box(root, name='body1', position="0.0 0.0 0.0", dim='2 2 2')
body.addSpring("0. 0. 0.", k="10")

# Spring World
body = Box(root, name='body2', position="4.0 0.0 0.0", dim='2 2 2')
body.addSpring("0. 0. 0.", positionW="4. 10. 0.", k="10")

# Spring body body
body = Box(root, name='body3', position="8.0 0.0 0.0", dim='2 2 2')
body.addSpring("0. 0. 0.", k="10")
boat = Box(root, name='body4', position="8.0 -5.0 0.0", dim='2 2 2')
boat.addSpring("0. 0. 0.", positionB2="0. 0. 0.", k="10", body2="body3")

export(root, "../springsTest.xml")
예제 #12
0
colors = [
    "0.3 0.3 0.3 1.", "0.2 0.5 0.2 1.", "0.3 0.3 0.5 1.", "0.7 0.7 0.5 1."
]
for i in range(8):
    y = str(i * 2.5 + 2.5)
    composite.addBox(name='floor' + str(i),
                     position=" 0. " + y + " 0.",
                     dim='10.2 0.2 4')
    # Books
    if (i > 0):
        for j in range(12):
            yb = str(float(y) - 1.39)
            shift = 4.8 if (i % 2 == 0) else 0.6
            x = str(-45 + shift + 0.42 * j)
            orientation = "0 0 -1 0.3" if (i % 2 == 0) else "0 0 1 0.3"
            orientation = "0 0 -1 0" if (i % 3 == 0) else orientation
            Box(root,
                name='book' + str(j),
                position=str(x) + " " + str(yb) + " " + str(z),
                dim="0.4 2 1.5",
                color=colors[random.randint(0, 3)],
                orientation=orientation,
                friction="0.3",
                density="1")

# Box(root, name='bookAlone1', position="-35.75 "+yb+" 1.", dim="0.15 2 1.5", color=colors[random.randint(0,3)], friction="0.3", density="0.1")
# Box(root, name='bookAlone2', position="-35.9 "+yb+" 1.", dim="0.1 2 1.5", color=colors[random.randint(0,3)], friction="0.3", density="0.1")

export(root, "../chariotvenus.xml")