[Fluxus] load-primitive vs recalc-normals

David Griffiths dave at pawfal.org
Wed May 4 11:24:00 PDT 2011


Hi Kassen,

The OBJ model format is indexed, so when you save a primitive and load
it back in it converts it to indexed mode. It's not really possible (or
quite "non-trivial") to convert them back into straight arrays again.

Once you have an indexed mode primitive it becomes ambiguous how to
smooth normals, as they may be shared by many different faces.

Sorry if this is a bad explanation, will try better if needed.

cheers,

dave

On Wed, 2011-05-04 at 02:03 +0200, Kassen wrote:
> Dear List,
> 
> 
> When I save a primitive as a .obj file in fluxus, then load this and
> try to use (recalc-normals ) on the result I only get angular results.
> This seems regardless of the setting of either the parameter to
> (recalc-normals ) on the resulting primitive or the original amount of
> smoothing on the saved one. I believe this to be a bug. I'll post
> versions of my code for reference below.
> 
> 
> Yours,
> Kas.
> 
> 
> ;----------------------in.scm-----------------------------------------------------------
> ;saves a range of shapes from "pebble" to "brick", crude version
> (clear)
> 
> 
> (define (build-stone size amount)
>     (letrec ((clamp (λ (x y) ((if (positive? x)+ -) x (* y (- 1
>  (magnitude x)))) )))
>             (let ((stone (build-icosphere 2)))
>                 (with-primitive stone
>                     (pdata-map!
>                         (λ (position)
>                             (let (  (ult (biggest position))
>                                     (px (vector-ref position 0))
>                                     (py (vector-ref position 1))
>                                     (pz (vector-ref position 2)))
>                                 (vector
>                                     (if (eq? ult 0) (clamp px amount)
> (clamp px (min amount (magnitude px))))
>                                     (if (eq? ult 1) (clamp py amount)
> (clamp py (min amount (magnitude py))))
>                                     (if (eq? ult 2) (clamp pz amount)
> (clamp pz (min amount (magnitude pz)))))))
>                         "p")
>                     (scale size)
>                     (colour .5)
>                     (recalc-normals 1)
>                     (hint-normalise))
>                 stone)))
> 
> 
> (for ((x (in-range 0 10)))
>         (with-primitive (build-stone (vector 1 1 1) (* x .1))
>             (save-primitive (string-append "brick" (number->string x)
> ".obj"))))
>         
> 
> 
> 
> 
> ;---------------------------------------out.scm--------------------------------
> (clear)
> 
> 
> (define test (load-primitive "/bricks/brick2.obj"))
> 
> 
> (with-primitive test
>     (colour .5)
>     (recalc-normals 1))





More information about the Fluxus mailing list