View Full Version : Adding Objects
barcombpictures 12-12-2007, 12:54 AM I am new to COFFEE and want to create a code which, when triggered, will add a light to any new object i add to the scene. I have been searching the internet and havent been able to find anything that is helpful. I just need to know the basics and have a reference of what is accepted by COFFEE. If anyone can tell me where to look or give me some code, that would be great.
thanks
|
|
tcastudios
12-12-2007, 07:52 PM
To get the basics what is possible, go to www.plugincafe.com and dload the
COFFEE SDK. The latest is R9.5.
Have a look at "Changes" and see the "AllocObject()" link.
Otherwise your description is a little bit unclear what you are trying to do.
Adding a object is pretty straight forward. The q is when, how, under what circumstances
as well as how much control of the adding process is needed.
Cheers
Lennart
barcombpictures
12-12-2007, 08:02 PM
Well, I am trying to create a plugin to create a light at the center of any new object i add to the scene. I want to do this as a global illumination work around. The main goal is to have any object also be a light emitter so i can simulate the diffusion of light off objects.
Another thing i want to eventually be able to do with this is to have a material be able to emit light and set up some math to assign its intensity based on various factors, like its distance from the light, etc. But i cannot find a good place to find out about the scripting style and language, about what needs to go where. I dloaded the most recent SDK and it's been little help. And I looked at c4dcafe and saw only one tutorial about the script manager. Ive been able to setup some simple 'Set' commands for rotation and position but not much else.
tcastudios
12-12-2007, 08:22 PM
Start with the first, easier part, creating a Object and light.
Look thru the available scripts here at the nearby Script resources thread.
There you'll find the syntax (very much the same as COFFEE) for specific tasks.
A Script is more or less a MenuPlugin. Read thru the COFFEE SDK to be able to search in it.
The fast lane into making your script into a MenuPlugin is to get the brand new and highly recommended COFFEE Book (pdf) by Ruimac at http://www.ruimac.com/coffee_book/
It takes the route from basic description all the way to a Menuplug with user settings.
Cheers
Lennart
Jorge Arango
12-12-2007, 09:06 PM
Another thing i want to eventually be able to do with this is to have a material be able to emit light and set up some math to assign its intensity based on various factors, like its distance from the light, etc.
I also recommend Rui's book but this part might be easier with xpresso.
Jorge Arango
tcastudios
12-12-2007, 11:42 PM
These two script examples will get you the basics.
Copy and paste each into two new scripts (ScriptManager ->New).
Cheers
Lennart
Example 1
// Add Light Example 1
// Add a light as child of a single selected object
// Only works if a single object is selected
// See example 2 for using several selected objects
var obj = doc->GetActiveObject(); // Do we have a selected object?
if(!obj) return; // Nothing is selected, nothing to do
var objm = obj->GetMg(); // Get the matrix of the selected object
var objname = obj->GetName(); // Get name of obj
doc->StartUndo(); // Start the Undo process
var light = AllocObject(Olight); // Create a Light object
//light#LIGHT_TYPE = 1; // Optionaly Set the light type to something specific, SpotLight etc.
light#ID_BASELIST_NAME = stradd(objname,"_Light");// Set a name based on obj
//light->SetName(stradd(objname,"_Light")); // another way to set a name based on obj
doc->AddUndo(UNDO_OBJECT_NEW,light);
light->InsertUnder(obj); // Insert the light as a child of obj
//doc->InsertObject(light,obj,NULL); // Another way of inserting the light
light->SetMg(objm); // Set the obj matrix into the light
doc->EndUndo(); // Done and regretable
Example 2
// Add Light Example 2
// Add a light as child of all selected objects
var doc = GetActiveDocument(); // Should be really since you are working in it,
if(!doc) return; // but better safe than sorry. More of a plugin issue
var obj = doc->GetFirstObject(); // We are scanning from first object in document
if(!obj) return; // No object in document, nothing to do
if(obj->GetBit(BIT_AOBJ)) obj=obj; // If first object is selected we start from it
else obj=obj->SearchNext(BIT_AOBJ); // else we search for the next selected
doc->StartUndo(); // Start the Undo process
var count = 1; // Start number for the naming process
while(obj) // For each selected object we scan we add a light....
{
var objm = obj->GetMg(); // Get the matrix of the selected object
var objname = obj->GetName(); // Get name of obj
var light = AllocObject(Olight); // Create a Light object
light#ID_BASELIST_NAME = stradd(objname,"_Light_",tostring(count));// Set a numbered name based on obj
doc->AddUndo(UNDO_OBJECT_NEW,light); // load the Undo cue
light->InsertUnder(obj); // Insert the light as a child of obj
light->SetMg(objm); // Set the obj matrix into the light
count++; // Increase the naming number
obj=obj->SearchNext(BIT_AOBJ); // Get next selected object as long as there is any
}
doc->EndUndo(); // Done and regretable
barcombpictures
12-12-2007, 11:49 PM
Thank you very much, those are very very helpful examples.
govinda
12-17-2007, 05:40 PM
I'm curious what the 'Done and Regrettable' line means in your code notes, Lennart. That's three times I've seen it. :) Is it a little coder's convention?
tcastudios
12-17-2007, 07:01 PM
Hehe.. It's maybe down to the fact that english is not my native language:)
Heck, it's not even spelt right, is it !?
So, it could mean: mission completed (Done) but if you didn't like it (regret)
it can be undone (UnDo) and no one would ever know it ever happened!
Cheers
Lennart
CGTalk Moderation
12-17-2007, 07:01 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.