Exemplo n.º 1
0
Abc::M44d AbcObjectCache::getXformMatrix(int index)
{
   if(iXformMap.find(index) == iXformMap.end()){
      AbcG::XformSample sample;
      getXform();
      pObjXform->getSchema().get(sample, index);
      Abc::M44d mat = sample.getMatrix();
      iXformMap[index] = mat;
      return mat;
   }
   return iXformMap[index];
}
Exemplo n.º 2
0
static PyObject * iXformProperty_getValues(PyObject * self, PyObject * args)
{
   ALEMBIC_TRY_STATEMENT
   iXformProperty * prop = (iXformProperty*)self;

   unsigned long long sampleIndex = 0;
   unsigned long long start = 0;
   unsigned long long count = 0;
   PyArg_ParseTuple(args, "|KKK", &sampleIndex,&start,&count);

   size_t numSamples = iXformProperty_getNbStoredSamples_func(self);
   if(sampleIndex >= numSamples)
   {
      std::string msg;
      msg.append("SampleIndex for Property '");
      msg.append(iXformProperty_getName_func());
      msg.append("' is out of bounds!");
      PyErr_SetString(getError(), msg.c_str());
      return NULL;
   }

   PyObject * tuple = NULL;
   tuple = PyTuple_New(16);

   AbcG::XformSample sample;
   prop->mXformSchema->get(sample,sampleIndex);
   Abc::M44d value = sample.getMatrix();

   PyTuple_SetItem(tuple,0,Py_BuildValue("d",value.x[0][0]));
   PyTuple_SetItem(tuple,1,Py_BuildValue("d",value.x[0][1]));
   PyTuple_SetItem(tuple,2,Py_BuildValue("d",value.x[0][2]));
   PyTuple_SetItem(tuple,3,Py_BuildValue("d",value.x[0][3]));
   PyTuple_SetItem(tuple,4,Py_BuildValue("d",value.x[1][0]));
   PyTuple_SetItem(tuple,5,Py_BuildValue("d",value.x[1][1]));
   PyTuple_SetItem(tuple,6,Py_BuildValue("d",value.x[1][2]));
   PyTuple_SetItem(tuple,7,Py_BuildValue("d",value.x[1][3]));
   PyTuple_SetItem(tuple,8,Py_BuildValue("d",value.x[2][0]));
   PyTuple_SetItem(tuple,9,Py_BuildValue("d",value.x[2][1]));
   PyTuple_SetItem(tuple,10,Py_BuildValue("d",value.x[2][2]));
   PyTuple_SetItem(tuple,11,Py_BuildValue("d",value.x[2][3]));
   PyTuple_SetItem(tuple,12,Py_BuildValue("d",value.x[3][0]));
   PyTuple_SetItem(tuple,13,Py_BuildValue("d",value.x[3][1]));
   PyTuple_SetItem(tuple,14,Py_BuildValue("d",value.x[3][2]));
   PyTuple_SetItem(tuple,15,Py_BuildValue("d",value.x[3][3]));

   return tuple;
   ALEMBIC_PYOBJECT_CATCH_STATEMENT
}
Exemplo n.º 3
0
//TODO: should only refer to our scene graph nodes, and rely on global transforms only
void SaveXformSample(SceneNodePtr node, AbcG::OXformSchema & schema,AbcG::XformSample & sample, double time, bool xformCache, bool globalSpace, bool flattenHierarchy)
{
   

   // check if we are exporting in global space
   if(globalSpace)
   {
      if(schema.getNumSamples() > 0)
         return;

      // store identity matrix
      sample.setTranslation(Imath::V3d(0.0,0.0,0.0));
      sample.setRotation(Imath::V3d(1.0,0.0,0.0),0.0);
      sample.setScale(Imath::V3d(1.0,1.0,1.0));

      // save the sample
      schema.set(sample);
      return;
   }

   // check if the transform is animated
   //if(schema.getNumSamples() > 0)
   //{
   //   X3DObject parent(kineState.GetParent3DObject());
   //   if(!isRefAnimated(kineState.GetParent3DObject().GetRef(),xformCache))
   //      return;
   //}

   if(flattenHierarchy){//a hack needed to handle namespace xforms
   sample.setMatrix(node->getGlobalTransDouble(time));
   }
   else{

      Imath::M44d parentGlobalTransInv = node->parent->getGlobalTransDouble(time).invert();
      Imath::M44d transform = node->getGlobalTransDouble(time) * parentGlobalTransInv;
      sample.setMatrix(transform);
   }



   //KinematicState kineState(kineStateRef);
   //CTransformation globalTransform = kineState.GetTransform(time);
   //CTransformation transform;

   //if(flattenHierarchy){
   //   transform = globalTransform;
   //}
   //else{
   //   KinematicState parentKineState(parentKineStateRef);
   //   CMatrix4 parentGlobalTransform4 = parentKineState.GetTransform(time).GetMatrix4();
   //   CMatrix4 transform4 = globalTransform.GetMatrix4();
   //   parentGlobalTransform4.InvertInPlace();
   //   transform4.MulInPlace(parentGlobalTransform4);
   //   transform.SetMatrix4(transform4);
   //}

   //// store the transform
   //CVector3 trans = transform.GetTranslation();
   //CVector3 axis;
   //double angle = transform.GetRotationAxisAngle(axis);
   //CVector3 scale = transform.GetScaling();
   //sample.setTranslation(Imath::V3d(trans.GetX(),trans.GetY(),trans.GetZ()));
   //sample.setRotation(Imath::V3d(axis.GetX(),axis.GetY(),axis.GetZ()),RadiansToDegrees(angle));
   //sample.setScale(Imath::V3d(scale.GetX(),scale.GetY(),scale.GetZ()));

   //ESS_LOG_WARNING("time: "<<time<<" trans: ("<<trans.GetX()<<", "<<trans.GetY()<<", "<<trans.GetZ()<<") angle: "<<angle<<" axis: ("<<axis.GetX()<<", "<<axis.GetY()<<", "<<axis.GetZ());

   // save the sample
   schema.set(sample);
}
Exemplo n.º 4
0
//we have to save out all mesh encountered on the current frame of this object immediately, because 
//the pointers will no longer be valid when the object is evaluated at a new time
void AlembicPoints::saveCurrentFrameMeshes()
{
    ESS_PROFILE_FUNC();

	for(int i=0; i<mMeshesToSaveForCurrentFrame.size(); i++){

        //TODO: save immediately instead accumulating in a vector
		meshInfo* mi = mMeshesToSaveForCurrentFrame[i];

		if(mi->pMesh){
			Mesh* pMesh = mi->pMesh;
			//mi->pMesh = NULL;//each mesh only needs to be saved once

			//Matrix3 worldTrans;
			//worldTrans.IdentityMatrix();

			CommonOptions options;
         options.SetOption("exportNormals", mJob->GetOption("exportNormals"));
			options.SetOption("exportMaterialIds", mJob->GetOption("exportMaterialIds"));

			//gather the mesh data
			mi->meshTM.IdentityMatrix();
			IntermediatePolyMesh3DSMax finalPolyMesh;
            {
            ESS_PROFILE_SCOPE("AlembicPoints::saveCurrentFrameMeshes - finalPolyMesh.Save");

            Imath::M44f transform44f;
            ConvertMaxMatrixToAlembicMatrix( mi->meshTM, transform44f );
            SceneNodeMaxParticlesPtr inputSceneNode(new SceneNodeMaxParticles(pMesh, NULL, mi->nMatId));
            finalPolyMesh.Save(inputSceneNode, transform44f, options, 0.0);

            }

            AbcG::OPolyMeshSchema::Sample meshSample;
            AbcG::OPolyMeshSchema meshSchema;
            {
            ESS_PROFILE_SCOPE("AlembicPoints::saveCurrentFrameMeshes - save xforms, bbox, geo, topo");
			//save out the mesh xForm
			//std::string xformName = mi->name + "Xfo";
			AbcG::OXform xform(mJob->GetArchive().getTop(), mi->name, GetCurrentJob()->GetAnimatedTs());
			AbcG::OXformSchema& xformSchema = xform.getSchema();//mi->xformSchema;

			std::string meshName = mi->name + "Shape";
			AbcG::OPolyMesh mesh(xform, meshName, GetCurrentJob()->GetAnimatedTs());
			meshSchema = mesh.getSchema();

			AbcG::XformSample xformSample;

			Matrix3 alembicMatrix;
			alembicMatrix.IdentityMatrix();
			alembicMatrix.SetTrans(Point3(-10000.0f, -10000.0f, -10000.0f));
			Abc::M44d iMatrix;
			ConvertMaxMatrixToAlembicMatrix(alembicMatrix, iMatrix);

			xformSample.setMatrix(iMatrix);
			xformSchema.set(xformSample);

			//update the archive bounding box
			Abc::Box3d bbox;
			bbox.min = finalPolyMesh.bbox.min * iMatrix;
			bbox.max = finalPolyMesh.bbox.max * iMatrix;

			mJob->GetArchiveBBox().extendBy(bbox);

			//save out the mesh data			
			meshSample.setPositions(Abc::P3fArraySample(finalPolyMesh.posVec));
			meshSample.setSelfBounds(finalPolyMesh.bbox);
			meshSchema.getChildBoundsProperty().set(finalPolyMesh.bbox);

			meshSample.setFaceCounts(Abc::Int32ArraySample(finalPolyMesh.mFaceCountVec));
			meshSample.setFaceIndices(Abc::Int32ArraySample(finalPolyMesh.mFaceIndicesVec));
            }

			if(mJob->GetOption("validateMeshTopology")){
                ESS_PROFILE_SCOPE("AlembicPoints::saveCurrentFrameMeshes - validateMeshTopology");
				mJob->mMeshErrors += validateAlembicMeshTopo(finalPolyMesh.mFaceCountVec, finalPolyMesh.mFaceIndicesVec, mi->name);
			}

			if(mJob->GetOption("exportNormals")){
                ESS_PROFILE_SCOPE("AlembicPoints::saveCurrentFrameMeshes - exportNormals");
				AbcG::ON3fGeomParam::Sample normalSample;
				normalSample.setScope(AbcG::kFacevaryingScope);
				normalSample.setVals(Abc::N3fArraySample(finalPolyMesh.mIndexedNormals.values));
				normalSample.setIndices(Abc::UInt32ArraySample(finalPolyMesh.mIndexedNormals.indices));
				meshSample.setNormals(normalSample);
			}

			if(mJob->GetOption("exportMaterialIds")){
                ESS_PROFILE_SCOPE("AlembicPoints::saveCurrentFrameMeshes - exportMaterialIds");
				Abc::OUInt32ArrayProperty mMatIdProperty = 
					Abc::OUInt32ArrayProperty(meshSchema, ".materialids", meshSchema.getMetaData(), mJob->GetAnimatedTs());
				mMatIdProperty.set(Abc::UInt32ArraySample(finalPolyMesh.mMatIdIndexVec));

				for ( facesetmap_it it=finalPolyMesh.mFaceSets.begin(); it != finalPolyMesh.mFaceSets.end(); it++)
				{
					std::stringstream nameStream;
					int nMaterialId = it->first+1;
					nameStream<<it->second.name<<"_"<<nMaterialId;

					std::vector<Abc::int32_t>& faceSetVec = it->second.faceIds;

					AbcG::OFaceSet faceSet = meshSchema.createFaceSet(nameStream.str());
					AbcG::OFaceSetSchema::Sample faceSetSample(Abc::Int32ArraySample(&faceSetVec.front(), faceSetVec.size()));
					faceSet.getSchema().set(faceSetSample);
				}
			}

			if(mJob->GetOption("exportUVs")){
				//TODO...
			}

            {
            ESS_PROFILE_SCOPE("AlembicPoints::saveCurrentFrameMeshes meshSchema.set");
			meshSchema.set(meshSample);
            }

			if(mi->bNeedDelete){
				delete mi->pMesh;
				mi->bNeedDelete = FALSE;
			}
			mi->pMesh = NULL;
		}
	}
	
	mMeshesToSaveForCurrentFrame.clear();
}