POV-Ray : Newsgroups : povray.general : Attempt to POV4 Syntax basics : Re: Attempt to POV4 Syntax basics Server Time
31 Jul 2024 10:20:29 EDT (-0400)
  Re: Attempt to POV4 Syntax basics  
From: Bruno Cabasson
Date: 11 Oct 2007 09:35:00
Message: <web.470e2653153c00f6e8ba46670@news.povray.org>
Fa3ien <fab### [at] yourshoesskynetbe> wrote:
> It seems to me that a combination between the backward-compatibility
> thing you suggested and Bruno Cabasson's samples would be ideal.
>
> Fabien.

I continue to dig... Here is a more signifiant fragment of code: a sample
scene with the related shipped-with classes that would be part of POV4
(skeletons for basic objects like spheres, planes, ...).

// my_stuff/trash/sample_scene.pov4 -------------------------------------
package my_struff.trash;

scene sample_scene
{
    camera {...}
    light_source{...}

    // Create a plane
    the_plane = plane
    {
        y, 0 // properties not named => valued in the order they apear
             // in the definition
        pigment // Hope this syntax can be kept, and the parser can assume
                //(as POV does today):material{texture{pigment{...}}}
        {
            agate
            turbulence 0.3
            color_map
            {
                ...
            }
        }
        finish {shiny}
    }

    // Create a sphere
    my_sphere = sphere
    {
        location 0 // Valuation by property name
        radius 1
        texture {metals.brass_1D}  // 'metals' in pov.primitives.*, imported
by default.

        // Inside construction blocks, methods returning something cannot
        // be invoked, especially conversion methods.
        // tomesh() is illegal here

        dropon(the_plane)

        timeline
        {
            // Animation parameters only available in this section.
            // And 'timeline' bocks only allowed in creation blocks.
            // POV4 would handle the time lines of objects properly,
            // with well defined mechanisms, and then send the sucessive
            // results to the renderer in a loop it controls, either as a
            // new scene (as POV does today), or as deltas for animated
            // objects, provided the renderer is designed for that.
            // The user could also specify whether or not the photon map
            // and radiosity data should be recomputed with the new
            // situation. By default, it would be 'yes'.

            // Make the ball roll: use the method predefined in the
            // 'sphere' class.
            // 'delta_t' keyword (or field of some provided
            // 'animation' module).
            roll_on_plane (my_plane, define_trajectory(), delta_t)

        }
    }

    // Make a mesh out of the sphere
    my_other_sphere = my_sphere.tomesh();
    my_other_sphere.subdivide();
    object // could be 'mesh'?
    {
        my_other_sphere
        timeline
        {
            // Make it follow the other sphere
            follow (my_sphere, 1)

            // make the ball bounce at the same time: use the scene's
            // 'bounce' method.
            bounce(this, 3, 2, clock-initial_clock)
        }
    }

    // Methods specific to that scene. Better than macros.
    spline define_trajectory()
    {
        ...
    }

    bounce (obj:object, frequency, amplitude, t)
    {
        // Bouncing formula.
        // Modify obj.matrix accordingly.
        ...
        obj.matrix = result;
    }

    follow (obj:object, distance, delay)
    {
        ...
    }
}
// ----------------------------------------------------------------------



With the following definitions:


// pov/primitives/renderer.pov4 -----------------------------------------
package pov.primitives;

// A module cannot be instanciated. Pretty much like static classes in Java.
// Parse-time access to renderer features and API. Can be used to
// define shaders.
module renderer
{

    // The 'trace' method ...
    vector[] trace (from:vector, direction:vector, o:object) {external
"trace"}

    // The 'hits' method is like 'trace', nut only return true if
    // the object was hit by the ray.
    boolean hits (from:vector, direction:vector, o:object) {external "hits"}

    // The 'visible' method returns true if a given point is visible
    // from another point.
    // Might be implemented by the renderer, or coded here.
    //boolean visible (target:vector, from:vector) {external "visible"}
    boolean visible (target:vector, from:vector)
    {

    }

    // The 'intersections' method intersects a ray with the whole scene
    // so far. It returns an array of vector triplets, one triplet per
    // intersection encountered by the ray from its start position.
    // They are ordered in the order of encounter.
    // Each triplet is the form:
    //
    //    <n, 0, 0> <ix, ix, iz> <nx, ny, nz>
    //
    // where
    //    n is the number of the object intersected. Objects are numbered
    //      from 0 while added to the scene.
    //          (Encapsulated in a vector for simplification of interface).
    //    <ix, ix, iz> is the intersection point of the ray on the suraface
    //                 of the object.
    //    <nx, ny, nz> is the normal at that point.
    vector [][3] intersections(from:vector, direction:vector) {external
"intersections"}

    color evalpigment (pigm:pigment, p:vector) {external "evalPigment"}
    color evalpigment (obj:object, p:vector) {evalpigment(obj.pigment)}
 }
// ----------------------------------------------------------------------

// pov/primitives/matrix.pov4 -------------------------------------------
package pov.primitives;

class matrix
{
    const I:float[][] = {{1,0,0,0}, {0,1,0,0}, {0,0,1,0}, {0,0,0,0}}

    property m:float[][] = I;

    scale(x,y,z) {/* apply <x,y,z> scale to m */}
    rotate(x,y,z) {/* apply <x,y,z> rotate to m */}
    translate(x,y,z) {/* apply <x,y,z> translate to m */}
    moveto(x,y,z) {/* apply <x,y,z> moveto to m */}

    apply (m00, m01, ... m33) {/* apply m00..m33 matrix to m */}

}
// ----------------------------------------------------------------------

// pov/primitives/object.pov4 -------------------------------------------
package pov.primitives;

class object
{
    // properties can become 'pseudo-keywords' for syntax highlighting
    property location = origin; // or <0,0,0>, or 0
    property matrix = Matrix.I;   // I = Identity matrix
    property bbox:vector[];

    // properties used by POV’s default shader
    property material = White; // Notational shortcut: material -> texture-
> pigment -> color (if possible, TBC)
    property hollow = false;
    property double_illuminate = false;
    property no_shadow = false;
    property no_image = false;
    property no_reflection = false;
    property inverse = false;
    property MotionBlur motion_blur = null;

    // transformation methods (common to all objects)
    translate (v:vector) {translate(v.x, v.y, v.z)}
    translate (f:float) {translate <f,f,f>} // Promotion through method
overloading. But can be done by the parser. TBD.
    translate (x,y,z) {matrix.translate (x,y,z)} // translate 'matrix'
property ;

    rotate (v:vector) {rotate (v.x, v.y, v.z)}
    rotate (f:float) {rotate <f,f,f>}
    rotate (x,y,z) {matrix.rotate(x,y,z)}

    scale (v:vector) {scale (v.x, v.y, v.z)}
    scale (f:float) {scale <f,f,f>}
    scale (x,y,z) {matrix.scale(x,y,z)}

    matrix (m00, m01, ... m33) {...}
    matrix (m:Matrix) {matrix.apply(m)}

    moveto (v:vector) {moveto (v.x, v.y, v.z)}
    moveto (f:float) {moveto <f,f,f>}
    moveto (x,y,z) {matrix.moveto(x,y,z)}

    // Get inspired by transforms.inc
    shear (a,b,c:vector) {...}
    axisscale (axis:vector, amount) {...}
    axisrotate (axis:vector, angle) {...}
    rotatearound (rotation:vector, point:vector) {...}
    reorient(target;object) {...}
    pointat (yaxis:vector) {...}
    center (axis:vector) {...}
    align(target;object) {...}

    // CSG methods?
    union (o:object) {...}
    merge (o:object) {...}
    difference (o:object) {...}
    intersection (o:object) {...}

    // Object conversion methods
    tomesh() {} // To be overriden by specific object types.
    tomesh2() {} // To be overriden by specific object types.

    // Placement methods
    dropon(target:object) {dropon(target, <0,0,0>)}
    dropon(target:object, yoffset) {dropon(target, <0, yoffset, 0>)}
    dropon(target:object, offsets:vector) {dropon(target, xoffset, yoffset,
zoffset)}
    dropon(target:object, xoffset, yoffset, zoffset)
    {
        // try downwards first
        res = trace (location, -y, target)
        if (vlength(res[1]) != 0)
            moveto res[0]
        else
        {
            // try upwardsthen
            res = trace (location, y, target)
            if (vlength(res[1]) != 0)
                moveto res[0]
        }
    }
    placeon(target:object)
    {
        ...
    }

    //

    // The ray-object intersection algo is hardcoded and optimized
    // in the renderer for performance. If different from 'native'
    // the renderer will call user code for intersection testing.
    intersect {native}

    // The standard, hardcoded POV shader (standard materials, standard
    //  radiosity, standard photons) will be used.
    shader {default}
}
// ----------------------------------------------------------------------

// pov/primitives/sphere.pov4 -------------------------------------------
package pov.primitive;

import pov.math.*;

class sphere extends object
{
    // Shape properties
    property radius = 1.0;

    // Methods
    mesh tomesh() {...} // Sphere-specific
    mesh2 tomesh2() {...}
}
// ----------------------------------------------------------------------

// pov/primitives/box.pov4 ----------------------------------------------
package pov.primitive;

import pov.math.*;

class box extends object
{
    // Shape properties
    property start = origin;
    property end:vector = 1; // As 'vector' is specified, 1 is promoted to
<1,1,1>;

    // Methods
    tomesh() {...} // Box-specific
    tomesh2() {...}

    // sphere-specific method
    roll_on_plane (p:object, s:spline, delta_t)
    {
        // Attitude propagator wrt previous position:
        // Changes the matrix by applying the changes between
        // t and t+delta_t, by folowing the spline s
        ...
    }
}
// ----------------------------------------------------------------------

// pov/primitives/box.pov4 ----------------------------------------------
package pov.primitive;

import pov.math.*;

class plane extends object
{
    // Shape properties
    property normal = y;
    property offset = 0;

    // Methods
    tomesh() {...} // Plane-specific
    tomesh2() {...}
}
// ----------------------------------------------------------------------

// pov/primitives/box.pov4 ----------------------------------------------
package pov.primitive;

import pov.math.*;

class mesh extends object
{
    // Shape properties
    property normal = y;
    property offset = 0;
    property triangles:triangle[] = null; // Might be much more than an
array of 'triangles'
    property inside_vector = null;
    property hierarchy = on;

    // Methods
    tomesh() {return this}
    tomesh2() {...}  // mesh->mesh2 conversion

    merge(msh:mesh) {...} // Merge a mesh to this one
}
// ----------------------------------------------------------------------


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.