COM Script Support

Updated 03/02/2001

 




Introduction

Since the first version of BS Contact the COM API was supported.

Documentation and sample programs can be found here.

In BS Contact 5.0 COM objects are now supported in the Script node. This can be used to implement custom nodes or complex computations in COM capable languages like C++ , Microsoft Java, Visual Basic.

Examples

NativeScript Demo

The script simply computes a sin wave elevation grid, a corresponding VRMLScript implementation is provided as well.

Download zip file with sources :NativeScriptDemo.zip

Run the Demo online. The plugin is installed using a Microsoft CAB file. This CAB is not signed, a real usage would install the plugin locally or would sign the CAB.

Run the demo.

 

Details

The class the CMyScript implements the blaxxunVRML Com Interface Script :

 

// Script interface methods 
    // we get the pointer to the owning Script node
    // inorder to get access to fields (and browser object)

    STDMETHOD(setContainer)(Node * container)
    {
        script = container;
        if (script) {

            // get any field pointers  needed 

            Field *tmp=NULL;

            // modify here : 
            script->getField( L"xDimension",&tmp);
            xDimension = tmp; RELEASE(tmp); 

        } else {
            // important zero pointers to clean up cyclic references
            xDimension.Release();
            fieldsAreOk = false;

        }
        return S_OK;
    }

    STDMETHOD(loadScriptObject)(BSTR urlData)
    {
        // 
        return E_NOTIMPL;
    }

    // initialize method (called after setContainer)
    STDMETHOD(initialize)()
    {

        // protect against bad , missing fields 
        if (!fieldsAreOk)
            return E_POINTER;

        xDimension->getValue(&xmax);
        return S_OK;

    }

    STDMETHOD(shutdown)()
    {
        // cleanup stuff done in initialize 
        return S_OK;
    }
    
    STDMETHOD(processEvent)(
        BSTR name, // name of eventIn function
        INT eventId, // ID, for speed, numbered by definition order (+3) for built-in fields
        EventOut * value,   // the value 
        DOUBLE timeStamp
        )
    {

        if (!fieldsAreOk)
            return E_POINTER;
        
        //TRACE("Got event %d \n",eventId);


        // assume the fraction eventIn function
        CComQIPtr fraction(value);

        if (!fraction)
            return E_POINTER;

        float fvalue;
        fraction->getValue(&fvalue);


        // now do something 

        int ioffset;
        // set the eventOut, triggering a ROUTE 
        heights->setValue(xmax*zmax,h);


        return S_OK;
    }

    STDMETHOD(eventsProcessed)()
    {
        // could do the work here, depending on whicht event has been changed
        return E_NOTIMPL;
    }