вторник, 3 ноября 2015 г.

Figures draw figures

3D-Coat AngelScript
This post I wrote quickly. Quickly, because I wanted to understand what format is the best for examples. With each new post I will try to provide such format that will be most useful for you. Your feedback would be welcomed! In general, I want each example to not only show the principles of scripting in 3D-Coat, but also show a proper method for working with AngelScript (the AngelScript is used in many areas – so it might be helpful). Thus, from my posts there will be a kind of “set of blanks” which you could use in your workflow or just for fun.

What is going on here

  • Making unusual structure using 3D-Coat's scripts. In other words, a 3D-plot. You can change function and restart script to get something more interesting.

What can we learn from the code

  • How to clear the scene?
  • How to toggle Voxels / Surface mode?
  • How to create a 3D-model (mesh)?
  • How to add a sphere to a separate layer?
  • How to place object to a certain location with defined coordinates?
  • How to create 3D-plots?
  • How to use `for-cycles`?
  • What math functions are represented in AngelScript?

Code (3DCoat, AngelScript)

void main() {

    // preparing a scene
    SculptRoom  room;
    room.clear().toSurface();

    // building some structure with spheres
    Builder  builder;
    const int  IU = 4;
    const int  ITHETA = 3;
    const float  S = 5.0;
    const float  PI = 3.14159;
    for ( int iu = -IU; iu <= IU; ++iu ) {
        for ( int itheta = 0; itheta <= ITHETA; ++itheta ) {
            const float  u = 1.0 * iu / IU;
            const float  theta = 2.0 * PI * itheta / ITHETA;
            const float  x = sqrt( 1.0 - u * u ) * cos( theta );
            const float  y = sqrt( 1.0 - u * u ) * sin( theta );
            const float  z = u;
            const float  radius = (itheta + u * u) * S + 1;
            const Vec3  coord = Vec3( x, y, z ) * radius * 1.7 * S;
            const Mesh  figure = builder.sphere()
              .radius( radius )
              .position( coord )
              .details( 0.1 )
              ();
            room |= figure;
        } // itheta
    } // iu
}

Result



Your questions?

Комментариев нет: