//------------------------------ LightObject* LightImporter::createSkyLight( const COLLADAFW::Light* light, const SkyLightParameters* skyLightParameters ) { void* lightMaxObject = createMaxObject(LIGHT_CLASS_ID, SKY_LIGHT_CLASS_ID); LightObject* skyLight = (LightObject*)lightMaxObject; IParamBlock2* skyLightParams = (IParamBlock2*) skyLight->GetReference(MaxLight::PBLOCK_REF_SKY); Point3 color = toMaxPoint3(light->getColor()); // param id documented in const Extra::ExtraParameter LightExporter::SKYLIGHT_PARAMETERS skyLightParams->SetValue(0, 0, color); skyLightParams->SetValue(1, 0, skyLightParameters->colorMapAmount); skyLightParams->SetValue(3, 0, skyLightParameters->colorMapOn); skyLightParams->SetValue(4, 0, skyLightParameters->raysPerSample); skyLightParams->SetValue(7, 0, skyLightParameters->mode); skyLightParams->SetValue(10, 0, skyLightParameters->multiplier); skyLightParams->SetValue(11, 0, skyLightParameters->rayBias); skyLightParams->SetValue(12, 0, skyLightParameters->castShadows); skyLightParams->SetValue(13, 0, skyLightParameters->intensityOn); return skyLight; }
int DirLight::Update(TimeValue t, const RendContext &rc, RenderGlobalContext *rgc, BOOL shadows, BOOL shadowGeomChanged) { int res = 1; BaseObjLight::Update(t,rc,rgc,shadows,shadowGeomChanged); hotsz = ls.hotsize; fallsz = ls.fallsize; fallsq = fallsz*fallsz; hotpct = ls.hotsize/ls.fallsize; ihotpct = 1.0f - hotpct; ObjectState os = inode->EvalWorldState(t); LightObject* lob = (LightObject *)os.obj; assert(os.obj->SuperClassID()==LIGHT_CLASS_ID); plRTDirLight* gl = (lob->GetInterface(I_MAXSCRIPTPLUGIN) != NULL) ? (plRTDirLight*)lob->GetReference(0) : (plRTDirLight*)lob; // JBW 4/7/99 //projector = gl->GetProjector(); aspect = 1.0f; //if (projector){ // projMap = gl->GetProjMap(); // if( projMap ) projMap->Update(t,FOREVER); // } return res; };
int SpotLight::Update(TimeValue t, const RendContext &rc, RenderGlobalContext *rgc, BOOL shadows, BOOL shadowGeomChanged) { int res = 1; BaseObjLight::Update(t,rc,rgc,shadows, shadowGeomChanged); float hs = DegToRad(ls.hotsize); float fs = DegToRad(ls.fallsize); fall_tan = (float)tan(fs/2.0f); hot_cos = (float)cos(hs/2.0f); fall_cos =(float)cos(fs/2.0f); fall_sin = (float)sin(fs/2.0f); hotpct = ls.hotsize/ls.fallsize; ihotpct = 1.0f - hotpct; ObjectState os = inode->EvalWorldState(t); LightObject* lob = (LightObject *)os.obj; assert(os.obj->SuperClassID()==LIGHT_CLASS_ID); plRTLightBase* gl = (lob->GetInterface(I_MAXSCRIPTPLUGIN) != NULL) ? (plRTLightBase*)lob->GetReference(0) : (plRTLightBase*)lob; // JBW 4/7/99 decayType = gl->GetDecayType(); decayRadius = gl->GetDecayRadius(t); projector = gl->GetProjector(); fov = std::max(fs, hs); float aspect = 1.0f; fov = 2.0f* (float)atan(tan(fov*0.5f)*sqrt(aspect)); zfac = -sz2 /(float)tan(0.5*(double)fov); xscale = zfac; yscale = -zfac*aspect; curve =(float)fabs(1.0f/xscale); rectv0.y = fall_sin * (float)sqrt(aspect); rectv1.y = fall_sin / (float)sqrt(aspect); rectv0.x = rectv1.x = fall_cos; rectv0 = Normalize(rectv0); rectv1 = Normalize(rectv1); Interval v; if (projector){ projMap = gl->GetProjMap(); if( projMap ) projMap->Update(t,v); } return res; }
int OmniLight::Update(TimeValue t, const RendContext & rc, RenderGlobalContext *rgc, BOOL shadows, BOOL shadowGeomChanged) { BaseObjLight::Update(t,rc,rgc,shadows,shadowGeomChanged); ObjectState os = inode->EvalWorldState(t); LightObject* lob = (LightObject *)os.obj; assert(os.obj->SuperClassID()==LIGHT_CLASS_ID); plRTOmniLight* gl = (lob->GetInterface(I_MAXSCRIPTPLUGIN) != NULL) ? (plRTOmniLight*)lob->GetReference(0) : (plRTOmniLight*)lob; // JBW 4/7/99 decayType = gl->GetDecayType(); decayRadius = gl->GetDecayRadius(t); fov = HALFPI; // 90 degree fov int res=1; if(gl->GetTex()) gl->GetTex()->Update(t, FOREVER); //projector = gl->GetProjector(); //if (projector){ // projMap = gl->GetProjMap(); // if( projMap ) projMap->Update(t,FOREVER); //} return res; }
//--------------------------------------------------------------- void LightExporter::exportLight( ExportNode* exportNode ) { if ( !exportNode->getIsInVisualScene() ) return; String lightId = getLightId(*exportNode); INode * iNode = exportNode->getINode(); LightObject* lightObject = (LightObject*) (iNode->GetObjectRef()); if ( !lightObject ) return; if ( mDocumentExporter->isExportedObject(ObjectIdentifier(lightObject)) ) return; mDocumentExporter->insertExportedObject(ObjectIdentifier(lightObject), exportNode); // Retrieve the target node, if we are not baking matrices. // Baked matrices must always sample the transform! ULONG ClassId = lightObject->ClassID().PartA(); bool isTargeted = !mDocumentExporter->getOptions().getBakeMatrices() && (ClassId == SPOT_LIGHT_CLASS_ID || ClassId == TDIR_LIGHT_CLASS_ID); INode* targetNode = isTargeted ? iNode->GetTarget() : 0; // some lights are not supported at all switch (ClassId) { case FSPOT_LIGHT_CLASS_ID: case SPOT_LIGHT_CLASS_ID: case DIR_LIGHT_CLASS_ID: case TDIR_LIGHT_CLASS_ID: case SKY_LIGHT_CLASS_ID_PART_A: case OMNI_LIGHT_CLASS_ID: break; default: return; } // Determine the light's type bool isSpot = false; bool isDirectional = false; bool isPoint = false; bool isSky = false; COLLADASW::Light::LightType lightType; switch (ClassId) { case FSPOT_LIGHT_CLASS_ID: case SPOT_LIGHT_CLASS_ID: lightType = COLLADASW::Light::SPOT; isSpot = true; break; case DIR_LIGHT_CLASS_ID: case TDIR_LIGHT_CLASS_ID: lightType = COLLADASW::Light::DIRECTIONAL; isDirectional = true; break; case SKY_LIGHT_CLASS_ID_PART_A: lightType = COLLADASW::Light::POINT; isSky = true; break; case OMNI_LIGHT_CLASS_ID: lightType = COLLADASW::Light::POINT; isPoint = true; break; } COLLADASW::Light * colladaLight = 0; switch ( lightType ) { case COLLADASW::Light::DIRECTIONAL: colladaLight = new COLLADASW::DirectionalLight(COLLADASW::LibraryLights::mSW, lightId, COLLADASW::Utils::checkNCName(NativeString(exportNode->getINode()->GetName()))); break; case COLLADASW::Light::POINT: colladaLight = new COLLADASW::PointLight(COLLADASW::LibraryLights::mSW, lightId, COLLADASW::Utils::checkNCName(NativeString(exportNode->getINode()->GetName()))); break; case COLLADASW::Light::SPOT: colladaLight = new COLLADASW::SpotLight(COLLADASW::LibraryLights::mSW, lightId, COLLADASW::Utils::checkNCName(NativeString(exportNode->getINode()->GetName()))); break; } // Retrieve the parameter block IParamBlock* parameters = 0; IParamBlock2* parametersSky = 0; if (isSky) parametersSky = (IParamBlock2*) lightObject->GetReference(MaxLight::PBLOCK_REF_SKY); else parameters = (IParamBlock*) lightObject->GetReference(MaxLight::PBLOCK_REF); if (!parameters && !parametersSky) { delete colladaLight; return; } if (parameters) { bool hasAnimatedColor = mAnimationExporter->addAnimatedParameter(parameters, MaxLight::PB_COLOR, lightId, colladaLight->getColorDefaultSid(), 0 ); colladaLight->setColor(EffectExporter::maxColor2Color(parameters->GetColor(MaxLight::PB_COLOR)), hasAnimatedColor); } else if (parametersSky ) { bool hasAnimatedColor = mAnimationExporter->addAnimatedParameter(parametersSky, MaxLight::PB_SKY_COLOR, lightId, colladaLight->getColorDefaultSid(), 0 ); colladaLight->setColor(EffectExporter::maxColor2Color(parametersSky->GetColor(MaxLight::PB_SKY_COLOR)), hasAnimatedColor); } if (isSpot || isPoint) { int decayFunction = parameters->GetInt(isPoint ? MaxLight::PB_DECAY : MaxLight::PB_OMNIDECAY, mDocumentExporter->getOptions().getAnimationStart()); switch (decayFunction) { case 1: colladaLight->setConstantAttenuation(0.0f); colladaLight->setLinearAttenuation(1.0f); break; case 2: colladaLight->setConstantAttenuation(0.0f); colladaLight->setQuadraticAttenuation(1.0f); break; case 0: default: colladaLight->setConstantAttenuation(1.0f); break; } } else if (isSky) { colladaLight->setConstantAttenuation(1.0f); } setExtraTechnique(colladaLight); if ( parameters ) addParamBlockAnimatedExtraParameters(LIGHT_ELEMENT, LIGHT_PARAMETERS, LIGHT_PARAMETER_COUNT, parameters, lightId); else addParamBlockAnimatedExtraParameters(SKYLIGHT_ELEMENT, SKYLIGHT_PARAMETERS, SKYLIGHT_PARAMETER_COUNT, parametersSky, lightId); // add all the information to extra tag, that are not contained in IParamBlock if (isSpot || isDirectional || isPoint) { GenLight* light = (GenLight*)(lightObject); if (!light) { delete colladaLight; return; } // Export the overshoot flag for directional lights if (isDirectional || isSpot) { addExtraChildParameter(LIGHT_ELEMENT, OVERSHOOT_PARAMETER, light->GetOvershoot() != false); } addExtraChildParameter(LIGHT_ELEMENT, DECAY_TYPE_PARAMETER, (int)light->GetDecayType()); addExtraChildParameter(LIGHT_ELEMENT, USE_NEAR_ATTENUATION_PARAMETER, (light->GetUseAttenNear() != false)); addExtraChildParameter(LIGHT_ELEMENT, USE_FAR_ATTENUATION_PARAMETER, (light->GetUseAtten() != false)); exportShadowParameters(light); if (light->GetProjector()) { Texmap* projectorMap = light->GetProjMap(); if (projectorMap) { String imageId = exportTexMap(projectorMap); if ( !imageId.empty() ) { addExtraChildParameter(LIGHT_ELEMENT, LIGHT_MAP_ELEMENT, "#" + imageId); } } } } else // isSky { Texmap *colorMap = parametersSky->GetTexmap(MaxLight::PB_SKY_COLOR_MAP, mDocumentExporter->getOptions().getAnimationStart()); String imageId = exportTexMap(colorMap); if ( !imageId.empty()) { addExtraChildParameter(SKYLIGHT_ELEMENT, SKYLIGHT_COLORMAP_ELEMENT, "#" + imageId); } } addLight(*colladaLight); delete colladaLight; }