POV-Ray : Newsgroups : povray.binaries.programming : My idea: Developers need tips! Help me, please! : Re: My idea: Developers need tips! Help me, please! Server Time
7 May 2024 10:41:58 EDT (-0400)
  Re: My idea: Developers need tips! Help me, please!  
From: clipka
Date: 30 Oct 2016 17:09:36
Message: <58166190$1@news.povray.org>
Am 30.10.2016 um 11:16 schrieb LanuHum:
> "LanuHum" <Lan### [at] yandexru> wrote:
>> "LanuHum" <Lan### [at] yandexru> wrote:
>>
>>  6775:   CASE (OBJECT_TOKEN)
>>              Parse_Begin ();
>>              Object = Parse_Object ();
>>              if (!Object)
>>                  bool add = addBlenderObject(Token.Token_String);
>>              if (!add)
>>                  Expectation_Error ("object");
>>              Object = Parse_Object_Mods (reinterpret_cast<ObjectPtr>(Object));
>>              EXIT
>>          END_CASE

No, you probably do /not/ want to do it this way.

Parse_Object may fail not only if an IDENTIFIER_TOKEN (a valid but
undeclared identifier) is used; it may also fail on virtually any other
token, e.g. a string literal, numeric literal, operator, a reserved
keyword that does not normally start a primitive, or even a string variable.

In case of a string literal, you'll get the raw string without the
surrounding double quotes.
If you want that to be supported, for the sake of consistency you should
also allow arbitrary string expressions -- but those would /not/ give
you the string in Token.Token_String; instead, that would just give you
the first token of that string expresison (e.g. "concat(Foo,Bar)" would
give you "concat).

My personal recommendation would be to add another keyword, e.g.
"blender_object", write completely separate code to parse that, and use
a string rather than an identifier to specify the Blender-internal name:

    #declare Foo = blender_object { "foo" }

The code would be something like:

    char *s;
    ...
    CASE(BLENDER_OBJECT_TOKEN)
        Parse_Begin();
        s = Parse_C_String();
        Object = addBlenderObject(std::string(s));
        POV_FREE(s);
        Parse_End();
    END_CASE


> bool BlenderScene::addBlenderObject(std::string name){
>     BlenderObject *bobject = objects.find(name) -> second;
>     if (!bobject)
>         return false
>     switch (bobject -> type) {
>         case 2: {
>             Mesh *mesh = new Mesh();
>             // reinterpret Blender mesh data to Povray mesh data
>             // bla-bla-bla
>         }
>         case 1: { std::cout<<"Type: "<<"CSG"<<std::endl; break; } //del
>         default: { std::cout<<"Type: "<<"BLOB"<<std::endl; } //del
>     }
>     return true
> }

You /somehow/ want to pass the mesh/blob object out of this function.


Post a reply to this message

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