UV Mapping for Parametric Object

Why it is introduced

   Parametric object already operates on uv coordinates but for some reason this space is not available for mapping textures on it. Here is comparision what uv_mapping gives for simple twisted tape.

mapping comparision for parametric object
No UV Mapping Default UV Mapping UV Mapping follow UV coordinates
no uv_mapping default uv_mapping patched uv_mapping
#version 3.5;

#declare minor=3;
#declare major=9;
#declare rotor=5;
#declare Corner=(major*<1,1,0>)+minor;

  contained_by{box{-Corner Corner}}
  precompute 18,x,y,z
  pigment{checker rgb 0 rgb 1}
  translate 3*z*major

light_source{-9-9*z 1}
camera{up y right x}

How it is implemented

   Implementation was pretty easy. I can not worry about calculating UV coordinates becouse they are already calculated for normal method during intersection test. They are stored in fields of object. All I need was open file fpmetric.cpp and find definition of Parametric_Methods (Local variables section) and replace there Default_UVCoord with Parametric_UVCoord. Method Parametric_UVCoord has to be defined so in section Static functions we have to add line:

static void Parametric_UVCoord (UV_VECT Result, OBJECT *Object, INTERSECTION *Inter);

and add this function at end of file:

 *   Parametric_UVCoord
 *   As for all UVCoord methods object and interstcion structure
 *   As for all UVCoord methods 2D vector with UV coordinates
 *   ABX (abx@abx.art.pl)
 *   I'm not sure if last_u and last_v fields are safe place for storing
 *   uv coordinates but they are used for normal calculations. I hope
 *   tests will confirm it.
 *   2002.Aug.07 - initial version

static void Parametric_UVCoord(UV_VECT Result, OBJECT *Object, INTERSECTION *Inter)
        Result[U] = Par->last_u;
        Result[V] = Par->last_v;


   I'm not sure that storing UV coordinates in fields is safe and personaly I preffered storing on intersection stack as it was done in MegaPOV. But I'm sure this replacement was considered during bulding of 3.5 and I trust the POV-Team :-) (but see my notes in UV Mapping for Torus Object)


This is an unofficial addition to POV-Ray. Do not ask the POV-Team for help with this. Feel free to send all opinions, suggestions, corrections and thanks :-) connected with this site to me
Copyright 2002 by Wlodzimierz ABX Skiba

Valid HTML 4.01!   Valid CSS!   Bobby WorldWide Approved AAA
If a thing is worth doing, it is worth doing well.