Added lamp options export/import.
This commit is contained in:
@@ -184,7 +184,7 @@ void forEachCameraObjectInScene(Scene *sce, Functor &f)
|
||||
Object *ob = base->object;
|
||||
|
||||
if (ob->type == OB_CAMERA && ob->data) {
|
||||
f(ob);
|
||||
f(ob, sce);
|
||||
}
|
||||
base= base->next;
|
||||
}
|
||||
@@ -1561,29 +1561,29 @@ public:
|
||||
|
||||
closeLibrary();
|
||||
}
|
||||
void operator()(Object *ob)
|
||||
void operator()(Object *ob, Scene *sce)
|
||||
{
|
||||
// XXX add other params later
|
||||
Camera *cam = (Camera*)ob->data;
|
||||
std::string cam_name(id_name(ob));
|
||||
std::string cam_id(id_name(ob));
|
||||
char *name = cam->id.name;
|
||||
|
||||
if (cam->type == CAM_PERSP) {
|
||||
COLLADASW::PerspectiveOptic persp(mSW);
|
||||
persp.setXFov(1.0);
|
||||
//persp.setYFov(1.0);
|
||||
persp.setAspectRatio(1.0);
|
||||
persp.setAspectRatio(0.1);
|
||||
persp.setZFar(cam->clipend);
|
||||
persp.setZNear(cam->clipsta);
|
||||
COLLADASW::Camera ccam(mSW, &persp, cam_name);
|
||||
COLLADASW::Camera ccam(mSW, &persp, cam_id, name);
|
||||
addCamera(ccam);
|
||||
}
|
||||
else {
|
||||
COLLADASW::OrthographicOptic ortho(mSW);
|
||||
ortho.setXMag(1.0);
|
||||
//ortho.setYMag(1.0, true);
|
||||
ortho.setAspectRatio(1.0);
|
||||
ortho.setAspectRatio(0.1);
|
||||
ortho.setZFar(cam->clipend);
|
||||
ortho.setZNear(cam->clipsta);
|
||||
COLLADASW::Camera ccam(mSW, &ortho, cam_name);
|
||||
COLLADASW::Camera ccam(mSW, &ortho, cam_id, name);
|
||||
addCamera(ccam);
|
||||
}
|
||||
}
|
||||
@@ -1604,37 +1604,49 @@ public:
|
||||
void operator()(Object *ob)
|
||||
{
|
||||
Lamp *la = (Lamp*)ob->data;
|
||||
std::string la_name(id_name(ob));
|
||||
std::string la_id(id_name(ob));
|
||||
char *la_name = la->id.name;
|
||||
COLLADASW::Color col(la->r, la->g, la->b);
|
||||
float e = la->energy;
|
||||
|
||||
// sun
|
||||
if (la->type == LA_SUN) {
|
||||
COLLADASW::DirectionalLight cla(mSW, la_name, "", la->energy);
|
||||
COLLADASW::DirectionalLight cla(mSW, la_id, la_name, e);
|
||||
cla.setColor(col);
|
||||
addLight(cla);
|
||||
}
|
||||
// hemi
|
||||
else if (la->type == LA_HEMI) {
|
||||
COLLADASW::AmbientLight cla(mSW, la_name, "", la->energy);
|
||||
COLLADASW::AmbientLight cla(mSW, la_id, la_name, e);
|
||||
cla.setColor(col);
|
||||
addLight(cla);
|
||||
}
|
||||
// spot
|
||||
// XXX add other params later
|
||||
else if (la->type == LA_SPOT) {
|
||||
COLLADASW::SpotLight cla(mSW, la_name, "", la->energy);
|
||||
COLLADASW::SpotLight cla(mSW, la_id, la_name, e);
|
||||
cla.setColor(col);
|
||||
cla.setFallOffAngle(la->spotsize);
|
||||
cla.setLinearAttenuation(la->att1);
|
||||
cla.setQuadraticAttenuation(la->att2);
|
||||
addLight(cla);
|
||||
}
|
||||
// lamp
|
||||
else if (la->type != LA_AREA) {
|
||||
COLLADASW::PointLight cla(mSW, la_name, "", la->energy);
|
||||
else if (la->type == LA_LOCAL) {
|
||||
COLLADASW::PointLight cla(mSW, la_id, la_name, e);
|
||||
cla.setColor(col);
|
||||
cla.setLinearAttenuation(la->att1);
|
||||
cla.setQuadraticAttenuation(la->att2);
|
||||
addLight(cla);
|
||||
}
|
||||
// area lamp is not supported
|
||||
// it will be exported as a local lamp
|
||||
else {
|
||||
// XXX write error
|
||||
return;
|
||||
COLLADASW::PointLight cla(mSW, la_id, la_name, e);
|
||||
cla.setColor(col);
|
||||
cla.setLinearAttenuation(la->att1);
|
||||
cla.setQuadraticAttenuation(la->att2);
|
||||
addLight(cla);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1181,7 +1181,7 @@ private:
|
||||
for(int j = 0; j < vca.getCount(); j++){
|
||||
int count = vca[j];
|
||||
if (count < 3) {
|
||||
fprintf(stderr, "Primitive %s in %s has at least one face with vertex count < 3 or > 4\n",
|
||||
fprintf(stderr, "Primitive %s in %s has at least one face with vertex count < 3\n",
|
||||
type_str, name);
|
||||
return false;
|
||||
}
|
||||
@@ -2499,12 +2499,17 @@ public:
|
||||
@return The writer should return true, if writing succeeded, false otherwise.*/
|
||||
virtual bool writeCamera( const COLLADAFW::Camera* camera )
|
||||
{
|
||||
std::string name = camera->getOriginalId();
|
||||
Camera *cam = (Camera*)add_camera((char*)name.c_str());
|
||||
Camera *cam;
|
||||
std::string cam_id = camera->getOriginalId();
|
||||
std::string cam_name = camera->getName();
|
||||
if (cam_name.size()) cam = (Camera*)add_camera((char*)cam_name.c_str());
|
||||
else cam = (Camera*)add_camera((char*)cam_id.c_str());
|
||||
|
||||
if (!cam) {
|
||||
fprintf(stderr, "Cannot create camera. \n");
|
||||
return true;
|
||||
}
|
||||
|
||||
COLLADAFW::Camera::CameraType type = camera->getCameraType();
|
||||
switch(type) {
|
||||
case COLLADAFW::Camera::ORTHOGRAPHIC:
|
||||
@@ -2555,12 +2560,22 @@ public:
|
||||
@return The writer should return true, if writing succeeded, false otherwise.*/
|
||||
virtual bool writeLight( const COLLADAFW::Light* light )
|
||||
{
|
||||
std::string name = light->getOriginalId();
|
||||
Lamp *lamp = (Lamp*)add_lamp((char*)name.c_str());
|
||||
Lamp *lamp;
|
||||
std::string la_id = light->getOriginalId();
|
||||
std::string la_name = light->getName();
|
||||
if (la_name.size()) lamp = (Lamp*)add_lamp((char*)la_name.c_str());
|
||||
else lamp = (Lamp*)add_lamp((char*)la_id.c_str());
|
||||
|
||||
if (!lamp) {
|
||||
fprintf(stderr, "Cannot create lamp. \n");
|
||||
return true;
|
||||
}
|
||||
if (light->getColor().isValid()) {
|
||||
COLLADAFW::Color col = light->getColor();
|
||||
lamp->r = col.getRed();
|
||||
lamp->g = col.getGreen();
|
||||
lamp->b = col.getBlue();
|
||||
}
|
||||
COLLADAFW::Light::LightType type = light->getLightType();
|
||||
switch(type) {
|
||||
case COLLADAFW::Light::AMBIENT_LIGHT:
|
||||
@@ -2571,6 +2586,9 @@ public:
|
||||
case COLLADAFW::Light::SPOT_LIGHT:
|
||||
{
|
||||
lamp->type = LA_SPOT;
|
||||
lamp->att1 = light->getLinearAttenuation().getValue();
|
||||
lamp->att2 = light->getQuadraticAttenuation().getValue();
|
||||
lamp->spotsize = light->getFallOffAngle().getValue();
|
||||
}
|
||||
break;
|
||||
case COLLADAFW::Light::DIRECTIONAL_LIGHT:
|
||||
@@ -2580,7 +2598,9 @@ public:
|
||||
break;
|
||||
case COLLADAFW::Light::POINT_LIGHT:
|
||||
{
|
||||
lamp->type = LA_AREA;
|
||||
lamp->type = LA_LOCAL;
|
||||
lamp->att1 = light->getLinearAttenuation().getValue();
|
||||
lamp->att2 = light->getQuadraticAttenuation().getValue();
|
||||
}
|
||||
break;
|
||||
case COLLADAFW::Light::UNDEFINED:
|
||||
@@ -2592,8 +2612,6 @@ public:
|
||||
}
|
||||
|
||||
this->uid_lamp_map[light->getUniqueId()] = lamp;
|
||||
|
||||
// XXX import light options*/
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user