Creating Custom Classes

I'm sure there must be a way of creating custom classes, but I can't find an example anywhere. Let me show you what I need to do in order to get started.

The code below should construct two custom classes. The second is derived from the first.

// psudo code for a class constructorclass C_foo() : someDerived object{	var nVersion = 1.234;	fuction getVersion()	{		return nVersion;	}}// psudo code for a class constructorclass C_fooBar() : C_foo // derived from C_foo{	var sAuthor = "John Wayne";	fuction getAuthor()	{		return sAuthor;	}}

I need to learn the correct syntax for creating class objects, and what they need to derive from.

Any help will be tremendously appreciated.

 

Comments

  • Richard HaseltineRichard Haseltine Posts: 100,879

    Try looking at the DS 3 scripting docs - there is soem discussion there http://docs.daz3d.com/doku.php/public/software/dazstudio/3/start

  • rbtwhizrbtwhiz Posts: 2,250

    In my signaure you will find a link to the Scripting documentation. I would recommend reading the Summary section, followed by the Background section, followed by clicking the Identifiers link in the Language Reference section and reading the Reserved Words section on the linked page (noting specifically that "class" is reserved for future use), followed by clicking the Moving from QSA to Qt Script link down in the External Sources section and reading the The Scripting Language section on that page. This should provide you with the information you seek along with a brief glimpse into the history of the inevitable "why?" question that often follows.

    -Rob

  • PraxisPraxis Posts: 252
    rbtwhiz said:

    ...The Scripting Language section ...

    That reference in particular is Gold!  Thank you Rob.

    Here is the direct reference for convenience: https://doc.qt.io/archives/qt-4.8/porting-qsa.html

     

  • Thanks to everyone who responded. The help you gave me tonight allowed me to cook up this simple example of what I had in mind.

    // Construct a custom class derived from ObjectmyScene = new Object();// add a Scene object for convenient accessmyScene.scene = Scene;// add a variable placeholder for a cameramyScene.camera = null;// add a function for loading a cameramyScene.loadCamera = function(sCamera){	myScene.camera = myScene.scene.findCameraByLabel(sCamera);}// End of class implementation// using the myScene class, load a cameramyScene.loadCamera("Default Camera");// test the interface by retrieving the camera's focal lengthvar focalLength = myScene.camera.focalLength;// print resultprint(focalLength);

    Now that we have defined this class, we can create another class derived from myScene, as shown below.

    mySuperScene = myScene;// add a couple of propertiesmySuperScene.x = 12;mySuperScene.y = 35;// add a function to retrieve the sum of x + ymySuperScene.getLength = function(){	return mySuperScene.x + mySuperScene.y;}// End of mySuperClass implementation// varify that the interfaces workvar focalLength = myScene.camera.focalLength;print(focalLength);var nLength = mySuperScene.getLength();print( nLength.toString() );

    Once classes like these are fully implemented, you could save them to a script file and include it as a library module (see my previous thread on using Include statements).

    I believe there are lots of opportunities for building wrapper classes around DS objects, encapsulating a lot of low-level operations and exposing simple-to-use interfaces.

    Thanks for you help guys!

     

     

Sign In or Register to comment.