POV-Ray : Newsgroups : moray.win : SimCloth.lua plugin (Cloth simulation of MegaPov) : Re: SimCloth.lua plugin (Cloth simulation of MegaPov) Server Time
28 May 2024 21:25:31 EDT (-0400)
  Re: SimCloth.lua plugin (Cloth simulation of MegaPov)  
From: StephenS
Date: 23 Oct 2004 06:17:13
Message: <417a2fa9$1@news.povray.org>
> Hi Stephen,
>
> Could you provide more info about the error message? Maybe I can help you
> correct the bug.
Sorry for the confusion. The error message is from Pov-Ray. The solution was
also provided, use #undef first and then redefine. I was using a function
to contain Morays transformations, so I can apply them to the mesh being
created.
        pov:write("#declare Object_trans = transform{")
        pov:transforms(self.xforms)
        pov:write("  }")
...
Pov-Ray code
      #local f_Trans = function {transform {Object_trans}}
...
Pov-Ray code
      #local xtemp=f_Trans(tempx,tempy,tempz).x;
      #local ytemp=f_Trans(tempx,tempy,tempz).y;
      #local ztemp=f_Trans(tempx,tempy,tempz).z;
To correct the error I add this to the end of the output
        pov:write("#undef Object_trans")

> I took a look at SimCloth.lua and I have a couple of sugestions:
Suggestions are most welcome :-)

> 1) In methods listcloth, listsim and listUDO it'll be better to declare f
as
> a local variable instead of as a parameter (e.g. function
> SimCloth:listsim() local f="" ... return f end). Don't forget to remove
the
> parameter when you call those methods (e.g. self:listsim() instead of
> self:listsim(f))
At one time I was having problems creating and using Lua functions (basic
understanding). When I slowly started to get things to work I had this
format self:listsim(f), I've been afraid the change anything ever since :-)

> 2) You use dostring at some places to declare global variables (e.g.
> dostring("Distance="..self.core:povtolua(self.Clothvalue[1]))). Plugins
> should not use global variables since you never now if another plugin will
> use a global variable with the same name. It'll be better to rewrite those
> as
>
> local Distance=dostring(self.core:povtolua(self.Clothvalue[1]))
>
> You don't have to change code where those variables are used though.
>
> Regards,
>
> Andre de Leiradella
I wanted to be able to use a text string, so I could:
   enter simple math expressions, 3+1/16
   use some declared variables, that the Lua plugin will understand
(wireframe)
      Precision=2
      9*Precision
   simple pre-defined substitutions, Pov-Ray syntax to Lua syntax
      from 'degrees' (pov) to 'deg' (Lua)

The dostring() seemed to be the only way to solve this, and have the Lua
plugin understand the resulting number for use in wireframes.

Thank you for looking at the code and suggesting better ways of doing
things. I will start using both immediately.

Stephen


Post a reply to this message

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