void AlembicImport_FillInCamera(alembic_fillcamera_options& options) { ESS_CPP_EXCEPTION_REPORTING_START ESS_LOG_INFO("AlembicImport_FillInCamera"); if (options.pCameraObj == NULL || !AbcG::ICamera::matches((*options.pIObj).getMetaData())) { return; } AbcG::ICamera objCamera = AbcG::ICamera(*options.pIObj, Abc::kWrapExisting); if (!objCamera.valid()) { return; } double sampleTime = GetSecondsFromTimeValue(options.dTicks); SampleInfo sampleInfo = getSampleInfo(sampleTime, objCamera.getSchema().getTimeSampling(), objCamera.getSchema().getNumSamples()); AbcG::CameraSample sample; objCamera.getSchema().get(sample, sampleInfo.floorIndex); // Extract the camera values from the sample // double focalLength = sample.getFocalLength(); // double fov = sample.getHorizontalAperture(); // double nearClipping = sample.getNearClippingPlane(); // double farClipping = sample.getFarClippingPlane(); // Blend the camera values, if necessary // if (sampleInfo.alpha != 0.0) //{ // objCamera.getSchema().get(sample, sampleInfo.ceilIndex); // focalLength = (1.0 - sampleInfo.alpha) * focalLength + sampleInfo.alpha // * sample.getFocalLength(); // fov = (1.0 - sampleInfo.alpha) * fov + sampleInfo.alpha * // sample.getHorizontalAperture(); // nearClipping = (1.0 - sampleInfo.alpha) * nearClipping + // sampleInfo.alpha * sample.getNearClippingPlane(); // farClipping = (1.0 - sampleInfo.alpha) * farClipping + sampleInfo.alpha // * sample.getFarClippingPlane(); //} // options.pCameraObj->SetTDist(options.dTicks, // static_cast<float>(focalLength)); // options.pCameraObj->SetFOVType(0); // Width FoV = 0 // options.pCameraObj->SetFOV(options.dTicks, static_cast<float>(fov)); // options.pCameraObj->SetClipDist(options.dTicks, CAM_HITHER_CLIP, // static_cast<float>(nearClipping)); // options.pCameraObj->SetClipDist(options.dTicks, CAM_YON_CLIP, // static_cast<float>(farClipping)); options.pCameraObj->SetManualClip(TRUE); ESS_CPP_EXCEPTION_REPORTING_END }
void AlembicImport_FillInVis_Internal(alembic_fillvis_options &options) { if (!options.pIObj->valid()) { options.bVisibility = options.bOldVisibility; return; } AbcG::IVisibilityProperty visibilityProperty = getAbcVisibilityProperty(*options.pIObj); if (!visibilityProperty.valid()) { options.bVisibility = options.bOldVisibility; return; } double sampleTime = GetSecondsFromTimeValue(options.dTicks); SampleInfo sampleInfo = getSampleInfo(sampleTime, getTimeSamplingFromObject(*options.pIObj), visibilityProperty.getNumSamples()); boost::int8_t rawVisibilityValue = visibilityProperty.getValue(sampleInfo.floorIndex); AbcG::ObjectVisibility visibilityValue = AbcG::ObjectVisibility(rawVisibilityValue); switch (visibilityValue) { case AbcG::kVisibilityVisible: { options.bVisibility = true; break; } case AbcG::kVisibilityHidden: { options.bVisibility = false; break; } default: { options.bVisibility = options.bOldVisibility; break; } } }
bool AlembicPoints::Save(double time, bool bLastFrame) { ESS_PROFILE_FUNC(); // Note: Particles are always considered to be animated even though // the node does not have the IsAnimated() flag. // Extract our particle emitter at the given time TimeValue ticks = GetTimeValueFromFrame(time); Object *obj = mMaxNode->EvalWorldState(ticks).obj; SaveMetaData(mMaxNode, this); SimpleParticle* pSimpleParticle = (SimpleParticle*)obj->GetInterface(I_SIMPLEPARTICLEOBJ); IPFSystem* ipfSystem = GetPFSystemInterface(obj); IParticleObjectExt* particlesExt = GetParticleObjectExtInterface(obj); #ifdef THINKING_PARTICLES ParticleMat* pThinkingParticleMat = NULL; TP_MasterSystemInterface* pTPMasterSystemInt = NULL; if(obj->CanConvertToType(MATTERWAVES_CLASS_ID)) { pThinkingParticleMat = reinterpret_cast<ParticleMat*>(obj->ConvertToType(ticks, MATTERWAVES_CLASS_ID)); pTPMasterSystemInt = reinterpret_cast<TP_MasterSystemInterface*>(obj->GetInterface(IID_TP_MASTERSYSTEM)); } #endif const bool bAutomaticInstancing = GetCurrentJob()->GetOption("automaticInstancing"); if( #ifdef THINKING_PARTICLES !pThinkingParticleMat && #endif !particlesExt && !pSimpleParticle){ return false; } //We have to put the particle system into the renders state so that PFOperatorMaterialFrequency::Proceed will set the materialID channel //Note: settting the render state to true breaks the shape node instancing export bool bRenderStateForced = false; if(bAutomaticInstancing && ipfSystem && !ipfSystem->IsRenderState()){ ipfSystem->SetRenderState(true); bRenderStateForced = true; } int numParticles = 0; #ifdef THINKING_PARTICLES if(pThinkingParticleMat){ numParticles = pThinkingParticleMat->NumParticles(); } else #endif if(particlesExt){ particlesExt->UpdateParticles(mMaxNode, ticks); numParticles = particlesExt->NumParticles(); } else if(pSimpleParticle){ pSimpleParticle->Update(ticks, mMaxNode); numParticles = pSimpleParticle->parts.points.Count(); } // Store positions, velocity, width/size, scale, id, bounding box std::vector<Abc::V3f> positionVec; std::vector<Abc::V3f> velocityVec; std::vector<Abc::V3f> scaleVec; std::vector<float> widthVec; std::vector<float> ageVec; std::vector<float> massVec; std::vector<float> shapeTimeVec; std::vector<Abc::uint64_t> idVec; std::vector<Abc::uint16_t> shapeTypeVec; std::vector<Abc::uint16_t> shapeInstanceIDVec; std::vector<Abc::Quatf> orientationVec; std::vector<Abc::Quatf> angularVelocityVec; std::vector<Abc::C4f> colorVec; positionVec.reserve(numParticles); velocityVec.reserve(numParticles); scaleVec.reserve(numParticles); widthVec.reserve(numParticles); ageVec.reserve(numParticles); massVec.reserve(numParticles); shapeTimeVec.reserve(numParticles); idVec.reserve(numParticles); shapeTypeVec.reserve(numParticles); shapeInstanceIDVec.reserve(numParticles); orientationVec.reserve(numParticles); angularVelocityVec.reserve(numParticles); colorVec.reserve(numParticles); //std::vector<std::string> instanceNamesVec; Abc::Box3d bbox; bool constantPos = true; bool constantVel = true; bool constantScale = true; bool constantWidth = true; bool constantAge = true; bool constantOrientation = true; bool constantAngularVel = true; bool constantColor = true; if(bAutomaticInstancing){ SetMaxSceneTime(ticks); } //The MAX interfaces return everything in world coordinates, //so we need to multiply the inverse the node world transform matrix Matrix3 nodeWorldTM = mMaxNode->GetObjTMAfterWSM(ticks); // Convert the max transform to alembic Matrix3 alembicMatrix; ConvertMaxMatrixToAlembicMatrix(nodeWorldTM, alembicMatrix); Abc::M44d nodeWorldTrans( alembicMatrix.GetRow(0).x, alembicMatrix.GetRow(0).y, alembicMatrix.GetRow(0).z, 0, alembicMatrix.GetRow(1).x, alembicMatrix.GetRow(1).y, alembicMatrix.GetRow(1).z, 0, alembicMatrix.GetRow(2).x, alembicMatrix.GetRow(2).y, alembicMatrix.GetRow(2).z, 0, alembicMatrix.GetRow(3).x, alembicMatrix.GetRow(3).y, alembicMatrix.GetRow(3).z, 1); Abc::M44d nodeWorldTransInv = nodeWorldTrans.inverse(); //ESS_LOG_WARNING("tick: "<<ticks<<" numParticles: "<<numParticles<<"\n"); ExoNullView nullView; particleGroupInterface groupInterface(particlesExt, obj, mMaxNode, &nullView); { ESS_PROFILE_SCOPE("AlembicPoints::SAVE - numParticlesLoop"); for (int i = 0; i < numParticles; ++i) { Abc::V3f pos(0.0); Abc::V3f vel(0.0); Abc::V3f scale(1.0); Abc::C4f color(0.5, 0.5, 0.5, 1.0); float age = 0; Abc::uint64_t id = 0; Abc::Quatd orientation(0.0, 0.0, 1.0, 0.0); Abc::Quatd spin(0.0, 0.0, 1.0, 0.0); // Particle size is a uniform scale multiplier in XSI. In Max, I need to learn where to get this // For now, we'll just default to 1 float width = 1.0f; ShapeType shapetype = ShapeType_Point; float shapeInstanceTime = (float)time; Abc::uint16_t shapeInstanceId = 0; #ifdef THINKING_PARTICLES if(pThinkingParticleMat){ if(pTPMasterSystemInt->IsAlive(i) == FALSE){ continue; } //TimeValue ageValue = particlesExt->GetParticleAgeByIndex(i); TimeValue ageValue = pTPMasterSystemInt->Age(i); if(ageValue == -1){ continue; } ESS_PROFILE_SCOPE("AlembicPoints::SAVE - numParticlesLoop - ThinkingParticles"); age = (float)GetSecondsFromTimeValue(ageValue); //pos = ConvertMaxPointToAlembicPoint(*particlesExt->GetParticlePositionByIndex(i)); pos = ConvertMaxPointToAlembicPoint(pTPMasterSystemInt->Position(i)); //vel = ConvertMaxVectorToAlembicVector(*particlesExt->GetParticleSpeedByIndex(i) * TIME_TICKSPERSEC); vel = ConvertMaxVectorToAlembicVector(pTPMasterSystemInt->Velocity(i) * TIME_TICKSPERSEC); scale = ConvertMaxScaleToAlembicScale(pTPMasterSystemInt->Scale(i)); scale *= pTPMasterSystemInt->Size(i); //ConvertMaxEulerXYZToAlembicQuat(*particlesExt->GetParticleOrientationByIndex(i), orientation); Matrix3 alignmentMatMax = pTPMasterSystemInt->Alignment(i); Abc::M44d alignmentMat; ConvertMaxMatrixToAlembicMatrix(alignmentMatMax, alignmentMat); /*alignmentMat = Abc::M44d( alignmentMatMax.GetRow(0).x, alignmentMatMax.GetRow(0).y, alignmentMatMax.GetRow(0).z, 0, alignmentMatMax.GetRow(1).x, alignmentMatMax.GetRow(1).y, alignmentMatMax.GetRow(1).z, 0, alignmentMatMax.GetRow(2).x, alignmentMatMax.GetRow(2).y, alignmentMatMax.GetRow(2).z, 0, alignmentMatMax.GetRow(3).x, alignmentMatMax.GetRow(3).y, alignmentMatMax.GetRow(3).z, 1);*/ //orientation = ConvertMaxQuatToAlembicQuat(extracctuat(alignmentMat), true); alignmentMat = alignmentMat * nodeWorldTransInv; orientation = extractQuat(alignmentMat); //ConvertMaxAngAxisToAlembicQuat(*particlesExt->GetParticleSpinByIndex(i), spin); ConvertMaxAngAxisToAlembicQuat(pTPMasterSystemInt->Spin(i), spin); id = particlesExt->GetParticleBornIndex(i); //seems to always return 0 //int nPid = pThinkingParticleMat->ParticleID(i); int nMatId = -1; Matrix3 meshTM; meshTM.IdentityMatrix(); BOOL bNeedDelete = FALSE; BOOL bChanged = FALSE; Mesh* pMesh = NULL; { ESS_PROFILE_SCOPE("AlembicPoints::SAVE - numParticlesLoop - ThinkingParticles - GetParticleRenderMesh"); pMesh = pThinkingParticleMat->GetParticleRenderMesh(ticks, mMaxNode, nullView, bNeedDelete, i, meshTM, bChanged); } if(pMesh){ ESS_PROFILE_SCOPE("AlembicPoints::SAVE - numParticlesLoop - ThinkingParticles - CacheShapeMesh"); meshInfo mi = CacheShapeMesh(pMesh, bNeedDelete, meshTM, nMatId, i, ticks, shapetype, shapeInstanceId, shapeInstanceTime); Abc::V3d min = pos + mi.bbox.min; Abc::V3d max = pos + mi.bbox.max; bbox.extendBy(min); bbox.extendBy(max); } else{ shapetype = ShapeType_Point; } } else #endif if(particlesExt && ipfSystem){ TimeValue ageValue = particlesExt->GetParticleAgeByIndex(i); if(ageValue == -1){ continue; } age = (float)GetSecondsFromTimeValue(ageValue); pos = ConvertMaxPointToAlembicPoint(*particlesExt->GetParticlePositionByIndex(i)); vel = ConvertMaxVectorToAlembicVector(*particlesExt->GetParticleSpeedByIndex(i) * TIME_TICKSPERSEC); scale = ConvertMaxScaleToAlembicScale(*particlesExt->GetParticleScaleXYZByIndex(i)); ConvertMaxEulerXYZToAlembicQuat(*particlesExt->GetParticleOrientationByIndex(i), orientation); ConvertMaxAngAxisToAlembicQuat(*particlesExt->GetParticleSpinByIndex(i), spin); //age = (float)GetSecondsFromTimeValue(particlesExt->GetParticleAgeByIndex(i)); id = particlesExt->GetParticleBornIndex(i); if(bAutomaticInstancing){ int nMatId = -1; if(ipfSystem){ if( groupInterface.setCurrentParticle(ticks, i) ){ nMatId = groupInterface.getCurrentMtlId(); } else{ ESS_LOG_WARNING("Error: cound retrieve material ID for particle mesh "<<i); } } Matrix3 meshTM; meshTM.IdentityMatrix(); BOOL bNeedDelete = FALSE; BOOL bChanged = FALSE; Mesh* pMesh = pMesh = particlesExt->GetParticleShapeByIndex(i); if(pMesh){ meshInfo mi = CacheShapeMesh(pMesh, bNeedDelete, meshTM, nMatId, i, ticks, shapetype, shapeInstanceId, shapeInstanceTime); Abc::V3d min = pos + mi.bbox.min; Abc::V3d max = pos + mi.bbox.max; bbox.extendBy(min); bbox.extendBy(max); } else{ shapetype = ShapeType_Point; } } else{ GetShapeType(particlesExt, i, ticks, shapetype, shapeInstanceId, shapeInstanceTime); } color = GetColor(particlesExt, i, ticks); } else if(pSimpleParticle){ if( ! pSimpleParticle->parts.Alive( i ) ) { continue; } pos = ConvertMaxPointToAlembicPoint(pSimpleParticle->ParticlePosition(ticks, i)); vel = ConvertMaxVectorToAlembicVector(pSimpleParticle->ParticleVelocity(ticks, i)); //simple particles have no scale? //simple particles have no orientation? age = (float)GetSecondsFromTimeValue( pSimpleParticle->ParticleAge(ticks, i) ); //simple particles have born index width = pSimpleParticle->ParticleSize(ticks, i); Abc::V3d min(pos.x - width/2, pos.y - width/2, pos.z - width/2); Abc::V3d max(pos.x + width/2, pos.y + width/2, pos.z + width/2); bbox.extendBy(min); bbox.extendBy(max); } { ESS_PROFILE_SCOPE("AlembicPoints::SAVE - numParticlesLoop - end loop save"); //move everything from world space to local space pos = pos * nodeWorldTransInv; Abc::V4f vel4(vel.x, vel.y, vel.z, 0.0); vel4 = vel4 * nodeWorldTransInv; vel.setValue(vel4.x, vel4.y, vel4.z); //scale = scale * nodeWorldTransInv; //orientation = Abc::extractQuat(orientation.toMatrix44() * nodeWorldTransInv); //spin = Abc::extractQuat(spin.toMatrix44() * nodeWorldTransInv); bbox.extendBy( pos ); positionVec.push_back( pos ); velocityVec.push_back( vel ); scaleVec.push_back( scale ); widthVec.push_back( width ); ageVec.push_back( age ); idVec.push_back( id ); orientationVec.push_back( orientation ); angularVelocityVec.push_back( spin ); shapeTypeVec.push_back( shapetype ); shapeInstanceIDVec.push_back( shapeInstanceId ); shapeTimeVec.push_back( shapeInstanceTime ); colorVec.push_back( color ); constantPos &= (pos == positionVec[0]); constantVel &= (vel == velocityVec[0]); constantScale &= (scale == scaleVec[0]); constantWidth &= (width == widthVec[0]); constantAge &= (age == ageVec[0]); constantOrientation &= (orientation == orientationVec[0]); constantAngularVel &= (spin == angularVelocityVec[0]); constantColor &= (color == colorVec[0]); // Set the archive bounding box // Positions for particles are already cnsider to be in world space if (mJob) { mJob->GetArchiveBBox().extendBy(pos); } } } } // if (numParticles > 1) // { // ESS_PROFILE_SCOPE("AlembicPoints::Save - vectorResize"); // if (constantPos) { positionVec.resize(1); } // if (constantVel) { velocityVec.resize(1); } // if (constantScale) { scaleVec.resize(1); } // if (constantWidth) { widthVec.resize(1); } // if (constantAge) { ageVec.resize(1); } // if (constantOrientation){ orientationVec.resize(1); } // if (constantAngularVel) { angularVelocityVec.resize(1); } //if (constantColor) { colorVec.resize(1); } // } { ESS_PROFILE_SCOPE("AlembicPoints::Save - sample writing"); // Store the information into our properties and points schema Abc::P3fArraySample positionSample( positionVec); Abc::P3fArraySample velocitySample(velocityVec); Abc::P3fArraySample scaleSample(scaleVec); Abc::FloatArraySample widthSample(widthVec); Abc::FloatArraySample ageSample(ageVec); Abc::FloatArraySample massSample(massVec); Abc::FloatArraySample shapeTimeSample(shapeTimeVec); Abc::UInt64ArraySample idSample(idVec); Abc::UInt16ArraySample shapeTypeSample(shapeTypeVec); Abc::UInt16ArraySample shapeInstanceIDSample(shapeInstanceIDVec); Abc::QuatfArraySample orientationSample(orientationVec); Abc::QuatfArraySample angularVelocitySample(angularVelocityVec); Abc::C4fArraySample colorSample(colorVec); mScaleProperty.set(scaleSample); mAgeProperty.set(ageSample); mMassProperty.set(massSample); mShapeTimeProperty.set(shapeTimeSample); mShapeTypeProperty.set(shapeTypeSample); mShapeInstanceIDProperty.set(shapeInstanceIDSample); mOrientationProperty.set(orientationSample); mAngularVelocityProperty.set(angularVelocitySample); mColorProperty.set(colorSample); mPointsSample.setPositions(positionSample); mPointsSample.setVelocities(velocitySample); mPointsSample.setWidths(AbcG::OFloatGeomParam::Sample(widthSample, AbcG::kVertexScope)); mPointsSample.setIds(idSample); mPointsSample.setSelfBounds(bbox); mPointsSchema.getChildBoundsProperty().set( bbox); mPointsSchema.set(mPointsSample); } mNumSamples++; //mInstanceNames.pop_back(); if(bAutomaticInstancing){ saveCurrentFrameMeshes(); } if(bRenderStateForced){ ipfSystem->SetRenderState(false); } if(bLastFrame){ ESS_PROFILE_SCOPE("AlembicParticles::Save - save instance names property"); std::vector<std::string> instanceNames(mNumShapeMeshes); for(faceVertexHashToShapeMap::iterator it = mShapeMeshCache.begin(); it != mShapeMeshCache.end(); it++){ std::stringstream pathStream; pathStream << "/" << it->second.name<< "/" << it->second.name <<"Shape"; instanceNames[it->second.nMeshInstanceId] = pathStream.str(); } //for some reason the .dims property is not written when there is exactly one entry if we don't push an empty string //having an extra unreferenced entry seems to be harmless instanceNames.push_back(""); mInstanceNamesProperty.set(Abc::StringArraySample(instanceNames)); } return true; }
void AlembicPoints::ReadShapeFromOperator( IParticleGroup *particleGroup, PFSimpleOperator *pSimpleOperator, int particleId, TimeValue ticks, ShapeType &type, Abc::uint16_t &instanceId, float &animationTime) { if(!pSimpleOperator){ return; } if (pSimpleOperator->ClassID() == PFOperatorSimpleShape_Class_ID) { IParamBlock2 *pblock = pSimpleOperator->GetParamBlockByID(0); int nShapeId = pblock->GetInt(PFlow_kSimpleShape_shape, ticks); switch(nShapeId) { case PFlow_kSimpleShape_shape_pyramid: type = ShapeType_Cone; break; case PFlow_kSimpleShape_shape_cube: type = ShapeType_Box; break; case PFlow_kSimpleShape_shape_sphere: type = ShapeType_Sphere; break; case PFlow_kSimpleShape_shape_vertex: type = ShapeType_Point; break; default: type = ShapeType_Point; } } else if (pSimpleOperator->ClassID() == PFOperatorShapeLib_Class_ID) { IParamBlock2 *pblock = pSimpleOperator->GetParamBlockByID(0); int nDimension = pblock->GetInt(PFlow_kShapeLibary_dimensionType, ticks); if(nDimension == PFlow_kShapeLibrary_dimensionType_2D){ int n2DShapeId = pblock->GetInt(PFlow_kShapeLibary_2DType, ticks); if( n2DShapeId == PFlow_kShapeLibrary_dimensionType_2D_square){ type = ShapeType_Rectangle; } else{ ESS_LOG_INFO("Unsupported shape type."); type = ShapeType_Point; } } else if(nDimension == PFlow_kShapeLibrary_dimensionType_3D){ int n3DShapeId = pblock->GetInt(PFlow_kShapeLibary_3DType, ticks); if(n3DShapeId == PFlow_kShapeLibary_3DType_cube){ type = ShapeType_Box; } else if(n3DShapeId == PFlow_kShapeLibary_3DType_Sphere20sides || n3DShapeId == PFlow_kShapeLibary_3DType_Sphere80sides){ type = ShapeType_Sphere; } else{ ESS_LOG_INFO("Unsupported shape type."); type = ShapeType_Point; } //ShapeType_Cylinder unsupported //ShapeType_Cone unsupported //ShapeType_Disc unsupported //ShapeType_NbElements unsupported } else{ ESS_LOG_INFO("Unknown dimension."); type = ShapeType_Point; } //int nNumParams = pblock->NumParams(); //for(int i=0; i<nNumParams; i++){ // ParamID id = pblock->IndextoID(i); // MSTR paramStr = pblock->GetLocalName(id, 0); // int n = 0; // //} } else if (pSimpleOperator->ClassID() == PFOperatorInstanceShape_Class_ID) { // Assign animation time and shape here IParamBlock2 *pblock = pSimpleOperator->GetParamBlockByID(0); INode *pNode = pblock->GetINode(PFlow_kInstanceShape_objectMaxscript, ticks); if (pNode == NULL || pNode->GetName() == NULL) { return; } type = ShapeType_Instance; bool bFlatten = GetCurrentJob()->GetOption("flattenHierarchy"); std::string nodePath = getNodeAlembicPath( EC_MCHAR_to_UTF8( pNode->GetName() ), bFlatten); // Find if the name is alerady registered, otherwise add it to the list // instanceId = FindInstanceName(nodePath); // if (instanceId == USHRT_MAX) // { //mInstanceNames.push_back(nodePath); // instanceId = (Abc::uint16_t)mInstanceNames.size()-1; // } // Determine if we have an animated shape BOOL animatedShape = pblock->GetInt(PFlow_kInstanceShape_animatedShape); BOOL acquireShape = pblock->GetInt(PFlow_kInstanceShape_acquireShape); if (!animatedShape && !acquireShape) { return; } // Get the necesary particle channels to grab the current time values ::IObject *pCont = particleGroup->GetParticleContainer(); if (!pCont) { return; } // Get synch values that we are interested in fromt the param block int syncType = pblock->GetInt(PFlow_kInstanceShape_syncType); BOOL syncRandom = pblock->GetInt(PFlow_kInstanceShape_syncRandom); IParticleChannelPTVR* chTime = GetParticleChannelTimeRInterface(pCont); if (chTime == NULL) { return; // can't find particle times in the container } IChannelContainer* chCont = GetChannelContainerInterface(pCont); if (chCont == NULL) { return; // can't get access to ChannelContainer interface } IParticleChannelPTVR* chBirthTime = NULL; IParticleChannelPTVR* chEventStartR = NULL; bool initEventStart = false; if (syncType == PFlow_kInstanceShape_syncBy_particleAge) { chBirthTime = GetParticleChannelBirthTimeRInterface(pCont); if (chBirthTime == NULL) { return; // can't read particle age } } else if (syncType == PFlow_kInstanceShape_syncBy_eventStart) { chEventStartR = GetParticleChannelEventStartRInterface(pCont); if (chEventStartR == NULL) { return; // can't read event start time } } IParticleChannelIntR* chLocalOffR = NULL; bool initLocalOff = false; // acquire LocalOffset particle channel; if not present then create it. if (syncRandom) { chLocalOffR = (IParticleChannelIntR*)chCont->GetPrivateInterface(PARTICLECHANNELLOCALOFFSETR_INTERFACE, pSimpleOperator); } // get new shape from the source PreciseTimeValue time = chTime->GetValue(particleId); switch(syncType) { case PFlow_kInstanceShape_syncBy_absoluteTime: break; case PFlow_kInstanceShape_syncBy_particleAge: time -= chBirthTime->GetValue(particleId); break; case PFlow_kInstanceShape_syncBy_eventStart: time -= chEventStartR->GetValue(particleId); break; default: break; } if (syncRandom) { if (chLocalOffR != NULL) time += chLocalOffR->GetValue(particleId); } //timeValueMap::iterator it = mTimeValueMap.find(time); //if( it != mTimeValueMap.end() ){ // ESS_LOG_WARNING("sampleTime already seen."); //} //else{ // mTimeValueMap[time] = true; // mTimeSamplesCount++; // ESS_LOG_WARNING("sampleTime: "<<(float)time<<" totalSamples: "<<mTimeSamplesCount); //} TimeValue t = TimeValue(time); animationTime = (float)GetSecondsFromTimeValue(t); } else if (pSimpleOperator->ClassID() == PFOperatorMarkShape_Class_ID) { ESS_LOG_INFO("Shape Mark operator not supported."); } else if (pSimpleOperator->ClassID() == PFOperatorFacingShape_Class_ID) { ESS_LOG_INFO("Shape Facing operator not supported."); } }
void AlembicFloatController::GetValueLocalTime(TimeValue t, void* ptr, Interval& valid, GetSetMethod method) { ESS_CPP_EXCEPTION_REPORTING_START Interval interval = FOREVER; MCHAR const* strPath = NULL; this->pblock->GetValue(AlembicFloatController::ID_PATH, t, strPath, interval); MCHAR const* strIdentifier = NULL; this->pblock->GetValue(AlembicFloatController::ID_IDENTIFIER, t, strIdentifier, interval); MCHAR const* strCategory = NULL; this->pblock->GetValue(AlembicFloatController::ID_CATEGORY, t, strCategory, interval); MCHAR const* strProperty = NULL; this->pblock->GetValue(AlembicFloatController::ID_PROPERTY, t, strProperty, interval); float fTime; this->pblock->GetValue(AlembicFloatController::ID_TIME, t, fTime, interval); BOOL bMuted; this->pblock->GetValue(AlembicFloatController::ID_MUTED, t, bMuted, interval); extern bool g_bVerboseLogging; if (g_bVerboseLogging) { ESS_LOG_WARNING("Param block at tick " << t << "-----------------------"); ESS_LOG_WARNING("PATH: " << strPath); ESS_LOG_WARNING("IDENTIFIER: " << strIdentifier); ESS_LOG_WARNING("PROPERTY: " << strProperty); ESS_LOG_WARNING("TIME: " << fTime); ESS_LOG_WARNING("MUTED: " << bMuted); ESS_LOG_WARNING("Param block end -------------"); } const float fDefaultVal = -1.0; std::string szPath = EC_MCHAR_to_UTF8(strPath); std::string szIdentifier = EC_MCHAR_to_UTF8(strIdentifier); std::string szProperty = EC_MCHAR_to_UTF8(strProperty); std::string szCategory = EC_MCHAR_to_UTF8(strCategory); if (szCategory.empty()) { // default to standard properties for backwards // compatibility szCategory = std::string("standardProperties"); } if (!strProperty || !strPath || !strIdentifier /*|| !strCategory*/) { return setController("1", szProperty, valid, interval, method, ptr, fDefaultVal); } if (bMuted) { return setController("2", szProperty, valid, interval, method, ptr, fDefaultVal); } // if( szCategory.size() == 0 ) { // ESS_LOG_ERROR( "No category specified." ); // return setController("3a", szProperty, valid, interval, method, ptr, // fDefaultVal); //} if (szProperty.size() == 0) { ESS_LOG_ERROR("No property specified."); return setController("3b", szProperty, valid, interval, method, ptr, fDefaultVal); } AbcG::IObject iObj = getObjectFromArchive(szPath, szIdentifier); if (!iObj.valid()) { return setController("4", szProperty, valid, interval, method, ptr, fDefaultVal); } TimeValue dTicks = GetTimeValueFromSeconds(fTime); double sampleTime = GetSecondsFromTimeValue(dTicks); float fSampleVal = fDefaultVal; if (boost::iequals(szCategory, "standardProperties")) { if (Alembic::AbcGeom::ICamera::matches( iObj.getMetaData())) { // standard camera properties Alembic::AbcGeom::ICamera objCamera = Alembic::AbcGeom::ICamera(iObj, Alembic::Abc::kWrapExisting); SampleInfo sampleInfo = getSampleInfo(sampleTime, objCamera.getSchema().getTimeSampling(), objCamera.getSchema().getNumSamples()); Alembic::AbcGeom::CameraSample sample; objCamera.getSchema().get(sample, sampleInfo.floorIndex); double sampleVal; if (!getCameraSampleVal(objCamera, sampleInfo, sample, szProperty, sampleVal)) { return setController("5", szProperty, valid, interval, method, ptr, fDefaultVal); } // Blend the camera values, if necessary if (sampleInfo.alpha != 0.0) { objCamera.getSchema().get(sample, sampleInfo.ceilIndex); double sampleVal2 = 0.0; if (getCameraSampleVal(objCamera, sampleInfo, sample, szProperty, sampleVal2)) { sampleVal = (1.0 - sampleInfo.alpha) * sampleVal + sampleInfo.alpha * sampleVal2; } } fSampleVal = (float)sampleVal; } else if (Alembic::AbcGeom::ILight::matches( iObj.getMetaData())) { // ILight material properties ESS_PROFILE_SCOPE( "AlembicFloatController::GetValueLocalTime - read ILight shader " "parameter"); Alembic::AbcGeom::ILight objLight = Alembic::AbcGeom::ILight(iObj, Alembic::Abc::kWrapExisting); SampleInfo sampleInfo = getSampleInfo(sampleTime, objLight.getSchema().getTimeSampling(), objLight.getSchema().getNumSamples()); AbcM::IMaterialSchema matSchema = getMatSchema(objLight); std::string strProp = szProperty; std::vector<std::string> parts; boost::split(parts, strProp, boost::is_any_of(".")); if (parts.size() == 3) { const std::string& target = parts[0]; const std::string& type = parts[1]; const std::string& prop = parts[2]; Abc::IFloatProperty fProp = readShaderScalerProp<Abc::IFloatProperty>( matSchema, target, type, prop); if (fProp.valid()) { fProp.get(fSampleVal, sampleInfo.floorIndex); } else { ESS_LOG_WARNING("Float Controller Error: could find shader parameter " << strProp); } } else if (parts.size() == 5) { const std::string& target = parts[0]; const std::string& type = parts[1]; const std::string& prop = parts[2]; const std::string& propInterp = parts[3]; const std::string& propComp = parts[4]; // ESS_LOG_WARNING("propInterp: "<<propInterp); if (propInterp == "rgb") { Abc::IC3fProperty fProp = readShaderScalerProp<Abc::IC3fProperty>( matSchema, target, type, prop); if (fProp.valid()) { Abc::C3f v3f; fProp.get(v3f, sampleInfo.floorIndex); if (propComp == "x") { fSampleVal = v3f.x; } else if (propComp == "y") { fSampleVal = v3f.y; } else if (propComp == "z") { fSampleVal = v3f.z; } else { ESS_LOG_WARNING( "Float Controller Error: invalid component: " << propComp); } } else { ESS_LOG_WARNING( "Float Controller Error: could find shader parameter " << strProp); } } else { ESS_LOG_WARNING( "Float Controller Error: unrecognized parameter interpretation: " << propInterp); } } else { ESS_LOG_WARNING( "Float Controller Error: could not parse property field: " << strProperty); } } } else if (boost::iequals(szCategory, "userProperties")) { // AbcA::TimeSamplingPtr timeSampling = obj.getSchema().getTimeSampling(); // int nSamples = (int)obj.getSchema().getNumSamples(); AbcA::TimeSamplingPtr timeSampling; int nSamples = 0; Abc::ICompoundProperty propk = AbcNodeUtils::getUserProperties(iObj, timeSampling, nSamples); if (propk.valid()) { SampleInfo sampleInfo = getSampleInfo(sampleTime, timeSampling, nSamples); std::vector<std::string> parts; boost::split(parts, szProperty, boost::is_any_of(".")); if (parts.size() == 1) { Abc::IFloatProperty fProp = readScalarProperty<Abc::IFloatProperty>(propk, szProperty); if (fProp.valid()) { fProp.get(fSampleVal, sampleInfo.floorIndex); } else { Abc::IInt32Property intProp = readScalarProperty<Abc::IInt32Property>(propk, szProperty); if (intProp.valid()) { int intVal; intProp.get(intVal, sampleInfo.floorIndex); fSampleVal = (float)intVal; } else { ESS_LOG_WARNING( "Float Controller Error: could not read user property " << szProperty); } } } else if (parts.size() == 3) { const std::string& prop = parts[0]; const std::string& propInterp = parts[1]; const std::string& propComp = parts[2]; // ESS_LOG_WARNING("interpretation: "<<propInterp); if (propInterp == "rgb") { fSampleVal = readScalarPropertyExt3<Abc::IC3fProperty, Abc::C3f>( propk, sampleInfo, prop, propComp); } else if (propInterp == "vector") { fSampleVal = readScalarPropertyExt3<Abc::IV3fProperty, Abc::V3f>( propk, sampleInfo, prop, propComp); } else { ESS_LOG_WARNING( "Float Controller Error: unrecognized parameter interpretation: " << propInterp); } } } } // else if( boost::iequals(szCategory, "arbGeomParams") ){ //} return setController("6", szProperty, valid, interval, method, ptr, fSampleVal); ESS_CPP_EXCEPTION_REPORTING_END }