Gracias Gracias:  0
Resultados 1 al 1 de 1

Tema: Game Physics and Paths

  1. #1
    Administrador y fundador. Avatar de 3dpoder
    Fecha de ingreso
    Apr 2002
    Mensajes
    15,460

    Game Physics and Paths

    Game Physics and Paths
    By Dave Jarvis




    This is a complex, advanced tutorial showing how to create an animation using Blender's Game Physics Engine and Paths. A Sphere will be dropped onto a Plane, moved along a Path, and then dropped onto a Box.
    Blender has the ability to record physics-based actions to an object's IPO curve. This functionality allows a recorded physics sequence to be rendered as an animation. Since Paths control objects independently of physics, Path motion is not recorded without special intervention. Let us now intervene.



    Setup
    Environment
    1.Press [Ctrl+X] for a new file.
    2.Clik OK to confirm.
    3.Clik SR:2-Model and change it to SR:1-Animation:

    Layout Menu
    4.Split the right-hand side of the 3D view window into two new Windows.
    5.Set the upper window to the IPO Curve Editor.
    6.Set the lower window to the Text Editor.
    7.Remove the Outliner window to increase the 3D view space, resulting in:

    Blender Layout


    Objects
    1.Add » Mesh » UVSphere
    2.Clik OK to accept the default options, then [Tab] to exit edit-mode.
    3.Press [S], 0.25 then Enter to shrink the Sphere.
    4.Press [G], [X], 2 then [Enter] to move the Sphere right.
    5.Press [G], [Y], 2 then [Enter] to move the Sphere back.
    6.Press [G], [Z], 4 then [Enter] to move the Sphere up.
    7.Add » Mesh » Plane, then [Tab] to exit edit-mode.
    8.Press [S], 5, then Enter to scale the Plane.
    9.Press [NumPad1] for a front view:
    Sphere, Box, and Plane



    10.Add » Curve » Path, then [Tab] to exit edit-mode.
    11.Press [G], [Y], 2 then [Enter] to move the Path back.
    12.Press [G], [Z], 0.25 then [Enter] to move the Path up.

    This will align the Path's first vertex with the Sphere's center. After it falls, the Sphere will move along the Path. There are other ways to align vértices that don't rely on premeditated positioning, as in step 18.

    13.Object » Mirror » X Local
    14.Press [NumPad7] for a top view.
    15.Press [Tab] to edit the Path.
    16.Press [A] to deselect all vértices.
    17.Clik RMB to select the last vertex (left-most).
    18.Press [Shift+S] then clik Selection -> Cursor.
    19.Press [G], [Z], 1.5 then [Enter] to move the last vertex up.
    20.Clik RMB to select the second-last vertex.
    21.Press [G], [X], 1 then [Enter] to align the second-last vertex with the last.
    22.Press [G], [Z], 2 then [Enter]to move the second-last vertex up.
    23.Clik RMB to select the first vertex (right-most) and Press [Shift+S], then clik Cursor -> Selection.
    Rotating the scene should show a view similar to:



    Properly Positioned Path

    Materials
    1.Press [Tab] to stop editing the Path.
    2.Press [F5] for the Materials buttons.
    3.Clik RMB on the Cube to only select the Cube.
    4.Under the "Links and Pipeline" panel, under "Link to Object", Rename Material to Cube.
    5.Clik RMB on the Plane to only select the Plane.
    6.Under the "Links and Pipeline" panel, under "Link to Object", Clik Add New.
    7.Rename Material to Plane.

    Record Path IPO
    1.Press [NumPad7] for a top view.
    2.Add » Empty
    3.Clik [SHIFT]+RMB on the Path.
    The Empty and Path should both be selected.
    4.Press [Ctrl+P] for the parenting menú.
    5.Clik Follow Path to parent the Empty to the Path.
    6.Copy and paste the following code into the Text window:

    #
    # This script is used to map the IPO curve of an object as it travels
    # through frames of an animation. The algorithm follows:
    #
    # 1. Calculate number of steps needed to animate at given framerate.
    # 2. Get the selected object.
    # 3. Duplicate the selected object (which will hold the generated IPO).
    # 4. Reset the duplicate object.
    # 5. Loop over the number of frames at the calculated framerate.
    # 6. Set the active frame.
    # 7. Position the duplicate object to the same place as the selected one.
    # 8. Copy the selected object's location and rotation into the duplicate's IPO.
    #
    # Usage:
    # (1) Select the object that follows a curve.
    # (2) Load this script in Blender's Text window.
    # (3) Move the mouse to the Text window.
    # (4) Press Alt-p.
    #
    import Blender
    from Blender import Object, Scene
    framesPerSecond = Scene.GetCurrent().getRenderingContext().fps
    firstFrame = 0
    lastFrame = 100
    stepsPerFrame = (lastFrame - firstFrame) / framesPerSecond
    selected = Object.GetSelected()[0]
    Object.Duplicate()
    duplicate = Object.GetSelected()[0]
    duplicate.clrParent()
    duplicate.clearIpo()
    for frame in range( firstFrame, lastFrame, stepsPerFrame ):
    Blender.Set( 'curframe', frame )
    duplicate.setMatrix( selected.getMatrix() )
    duplicate.insertIpoKey( Object.LOC )
    duplicate.insertIpoKey( Object.ROT )

    7.Change the name of the script to copy-path.py.
    8.Save the script as copy-path.py.
    9.Clik RMB to select the Empty.
    10.Move the mouse to the Text window.
    11.Press [Alt+P] to execute the script.
    12.While executing, the script instructs Blender to scrub through frames at 25 frames per second (default). With 100 frames, only every fourth frame is used. Each frame that is used causes the duplicate object to have its location and rotation recorded as an IPO key (i.e., a vertex in that object's IPO curve).
    13.Move the mouse to the 3D window.
    14.Press [Del] then [Enter] to delete Empty.001.
    15.Clik RMB to select the Empty.
    16.Press [Alt+P].
    17.Clik Clear Parent to remove the Path as the Empty's parent.
    18.Press [Shift+DownArrow] to Reset the IPO to frame 0.
    If the Empty moves in unexpected ways, it is likely this step was missed.
    19.In the IPO window, set the Empty to use the newly created IPO data block, Obipo.



    Empty's New IPO
    20.Clik RMB to select the Path.
    21.Press [M], 2, then [Enter] to move the Path to another layer.
    22.Press [F7] for the Object buttons.
    23.Clik RMB to select the Empty.
    24.Under the "Animation Settings" panel, Set TimeOffset to 180.
    This is the number of frames the Sphere takes to hit the Plane.

    Game Engine Actors
    1.Press [F4] for the Logic buttons.
    2.Clik RMB to select the Sphere.
    3.Clik Actor.
    4.Clik Dynamic.
    5.Clik Bounds.
    6.Set Radius to 0.75.
    7.Change Box to Sphere (as the bounds type).
    8.Clik RMB to select the Plane.
    9.Clik Actor.
    10.Clik Bounds.

    Game Engine Logic

    When the Sphere collides with the Plane the following must happen:
    The Sphere makes the Empty its parent.
    The Empty plays its IPO.
    The Sphere's IPO keys are recorded for each frame.

    Logic Blocks - Empty
    1.Clik RMB to select the Empty.
    2.Clik Add Property.
    3.Change the name to collision.
    4.Change the type from its default value Float to Bool.
    This will record the Sphere colliding with the Plane. Upon collision, the Sphere must follow the Empty (which has an IPO that was derived from the Path that was banished to Layer 2).
    5.Under the "Sensors" Panel, Clik Add (right next to Empty) to add a sensor to the Empty.
    6.Change the name of the sensor to s.copy.
    This sensor will help continually copy the value of the Sphere's collision property.
    7.To add another sensor, Clik Add, below Sensors.
    8.Change the sensor type from Always to Property.
    9.Change the name of the sensor to s.ipo.
    10.Set the value of Prop to collision.
    11.Set the value of Value to True.
    12.Under the "Controllers" panel, Clik Add, to add a controller.
    13.Change the name of the controller to c.copy.
    14.To add another controller, Clik Add, below Controllers.
    15.Change the name of the controller to c.ipo.
    16.Under the "Actuators" panel, Clik Add, to add an actuator.
    17.Change the name of the actuator to a.copy.
    18.Change the actuator type from Motion to Property.
    19.Change the actuator's property type from Assign to Copy.
    20.Set the value of Prop to collision.
    21.Set the value of OB to Sphere.
    22.Set the value of Prop to collision.
    23.To add another actuator, Clik Add, below Actuators.
    24.Change the actuator type from Motion to Ipo.
    25.Change the name of the actuator to a.ipo.
    26.Set the value of End to 100.
    27.Link Sensor copy to Controller copy to Actuator copy.
    28.Link Sensor ipo to Controller ipo to Actuator ipo.
    The logic should look similar to:



    Logic Blocks for the Empty


    The logic blok instructs Blender to continually copy the Sphere's collision property into the Empty's property of the same name. Once the collision property is set to True, the Empty is instructed to replay its IPO. All that remains is to set the Sphere's parent to the Empty, remove the parent relationship when appropriate, and record the Sphere's complete IPO curve.

    Logic Blocks - Sphere - Sensors

    1.Clik RMB to select the Sphere in the 3D Window, then Clik Add Property.
    2.Change the name to collision.
    3.Change the type from its default value Float to Bool.
    4.Clik Add Property.
    5.Set the name to time.
    6.Change the type from Float to Timer.
    A timer will be used to remove the Sphere's parent (the Empty). It is alos used to calculate the current frame.
    7.Under the "Sensors" Panel, Clik Add, below Sensors.
    8.Change the name to s.plane.
    9.Change the sensor type to Collision.
    10.Toggle M/P on.
    11.Set the value of M/P to Plane.
    12.Clik Add, below Sensors.
    13.Change the name to s.time.
    14.Change the sensor type to Property.
    15.Toggle Activate TRUE level triggering on.
    16.Change the type from Equal to Interval.
    17.Set the value of Prop: to time.
    18.Set the value of Min: to 4.0.
    19.Set the value of Max: to 4.1.
    20.Clik Add, below Sensors.
    21.Change the name to s.start.
    22.Toggle Activate TRUE level triggering off.
    23.Clik Add, below Sensors.
    24.Change the name to s.record.
    25.Set the value of f: to 2.
    26.Toggle Activate TRUE level triggering on.
    27.Clik Add, below Sensors.
    28.Change the name to s.stop.
    29.Change the sensor type to Collision.
    30.Toggle M/P on.
    31.Set the value of M/P to Cube.

    Logic Blocks - Sphere - Controllers

    1.Under the "Controllers" Panel, Clik Add, below Controllers, five times.
    2.Change the name of the controllers, from top to bottom as:
    i.c.plane
    ii.c.time
    iii.c.start
    iv.c.record
    v.c.stop
    3.Change the default controller type from AND to Python for c.start and c.record.
    4.Create a new text file in the Text window by clicking the arrows next to the datablok name and clicking ADD NEW.
    5.Copy and paste the following code into the Text window:

    #
    # This script is used to record the IPO curve of an object as it is
    # assaulted by the Game Physics engine. It should be executed automatically
    # via Logic Blocks. The algorithm follows:
    #
    # 1. Get the object being controlled by physics.
    # 2. Create a new IPO for recording the motion of that object.
    # 3. Store the IPO curves for use by the frame recorder.
    #
    import Blender
    # Get the name of the object being controlled by physics.
    #
    gameObject = GameLogic.getCurrentController().getOwner()
    objectName = gameObject.getName()[2:]
    # Create an IPO of type Object named 'Recorded IPO'.
    #
    blenderObject = Blender.Object.Get( objectName )
    ipo = Blender.Ipo.New( 'Object', 'Recorded IPO' )
    blenderObject.setIpo( ipo )
    # Get the position of gameObject as IPO curves.
    #
    locx = ipo.addCurve( 'LocX' )
    locy = ipo.addCurve( 'LocY' )
    locz = ipo.addCurve( 'LocZ' )
    # Keep a reference to the curves in a global variable. The variable
    # (GameLogic.rec) is used by a script that records the position of the
    # game Object per frame.
    #
    GameLogic.rec = [gameObject, locx, locy, locz]
    6.Change the name of the script to record-ipo.py.
    7.Save the script as record-ipo.py.
    8.Create a new text file in the Text window by clicking the arrows next to the datablok name and clicking ADD NEW, and then change the name to record-frame.py and save it as record-frame.py.
    9.Copy and paste the following code into the Text window:

    #
    # This script is used to record the position of an object as it travels
    # through each frame, independent of the Game Physics. If Blender is set
    # to record Game Physics to IPO, toggle that menú item OFF. This is a
    # replacement. The algorithm follows:
    #
    # 1. Get the object being controlled by physics.
    # 2. Get the object's position (for a given frame).
    # 3. Update the recorded curves (stored in the global variable GameLogic.rec).
    #
    import Blender
    from Blender import Scene
    gameObject = GameLogic.getCurrentController().getOwner()
    position = gameObject.getPosition()
    frame = gameObject.time * Scene.GetCurrent().getRenderingContext().fps
    # Only try to update the curves if the variable has been initialized.
    #
    if hasattr( GameLogic, 'rec' ):
    # Set the curves for the X, Y, and Z axis.
    #
    GameLogic.rec[1].addBezier( (frame, position[0]) )
    GameLogic.rec[1].update()
    GameLogic.rec[2].addBezier( (frame, position[1]) )
    GameLogic.rec[2].update()
    GameLogic.rec[3].addBezier( (frame, position[2]) )
    GameLogic.rec[3].update()
    10.Under the "Controllers" Panel, Set the value of Script: for controller c.start to record-ipo.py.
    11.Likewise, Set the value of Script: for c.record to record-frame.py.
    12.Under the "Actuators" Panel, Clik Add, below Actuators, five times.
    13.Change the type of actuators, from top to bottom as:
    i.Property
    ii.Parent
    iii.Property
    iv.Parent
    v.Game
    14.Change the name of the actuators, from top to bottom as:
    i.a.start.parent
    ii.a.parent.empty
    iii.a.stop.parent
    iv.a.parent.none
    v.a.stop
    15.From top to bottom:
    i.Set the Prop value of "a.start.parent" to collision.
    ii.Set Value of "a.start.parent" to True.
    iii.Set the OB value of "a.parent.empty" to Empty.
    iv.Set the Prop value of "a.stop.parent" to collision.
    v.Set Value of "a.stop.parent" to False.
    vi.Change Set Parent of "a.parent.none" to Remove Parent.
    vii.Change Start new game of "a.stop" to Quit this game.
    16.Link Sensors to Controllers to Actuators:



    Logic Blocks for the Sphere

    Render Animation
    1.Move the mouse cursor over to the 3D window.
    2.Press [P] to invoke the wrath of the Game Physics.
    3.Press [Alt+A] to play the animation using IPO curves.
    The Sphere should fall from gravity to the Plane, follow the Path, then fall from gravity to the Box.
    4.Render » Render Animation


    David Jarvis
    URL: http://www.davidjarvis.ca/

    www.blenderart.org
    Miniaturas adjuntadas Miniaturas adjuntadas Game Physics and Paths-1_pagina_1_imagen_0007.jpg   Game Physics and Paths-1_pagina_1_imagen_0009.jpg   Game Physics and Paths-1_pagina_2_imagen_0005.jpg   Game Physics and Paths-1_pagina_2_imagen_0006.jpg  

    Game Physics and Paths-1_pagina_4_imagen_0005.jpg   Game Physics and Paths-1_pagina_5_imagen_0005.jpg   Game Physics and Paths-1_pagina_8_imagen_0005.jpg  
    Imágenes adjuntadas Imágenes adjuntadas Game Physics and Paths-1_pagina_1_imagen_0008.jpg 
    Si vas a subir un trabajo al foro, hazlo adjuntando la imagen, archivo, vídeo o lo que sea, no publicando enlaces de otros sitios. http://www.foro3d.com/f45/forma-correcta-de-insertar-imagenes-y-archivos-en-nuestro-mensaje-98930.html

    |Agradecer cuando alguien te ayuda es de ser agradecido|

Temas similares

  1. Blender Consulta respecto a Particulas y Physics
    Por mikecore3d en el foro Partículas y Dinámicas
    Respuestas: 5
    Último mensaje: 19-02-2013, 10:55
  2. Blender Physics of Circular Motion
    Por Freemind en el foro Blender Art Magazine nº31 (in English)
    Respuestas: 0
    Último mensaje: 15-06-2012, 19:14
  3. Blender manuales para physics buttons
    Por LEMUR en el foro Partículas y Dinámicas
    Respuestas: 2
    Último mensaje: 31-05-2009, 23:23
  4. Terragen Sketchup physics test
    Por 3dpoder en el foro Índice de Video3d.es
    Respuestas: 0
    Último mensaje: 26-03-2009, 02:42
  5. Poket Physics: alucina en la Nintendo DS
    Por Klópes en el foro Discusiones generales
    Respuestas: 5
    Último mensaje: 11-04-2008, 20:28

Actualmente estos son sus permisos de publicación en el foro.

  • -No puedes crear nuevos temas al no estar registrado o no haber iniciado sesión en el foro.
  • -No puedes responder temas al no estar registrado o no haber iniciado sesión en el foro.
  • -No puedes subir archivos adjuntos al no estar registrado o no haber iniciado sesión en el foro.
  • -No puedes editar tus mensajes al no estar registrado o no haber iniciado sesión en el foro.
  •