Пример #1
0
# Next, let's create a clickable object to start the timeline
my_object = objects.W3DObject(
    name="button",  # Give it a name
    color=(255, 0, 0),  # Make it red
    placement=placement.W3DPlacement(  # Specify position and orientation
        position=(0, 1, 0),  # We'll leave rotation as default for now
    ),
    content=objects.W3DText(  # Specify that this is a text object
        text="Play"  # ...with text reading "Hello, World!"
    ),
    link=objects.W3DLink(  # Add a clickable link to the text object
        actions={
            0: [  # On first click (index 0)...
                actions.TimelineAction(  # start the timeline
                    timeline_name="my_timeline", change="Start"
                )
            ]
        }
    )
)

# Now add this object to the project
my_project["objects"].append(my_object)
my_project["debug"] = True

# Finally, we render the whole thing using Blender, export it, and display the
# result
export_to_blender(my_project,
                  filename="timeline_sound_sample.blend",
                  display=True)
Пример #2
0
    start_immediately=True,
    actions=absolute_actions
)
my_project["timelines"].append(absolute_timeline)

relative_actions.append(
    (
        2 * theta_div, actions.TimelineAction(
            timeline_name="absolute",
            change="Start"
        )
    )
)

relative_timeline = timeline.W3DTimeline(
    name="relative",
    start_immediately=False,
    actions=relative_actions
)
my_project["timelines"].append(relative_timeline)
# Now, we export the project to archival XML (e.g. for use in legacy cwapp
# environment)
my_project.save_XML("axis_rotations.xml")

# Finally, we render the whole thing using Blender, export it, and display the
# result
export_to_blender(
    my_project, filename="axis_rotations.blend", display=True,
    fullscreen=False
)
Пример #3
0
    color=(255, 0, 0),  # Make it red
    placement=placement.W3DPlacement(  # Specify position and orientation
        position=(0, 1, 0),  # We'll leave rotation as default for now
    ),
    content=objects.W3DText(  # Specify that this is a text object
        text="Hello, World!"  # ...with text reading "Hello, World!"
    ),
    link=objects.W3DLink(  # Add a clickable link to the text object
        actions = {
            -1: [  # On every click (negative number)...
                actions.ObjectAction(  # ...change the object...
                    object_name="hello",  # ...named hello...
                    duration=1,  # ...over a period of one second...
                    move_relative=True,  # ...by moving it relative to its
                                         # current location...
                    placement=placement.W3DPlacement(
                        position=(0, 0.5, 0)  # ...back half a meter.
                    )
                )
            ]
        }
    )
)

# Now add this object to the project
my_project["objects"].append(my_object)

#Finally, we render the whole thing using Blender, export it, and display the
#result
export_to_blender(my_project, filename="link_sample.blend", display=True)
Пример #4
0
        my_object = objects.W3DObject(
            name="elem{}x{}".format(i, j),
            color=(randint(0, 255), randint(0, 255), randint(0, 255)),
            placement=placement.W3DPlacement(
                position=(
                    radius*sin(theta)*cos(phi),
                    radius*sin(theta)*sin(phi),
                    radius*cos(theta)
                ),
                rotation=placement.W3DRotation(
                    rotation_mode="LookAt",
                    rotation_vector=(0, 0, 0)
                )
            ),
            content=objects.W3DText(
                text="W3D"
            ),
        )

        my_project["objects"].append(my_object)

#Now, we export the project to archival XML (e.g. for use in legacy cwapp
#environment)
my_project.save_XML("sphere_sample.xml")

#Finally, we render the whole thing using Blender, export it, and display the
#result
export_to_blender(
    my_project, filename="sphere_sample.blend", display=True, fullscreen=True)
Пример #5
0
import argparse
import os
import sys
home_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.abspath(os.path.join(home_dir, os.pardir)))

from pyw3d import project, export_to_blender, W3D_CONFIG

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("config",
                        choices=["desktop", "desktopfull"],
                        help="run configuration")
    parser.add_argument("project_file")
    if "blender" in sys.argv[0]:
        args = parser.parse_args(sys.argv[4:])
    else:
        args = parser.parse_args()

    print("Configuration information: ", W3D_CONFIG)

    # It's as simple as loading the project...
    my_project = project.W3DProject.fromXML_file(args.project_file)
    blend_filename = "run.blend"

    # ...and exporting it!
    export_to_blender(my_project,
                      filename=blend_filename,
                      display=True,
                      fullscreen=(args.config == "desktopfull"))
Пример #6
0
])

absolute_actions.append((2 * (len(ordered_names) + 1),
                         actions.TimelineAction(timeline_name="relative",
                                                change="Start")))

absolute_timeline = timeline.W3DTimeline(name="absolute",
                                         start_immediately=True,
                                         actions=absolute_actions)
my_project["timelines"].append(absolute_timeline)

relative_actions.append(
    (5, actions.TimelineAction(timeline_name="absolute", change="Start")))

relative_timeline = timeline.W3DTimeline(name="relative",
                                         start_immediately=False,
                                         actions=relative_actions)
my_project["timelines"].append(relative_timeline)

my_project["debug"] = True
# Now, we export the project to archival XML (e.g. for use in legacy cwapp
# environment)
my_project.save_XML("wall_movement.xml")

# Finally, we render the whole thing using Blender, export it, and display the
# result
export_to_blender(my_project,
                  filename="wall_movement.blend",
                  display=True,
                  fullscreen=False)
Пример #7
0
    placement=placement.W3DPlacement(  # Specify position and orientation
        position=(0, 1, 0),  # We'll leave rotation as default for now
    ),
    content=objects.W3DText(  # Specify that this is a text object
        text="Hello, World!",  # ...with text reading "Hello, World!"
        font="LinBiolinum_K.otf"
    ),
    link=objects.W3DLink(  # Add a clickable link to the text object
        actions = {
            -1: [  # On every click (negative number)...
                actions.ObjectAction(  # ...change the object...
                    object_name="hello",  # ...named hello...
                    duration=1,  # ...over a period of one second...
                    move_relative=True,  # ...by moving it relative to its
                                         # current location...
                    placement=placement.W3DPlacement(
                        position=(0, 0.5, 0)  # ...back half a meter.
                    )
                )
            ]
        }
    ),
)

# Now add this object to the project
my_project["objects"].append(my_object)

#Finally, we render the whole thing using Blender, export it, and display the
#result
export_to_blender(my_project, filename="link_sample.blend", display=True)
Пример #8
0
my_project["objects"].append(my_object)

my_object = objects.W3DObject(
    name="litmodel",
    placement=placement.W3DPlacement(position=(-10, 20, 0),
                                     rotation=placement.W3DRotation(
                                         rotation_mode="LookAt",
                                         rotation_vector=(0, 0, 0),
                                     )),
    content=objects.W3DModel(filename="models/bathroom2.obj"),
    lighting=True)

my_project["objects"].append(my_object)

my_object = objects.W3DObject(
    name="unlitmodel",
    placement=placement.W3DPlacement(position=(10, 20, 0),
                                     rotation=placement.W3DRotation(
                                         rotation_mode="LookAt",
                                         rotation_vector=(0, 0, 0),
                                     )),
    content=objects.W3DModel(filename="models/bathroom2.obj"),
    lighting=False)

my_project["objects"].append(my_object)
my_project["background"] = (140, 0, 140)

my_project["debug"] = True

export_to_blender(my_project, filename="lighting.blend", display=True)
Пример #9
0
where run.xml is a copy of your project in archival XML format.

It is possible to use this script as a drop-in replacement for cwapp with
CWEditor. In the "Run" menu of CWEditor, select "Configure Paths". Then, simply
browse to find this script in the resulting dialog.

You may also need to make this script executable on your platform. On
Unix-based systems, this can be done from terminal via::

    $ chmod u+x cwapp.py

"""

import argparse
from pyw3d import project, export_to_blender

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "config", choices=["desktop", "desktopfull"], help="run configuration")
    parser.add_argument("project_file")
    args = parser.parse_args()

    # It's as simple as loading the project...
    my_project = project.W3DProject.fromXML_file(args.project_file)
    # ...and exporting it!
    export_to_blender(
        my_project, display=True, fullscreen=(args.config == "desktopfull")
    )
Пример #10
0
                              (radius + 8) * sin(theta) * sin(phi),
                              (radius + 8) * cos(theta)),
                ),
                content=objects.W3DPSys(particle_group="particles",
                                        max_particles=100,
                                        max_age=3,
                                        speed=1,
                                        particle_actions="my_actions"),
                visible=True))
        my_project["trigger_events"].append(
            triggers.HeadPositionTrigger(
                name="trigger{}x{}".format(i, j),
                box=triggers.EventBox(direction="Inside",
                                      corner1=(i, j, i + j),
                                      corner2=(j, i + 5, i + j)),
                actions=[
                    actions.ObjectAction(object_name="system{}x{}".format(
                        i, j),
                                         visible=False)
                ]))

my_project["profile"] = True
my_project["debug"] = False

start_time = time.time()
export_to_blender(my_project,
                  filename="performance_sample.blend",
                  display=False,
                  fullscreen=True)
print("Approximate wall time: {}".format(time.time() - start_time))
Пример #11
0
            name="elem{}x{}".format(i, j),
            color=(randint(0, 255), randint(0, 255), randint(0, 255)),
            double_sided=False,
            placement=placement.W3DPlacement(
                position=(
                    radius*sin(theta)*cos(phi),
                    radius*sin(theta)*sin(phi),
                    radius*cos(theta)
                ),
                rotation=placement.W3DRotation(
                    rotation_mode="LookAt",
                    rotation_vector=(0, 0, 0)
                )
            ),
            content=objects.W3DText(
                text="W3D"
            ),
        )

        my_project["objects"].append(my_object)

#Now, we export the project to archival XML (e.g. for use in legacy cwapp
#environment)
my_project.save_XML("single_sided_sample.xml")

#Finally, we render the whole thing using Blender, export it, and display the
#result
export_to_blender(
    my_project, filename="single_sided_sample.blend", display=True,
    fullscreen=True)