POV-Ray : Newsgroups : povray.general : [3.8] Forward And Backward Reaching Inverse Kinematics Server Time
29 Mar 2024 08:49:10 EDT (-0400)
  [3.8] Forward And Backward Reaching Inverse Kinematics (Message 4 to 13 of 13)  
<<< Previous 3 Messages Goto Initial 10 Messages
From: ingo
Subject: Re: [3.8] Forward And Backward Reaching Inverse Kinematics
Date: 1 Dec 2018 13:37:11
Message: <XnsA9ABC79532498seed7@news.povray.org>
in news:5c02c8d1@news.povray.org Stephen wrote:

> On 01/12/2018 16:18, ingo wrote:
>> // Forward And Backward Reaching Inverse Kinematics (FABRIK) by
>> Andreas Aristidou.
>> //http://www.andreasaristidou.com/FABRIK.html
> 
> Very interesting. I also took a look at your you tube channel with
> the motion capture.

Not my channel Stephen, I just stumbled over Andreas' work yesterday and 
implemented it in POV-Ray (peeking a lot at other code), well, just a part 
of it for now.

Cheers,

ingo


Post a reply to this message

From: Stephen
Subject: Re: [3.8] Forward And Backward Reaching Inverse Kinematics
Date: 1 Dec 2018 23:51:52
Message: <5c0364e8$1@news.povray.org>
On 01/12/2018 18:37, ingo wrote:
> in news:5c02c8d1@news.povray.org Stephen wrote:
> 
>> On 01/12/2018 16:18, ingo wrote:
>>> // Forward And Backward Reaching Inverse Kinematics (FABRIK) by
>>> Andreas Aristidou.
>>> //http://www.andreasaristidou.com/FABRIK.html
>>
>> Very interesting. I also took a look at your you tube channel with
>> the motion capture.
> 
> Not my channel Stephen, I just stumbled over Andreas' work yesterday and
> implemented it in POV-Ray (peeking a lot at other code), well, just a part
> of it for now.
> 

My oops then. :)
Good luck with your IK project.


-- 

Regards
     Stephen


Post a reply to this message

From: And
Subject: Re: [3.8] Forward And Backward Reaching Inverse Kinematics
Date: 2 Dec 2018 05:55:00
Message: <web.5c03b9b475ee21eb25503a850@news.povray.org>
ingo <ing### [at] tagpovrayorg> wrote:
> in news:5c02c8d1@news.povray.org Stephen wrote:
>
> > On 01/12/2018 16:18, ingo wrote:
> >> // Forward And Backward Reaching Inverse Kinematics (FABRIK) by
> >> Andreas Aristidou.
> >> //http://www.andreasaristidou.com/FABRIK.html
> >
> > Very interesting. I also took a look at your you tube channel with
> > the motion capture.
>


interest


Post a reply to this message

From: ingo
Subject: Re: [3.8] Forward And Backward Reaching Inverse Kinematics
Date: 5 Dec 2018 03:49:16
Message: <XnsA9AF63E8912FBseed7@news.povray.org>
Another update. Before implementing more complex structures, I made it 
possible to solve multiple independen IK's with one Fabrik 'object'

ingo

----%<----%<----%<----%<----%<----
//==
// Pov-Ray   : 3.8
// Scene File: FABRIK.inc
// Author    : Ingo Janssen
// Date      : 01-12-2018
// Rev Date  : 05-12-2018
// Version   : 1a2
//--
// Forward And Backward Reaching Inverse Kinematics (FABRIK) by Andreas 
Aristidou.
// http://www.andreasaristidou.com/FABRIK.html
// http://www.andreasaristidou.com/publications/papers/FABRIK.pdf
// 
http://www.andreasaristidou.com/publications/papers/Extending_FABRIK_wit
h_Model_C%CE%BFnstraints.pdf
// Excellent code inspiration & guide, by unknown author:
// https://developer.roblox.com/articles/Inverse-Kinematics-for-
Animation#FABRIK
// 

#version 3.8;

//==
// macros starting with an underscore should not be called 'from the 
outside'.
// only chains mentioned in the process dictionary will be initialised
// absence of the process dictionary will result in an error
//
// The FABRIK macro needs a rather complex datastructure as input, to be 
explained later.
// Create an 'instance' of the Fabrik 'object': #declare S = FABRIK(F); 
where F is the 
// datastructure. Fabrik 'returns' an updated/initialised version of the 
input structure. 
// 
// To run the IK solver use SetTarget(S, T) where S is the afore 
mentioned insatance of 
// Fabrik and T a datastructure holding the target(s)
//
#macro FABRIK(self)
  #ifndef (self.Proc)
    #error "\nNo Process 'Proc' dictionary defined\n"
  #end
  
  // add FABRIK global defaults, they can be overridden by adding a 
Default
  // dictionary to a Chain dictionary. The Chain dict is checked first 
for
  // these values, if not available the 'global' ones are used. 
  #local self.Default = dictionary {
    ["Tolerance"] : 0.1,
    ["MaxIter"] : 100
  }
  
  #macro _Init(self)
    #macro _Lengths(self, Chain)
      #local self[Chain]._Lengths = array[self[Chain]._N-1];
      #local self[Chain]._Length = 0;
      #local i = 0;
      #while (i < (self[Chain]._N-1))
        #local self[Chain]._Lengths[i] = vlength(self[Chain].Joint[i]-
self[Chain].Joint[i+1]);
        #local self[Chain]._Length = self[Chain]._Length + self[Chain].
_Lengths[i];
        #local i = i + 1; 
      #end
    #end
    
    #for (i,0,dimension_size(self.Proc,1)-1,1)
      #ifdef (self[self.Proc[i]].Joint)
        #local Chain = self.Proc[i];
        #debug concat("init chain : ", Chain, "\n")
        #local self[Chain]._O = self[Chain].Joint[0];
        #local self[Chain]._N = dimension_size(self[Chain].Joint, 1);
        #local self[Chain]._M = self[Chain]._N-1; //max index of array
        _Lengths(self, Chain)
      #end
    #end
  #end
  _Init(self)

  // internals  
  #macro _Reach(self, Chain) //SimpleSolver & EndPoint
    #debug "Reach : "
    #if (vlength(self[Chain]._O - self[Chain].Target) > self[Chain].
_Length)
      #local self[Chain]._Reachable = false;
      #debug "False\n"
    #else
      #local self[Chain]._Reachable = true;
      #debug "True\n"
    #end
  #end

  #macro _Backwards(self, Chain)
    #debug "  Backwards :\n"
    #local self[Chain].Joint[self[Chain]._M] = self[Chain].Target;
    #for (i, self[Chain]._M-1, 0, -1)
      #local l = self[Chain]._Lengths[i]/vlength(self[Chain].Joint[i+1]-
self[Chain].Joint[i]);
      #local Pos =  (1-l) * self[Chain].Joint[i+1] + l * self
[Chain].Joint[i];
      //if constraint
      //check constraint
      //if not within constraint adjust Pos
      //2B done
      #local self[Chain].Joint[i] = Pos;
      #debug concat("    i : ",str(i,0,0)," pos : ", vstr
(3,Pos,",",0,3),"\n")
    #end
  #end

  #macro _Forward(self, Chain)
    #debug "  Forward :\n"
    // set first point back to its original position
    #local self[Chain].Joint[0] = self[Chain]._O; 
    #for (i, 0, self[Chain]._M-1, 1)
      #local l = self[Chain]._Lengths[i]/vlength(self[Chain].Joint[i+1]-
self[Chain].Joint[i]);
      #local Pos =  (1-l) * self[Chain].Joint[i] + l * self[Chain].Joint
[i+1];
      //if constraint
      //check constraint
      //if not within constraint adjust Pos
      //2B done
      #local self[Chain].Joint[i+1] = Pos;
      #debug concat("    i : ",str(i,0,0)," pos : ", vstr
(3,Pos,",",0,3),"\n")
    #end
  #end

  #macro _Stretch(self, Chain)
    #debug "Stretch :\n"
    #for (i, 0, self[Chain]._M-1, 1)
      #local l = self[Chain]._Lengths[i]/vlength(self[Chain].Target-self
[Chain].Joint[i]);  
      #local self[Chain].Joint[i+1] = (1-l) * self[Chain].Joint[i] + l * 
self[Chain].Target;
      #debug concat("i : ",str(i,0,0), " pos : ", vstr(3,self
[Chain].Joint[i+1],",",0,3),"\n")
    #end
  #end

  #macro _SolveSimple(self, Chain)
    #debug "Solving :\n"
    #if (self[Chain]._Reachable = false)
      _Stretch(self, Chain)
    #else
      #local itercount = 0;
      #local dif = vlength(self[Chain].Joint[self[Chain]._M] - self
[Chain].Target); 
      #while (dif > self.Default.Tolerance)  //2B done also check chain 
local defaults
        #debug concat("  dif : ",str(dif,0,3)," iter : ",str
(itercount,0,0),"\n")         
        _Backwards(self, Chain)
        _Forward(self, Chain)
        #local dif = vlength(self[Chain].Joint[self[Chain]._M] - self
[Chain].Target);
        #local itercount = itercount + 1;
        #if (itercount > self.Default.MaxIter)//2B done also check chain 
local defaults
          #local dif = 0;
        #end
      #end
      #debug concat("\n  dif : ",str(dif,0,3)," end iter\n\n")         
    #end
  #end 

  // external
  #macro SetTarget (self, T)
    #for (i, 0, dimension_size(T.Index,1)-1,1)
      #local Chain = T.Index[i];
      #debug concat("set target : ", Chain, "\n")
      #local self[Chain].Target = T[Chain];
      _Reach(self, T.Index[i])
      _SolveSimple(self, T.Index[i])
    #end
  #end

  self
#end


/*test scene*/

#global_settings{assumed_gamma 1.0 }
#default{pigment{rgb 1} finish{ ambient 0.2 diffuse 0.9 }} 
light_source{<1000,1000,-1000>, rgb 1}
//plane{-z,0 pigment{checker rgb 0.8 rgb 0.5}}
camera{location <0,0,-8> look_at <0,0,0>}


// Two 'independent' chains
#declare F = dictionary{
  ["Proc"]: array[2]{"Base1", "Base2"},
  ["Base1"]   : dictionary {
      ["Joint"] : array[6]{<0,0,0>, < 0,1,0>, < 0,2,0>, < 0,3,0>, 
<0,4,0>, <0,5,0>},
  }
  ["Base2"]   : dictionary {
      ["Joint"] : array[6]{<0,0,0>, < 0,1,0>, < 0,2,0>, < 0,3,0>, 
<0,4,0>, <0,5,0>},
  }
};
#declare S = FABRIK(F);


#declare T = dictionary {
  ["Index"] : array[2]{"Base1", "Base2"},
  ["Base1"] : <4,0,0>,
  ["Base2"] : <-4,0,0>
}
SetTarget(S, T)

#for (i,0,dimension_size(S.Proc,1)-1,1)
  #ifdef (S[S.Proc[i]].Joint)
    #local Chain = S.Proc[i];
    #for (n,0,S[Chain]._M-1,1)    
      sphere{S[Chain].Joint[n], 0.2}
      cylinder{S[Chain].Joint[n],S[Chain].Joint[n+1],0.2}
    #end
    sphere{S[Chain].Joint[n], 0.2 pigment{rgb x}} //end points
  #end 
#end


Post a reply to this message

From: ingo
Subject: Re: [3.8] Forward And Backward Reaching Inverse Kinematics
Date: 10 Dec 2018 10:38:04
Message: <XnsA9B4A9371664Eseed7@news.povray.org>
Added an updated version in p.b.scene-files FABRIK IK
<XnsA9B4A7C06381seed7@news.povray.org>
http://news.povray.org/povray.binaries.scene-files/thread/%
3CXnsA9B4A7C06381seed7%40news.povray.org%3E/

Still needs a lot of work but the basics do work.

I have an implementation for moving other nodes than the end nodes but 
it's complicated to integrate. I have an implementation for movement 
restriction, simplified from what is in the paper. Closed loops is one I 
havn't looked at yet. 

Specifying the whole FABRIC dictionary as it is now is tedious and will be 
simplified. Most of the data there can be derived during initialisation,

ingo


Post a reply to this message

From: ingo
Subject: Re: [3.8] Forward And Backward Reaching Inverse Kinematics
Date: 19 Dec 2018 13:51:12
Message: <XnsA9BDC9F61A606seed7@news.povray.org>
in news:XnsA9AB7C841FAFAseed7@news.povray.org ingo wrote:

> So here's 
> my first attempt at the most basic version.

Several more attempts followed. I put the code in a Fossil at
https://chiselapp.com/user/ingo/repository/POV-Ray-FABRIK/home
It runs smoothly now. Updated the interface to the macro to make it easier 
to experiment. All still not well documented. 

Next will be the addition of movement constraints.

ingo


Post a reply to this message

From: jr
Subject: Re: [3.8] Forward And Backward Reaching Inverse Kinematics
Date: 19 Dec 2018 18:55:01
Message: <web.5c1ad94775ee21eb48892b50@news.povray.org>
hi,

ingo <ing### [at] tagpovrayorg> wrote:
> ... I put the code in a Fossil at
> https://chiselapp.com/user/ingo/repository/POV-Ray-FABRIK/home

thanks, downloaded.

> It runs smoothly now. Updated the interface to the macro to make it easier
> to experiment. All still not well documented.
>
> Next will be the addition of movement constraints.

looking forward to more playing.  :-)

also, a "feature request": during initialisation, a means to enable or disable
the debug output for that scene would be handy.


regards, jr.


Post a reply to this message

From: ingo
Subject: Re: [3.8] Forward And Backward Reaching Inverse Kinematics
Date: 20 Dec 2018 01:21:12
Message: <XnsA9BE4ACD8D591seed7@news.povray.org>
in news:web.5c1ad94775ee21eb48892b50@news.povray.org jr wrote:

> a means to enable or disable
> the debug output for that scene would be handy

Yep. Working on that already, I have a macro for setting various debug 
levels so I can target specific parts of the code, but not integrated in 
fabrik yet.

ingo


Post a reply to this message

From: ingo
Subject: Re: [3.8] Forward And Backward Reaching Inverse Kinematics
Date: 20 Dec 2018 05:34:04
Message: <XnsA9BE75AE28767seed7@news.povray.org>
in news:web.5c1ad94775ee21eb48892b50@news.povray.org jr wrote:

> enable or disable
> the debug output

Done. Download the latest Leaf at
https://chiselapp.com/user/ingo/repository/POV-Ray-
FABRIK/info/96d889a5b57f1d1b

Afther initialising FABRIK, set the LogLevel.
0 = silence higher number is more chatty. Currently three levels are 
defined within FABRIK. 1 = default.

#declare S = FABRIK();
#declare S.LogLevel=5;

Cheers,

ingo


Post a reply to this message

From: jr
Subject: Re: [3.8] Forward And Backward Reaching Inverse Kinematics
Date: 20 Dec 2018 16:45:01
Message: <web.5c1c0cc375ee21eb48892b50@news.povray.org>
hi,

ingo <ing### [at] tagpovrayorg> wrote:
> in news:web.5c1ad94775ee21eb48892b50@news.povray.org jr wrote:
> > enable or disable
> > the debug output
>
> Done. Download the latest Leaf at
> https://chiselapp.com/user/ingo/repository/POV-Ray-
> FABRIK/info/96d889a5b57f1d1b
>
> Afther initialising FABRIK, set the LogLevel.
> 0 = silence higher number is more chatty. Currently three levels are
> defined within FABRIK. 1 = default.
>
> #declare S = FABRIK();
> #declare S.LogLevel=5;

v cool.  will get this later.


regards, jr.


Post a reply to this message

<<< Previous 3 Messages Goto Initial 10 Messages

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