Cannot create polygon & primitive object



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 01/08/2003 at 07:51, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   8.100 
    Platform:   Windows  ;   
    Language(s) :   C.O.F.F.E.E  ;

    ---------
    Hello,
    I want to develop a coffee plugin to read in polygon data and
    primitive data generated elsewhere. I succeeded in creating
    a polygon object with a phong tag, but I can neither
    set a point array nor a polygon array for the polygon object.
    Look at the code below which I placed in a file named
    GenerateMyModel.cof in the Plugins folder of CINEMA_4D_R8.
    The commands
    var rc = polygonObj->SetPoints(ptarr);
    var rc = polygonObj->SetPolygons(pgarr);   
    both return false, what's wrong here ?
    The command
    var rc=polygonObj->SetPoint(0, pt);
    also returns false !
    I cannot generate a primitve object neither, look at
    the command
    var cube = new(PrimitiveObject);
    println("var cube = ", cube);
    Variable cube is nil, what's the problem here ?
    Thanks for any help !
    Chris Bucher

    CODE
    // -------------------------------------------------------------------------
    // Base of this program is the example MPControl.cof from MenuPlugin
    // in 1.4 - Plugin Types description / Ch. Bucher 31.7.03
    // -------------------------------------------------------------------------
    // This plugin ceates model data whenever executed

    class GenerateMyModel : MenuPlugin
    {
     public:
      GenerateMyModel();
      GetID();
      GetName();
      GetState();
      
      GetHelp();
      Execute(doc);
    }
    GenerateMyModel::GenerateMyModel()
    {
     super();
    }
    GenerateMyModel::GetID()
    {
     return 1001150;
    }
    GenerateMyModel::GetState()
    {
     var doc = GetActiveDocument(); if (!doc) return 0;
     return CMD_ENABLED|CMD_CHECKED;
    }
    GenerateMyModel::GetName()
    {
     return "GenerateMyModel";
    }
    GenerateMyModel::GetHelp()
    {
     return "Generates C4D-Model from Computed Geometry";
    }

    GenerateMyModel::Execute(doc)
    {
     println("GenerateMyModel executed ...");
     // var str = new(string, 5);
     // str="aBcDeFgHi";
     // println("var str = ", str);
     var polygonObj = new(PolygonObject);
     println("var polygonObj = ", polygonObj);
     var ptarr = polygonObj->GetPoints();
     println("ptarr of polygonObj->GetPoints=", ptarr);
     // define point array as array of vectors
     var pt = vector(0);
     println("pt.x=", pt.x, "  pt.y=", pt.y, "  pt.z=", pt.z);
     var ptarr = new(array,6);
     pt.x=0; pt.y=0; ptarr[0] =  pt;
     var rc=polygonObj->SetPoint(0, pt);
     println("rc of polygonObj->SetPoint(0, pt)=", rc);
     println("GetPoint(0)=", polygonObj->GetPoint(0));
     println("pt.x=", pt.x, "  pt.y=", pt.y, "  pt.z=", pt.z);
     pt.x=0; pt.y=100; ptarr[1] =  pt; polygonObj->SetPoint(1, pt);
     println("pt.x=", pt.x, "  pt.y=", pt.y, "  pt.z=", pt.z);
     pt.x=100; pt.y=0; ptarr[2] =  pt; polygonObj->SetPoint(2, pt);
     println("pt.x=", pt.x, "  pt.y=", pt.y, "  pt.z=", pt.z);
     pt.x=100; pt.y=100; ptarr[3] =  pt; polygonObj->SetPoint(3, pt);
     println("pt.x=", pt.x, "  pt.y=", pt.y, "  pt.z=", pt.z);
     pt.x=200; pt.y=0; ptarr[4] =  pt; polygonObj->SetPoint(4, pt);
     println("pt.x=", pt.x, "  pt.y=", pt.y, "  pt.z=", pt.z);
     pt.x=200; pt.y=100; ptarr[5] =  pt; polygonObj->SetPoint(5, pt);
     println("pt.x=", pt.x, "  pt.y=", pt.y, "  pt.z=", pt.z);
     var i;
     for (i=0; i<6; i++)
      println("ptarr[i].x=", ptarr[i].x, "  ptarr[i].y=", ptarr[i].y, "  ptarr[i].z=", ptarr[i].z);

    var rc = polygonObj->SetPoints(ptarr);
     println("rc of polygonObj->SetPoints=", rc);
     // check if array set
     var cnt = polygonObj->GetPointCount();
     println("cnt=", cnt);
     var aa = polygonObj->GetPoints();
     var i;
     for (i=0; i<cnt; i++)
      println("aa[i].x=", aa[i].x, "  aa[i].y=", aa[i].y, "  aa[i].z=", aa[i].z);

    // var ptObj = new("PointObject");
     // var ptObjClass = PointObject;
     // var ptObj = new(ptObjClass);
     // println("var ptObj = ", ptObj);
     // ptObj->SetPoints(ptarr);
     // fill array with points of polygons
     var pgarr = new(array,8);
     // fill points of polygon 0
     var i=0;
     pgarr[i * 4 + 0] =  0;
     pgarr[i * 4 + 1] =  1;
     pgarr[i * 4 + 2] =  3;
     pgarr[i * 4 + 3] =  2;
        
     // fill points of polygon 1
     var i=1;
     pgarr[i * 4 + 0] =  2;
     pgarr[i * 4 + 1] =  3;
     pgarr[i * 4 + 2] =  5;
     pgarr[i * 4 + 3] =  4;
     var rc=polygonObj->SetPolygons(pgarr);   
     println("rc of polygonObj->SetPolygons=", rc);
     
     // create phong tag and attach to polygonObj
     var phongTag = new(PhongTag);
      println("var phongTag = ", phongTag);
     var bc = phongTag->GetContainer();
      println("phongTagContainer = ", bc);
     bc->SetData(PHONGTAG_PHONG, 1.396262222);
     var rc=phongTag->SetContainer(bc);
     println("rc of phongTag->SetContainer=", rc);
     
     var rc=polygonObj->InsertTag(phongTag, NULL);   
     println("rc of polygonObj->InsertTag=", rc);
     
     // --------------------------------------------------
     // pointObj - here error: member not found
     // (may be correct, since it may be an abstract class)
     // var pointObj = new(PointObject);
      // println("var pointObj = ", pointObj);
     var metaball = new(MetaballObject);
      println("var metaball = ", metaball);
     var cube = new(PrimitiveObject);
      println("var cube = ", cube);
     // Creates a cube that's 200x100x300
     // cube->SetPrimitiveType(PRIMITIVE_CUBE);
     // var bc = cube->GetContainer();
     // bc->SetData(PRIM_CUBE_LEN, vector(200, 100, 300));
     // cube->SetContainer(bc);
     var doc = GetActiveDocument(); if (!doc) {
      println("There is no active document"); return 0;
     }
     doc->InsertObject(polygonObj, NULL, NULL);
     doc->InsertObject(metaball , NULL, NULL);
     doc->MultiMessage(MSG_UPDATE); // has no effect
    }

    main()
    {
     Register(GenerateMyModel);
    }
    // ----------------------------------------------------
    /CODE



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 02/08/2003 at 06:52, xxxxxxxx wrote:

    Hi,
    1. in your polygonobject, are there any points or polygons? Otherwise setpoints for example logically won´t work.
    2. Primitive objects in R8 are created otherwise. Please search the SDK Questions forum.
    Best
    Samir



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 03/08/2003 at 14:33, xxxxxxxx wrote:

    Hi,
    1. As I understand it, one has to associate a point array and a a polygon array to the polygon object and this can be done with polygonObj->SetPoints(ptarr) and polygonObj->SetPoints(ptarr), respectively. But both calls do not work.
    2. Thanks for these hints ! I also read in the forum and noticed myself (!) that the coffee documentation (and probably coffee ?) isn't yet updated to R8 ....

    Thanks
    Chris



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 03/08/2003 at 15:12, xxxxxxxx wrote:

    1. As I understand it, one has to associate a point array and a a polygon array to the polygon object and this can be done with polygonObj->SetPoints(ptarr) and polygonObj->SetPoints(ptarr), respectively. But both calls do not work.
    Hi, no, you misunderstood that then. You will need to resize the polygonobject first and append points and polygons to the polygonobject. Otherwise the polygonobject is "empty" when created. point and polygonarrays are only pointers to positions (yes polygonarrays do contain polygons but those do only store point positions), so you will need to create either of them before you can set their positions.
    This is done for example via the VariableChanged class. Please have a look also here into the SDK :) Maybe you should also search the old plugincafe forum, where you will surely find much more information on this (and also on other topics). Here is the link to the old forum: www.plugincafe.com/forum_main.asp
    2. Thanks for these hints ! I also read in the forum and noticed myself (!) that the coffee documentation (and probably coffee ?) isn't yet updated to R8 ....

    Yes, that´s true. The documentation is not yet updated and coffee was only slightly adapted to work with R8 (i.e. the primitive objects).
    Hope that helped
    Best
    Samir



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 04/08/2003 at 13:44, xxxxxxxx wrote:

    Hi Samir
    Many thanks to your valuable hints, fast responses and assistance !
    Chris


Log in to reply