private void GetTransform(MFnTransform mFnTransform, ref float[] position, ref float[] rotationQuaternion, ref float[] rotation, ref BabylonVector3.EulerRotationOrder rotationOrder, ref float[] scaling) { var transformationMatrix = new MTransformationMatrix(mFnTransform.transformationMatrix); var mayaRotationOrder = 0; MGlobal.executeCommand($"getAttr {mFnTransform.fullPathName}.rotateOrder", out mayaRotationOrder); rotationOrder = Tools.ConvertMayaRotationOrder((MEulerRotation.RotationOrder)mayaRotationOrder); position = transformationMatrix.getTranslation(); rotationQuaternion = transformationMatrix.getRotationQuaternion(); rotation = transformationMatrix.getRotation(); scaling = transformationMatrix.getScale(); // Switch coordinate system at object level position[2] *= -1; rotationQuaternion[0] *= -1; rotationQuaternion[1] *= -1; rotation[0] *= -1; rotation[1] *= -1; rotationOrder = Tools.InvertRotationOrder(rotationOrder); // Apply unit conversion factor to meter position[0] *= scaleFactorToMeters; position[1] *= scaleFactorToMeters; position[2] *= scaleFactorToMeters; }
/// <summary> /// Default space is transform /// Default rotation order is YXZ /// </summary> /// <param name="mTransformationMatrix"></param> /// <returns></returns> public static float[] getRotation(this MTransformationMatrix mTransformationMatrix) { double[] rotation = new double[3]; int order = (int)MTransformationMatrix.RotationOrder.kYXZ; mTransformationMatrix.getRotation(rotation, out order); return(Array.ConvertAll(rotation, item => (float)item));; }
void printTransformData(MDagPath dagPath, bool quiet) { MObject transformNode = null; try { transformNode = dagPath.transform; } catch (System.Exception) { // This node has no transform - i.e., it's the world node // return; } MFnDagNode transform = null; try { transform = new MFnDagNode(transformNode); } catch (System.Exception) { return; } MTransformationMatrix matrix = new MTransformationMatrix(transform.transformationMatrix); if (!quiet) { MGlobal.displayInfo(" translation: " + MVectorToString(matrix.translation(MSpace.Space.kWorld)) + Environment.NewLine); } double[] threeDoubles = new double[3]; int rOrder = 0; matrix.getRotation(threeDoubles, out rOrder, MSpace.Space.kWorld); if (!quiet) { MGlobal.displayInfo(string.Format(" rotation: [%f, %f, %f]\n", threeDoubles[0], threeDoubles[1], threeDoubles[2])); } matrix.getScale(threeDoubles, MSpace.Space.kWorld); if (!quiet) { MGlobal.displayInfo(string.Format(" scale: [%f, %f, %f]\n", threeDoubles[0], threeDoubles[1], threeDoubles[2])); } }
private void GetTransform(MFnTransform mFnTransform, ref float[] position, ref float[] rotationQuaternion, ref float[] rotation, ref float[] scaling) { var transformationMatrix = new MTransformationMatrix(mFnTransform.transformationMatrix); position = transformationMatrix.getTranslation(); rotationQuaternion = transformationMatrix.getRotationQuaternion(); rotation = transformationMatrix.getRotation(); scaling = transformationMatrix.getScale(); // Switch coordinate system at object level position[2] *= -1; rotationQuaternion[0] *= -1; rotationQuaternion[1] *= -1; rotation[0] *= -1; rotation[1] *= -1; }
private void ExportTransform(BabylonAbstractMesh babylonAbstractMesh, MFnDagNode mFnDagNode) { // Position / rotation / scaling var transformationMatrix = new MTransformationMatrix(mFnDagNode.transformationMatrix); babylonAbstractMesh.position = transformationMatrix.getTranslation(); if (_exportQuaternionsInsteadOfEulers) { babylonAbstractMesh.rotationQuaternion = transformationMatrix.getRotationQuaternion(); } else { babylonAbstractMesh.rotation = transformationMatrix.getRotation(); } babylonAbstractMesh.scaling = transformationMatrix.getScale(); }
public void ResetLights() { //<AmbientLight Color="White" /> //<DirectionalLight Color="White" Direction="-1,-1,-1" /> //<PointLight Color="White" ConstantAttenuation="1" LinearAttenuation="1" Position="0,0,0" QuadraticAttenuation="1" Range="0" /> //<SpotLight Color="White" ConstantAttenuation="1" Direction="-1,-1,-1" InnerConeAngle="10" LinearAttenuation="1" OuterConeAngle="10" Position="0,0,0" QuadraticAttenuation="1" Range="0" /> lights.Children.Clear(); MItDag dagIterator = new MItDag(MItDag.TraversalType.kDepthFirst, MFn.Type.kLight); for ( ; !dagIterator.isDone; dagIterator.next()) { MDagPath lightPath = new MDagPath(); dagIterator.getPath(lightPath); MFnLight light = new MFnLight(lightPath); bool isAmbient = light.lightAmbient; MColor mcolor = light.color; Color color = Color.FromScRgb(1.0f, mcolor.r, mcolor.g, mcolor.b); if (isAmbient) { AmbientLight ambient = new AmbientLight(color); lights.Children.Add(ambient); continue; } MFloatVector lightDirection = light.lightDirection(0, MSpace.Space.kWorld); Vector3D direction = new Vector3D(lightDirection.x, lightDirection.y, lightDirection.z); bool isDiffuse = light.lightDiffuse; try { MFnDirectionalLight dirLight = new MFnDirectionalLight(lightPath); DirectionalLight directional = new DirectionalLight(color, direction); lights.Children.Add(directional); continue; } catch { } MObject transformNode = lightPath.transform; MFnDagNode transform = new MFnDagNode(transformNode); MTransformationMatrix matrix = new MTransformationMatrix(transform.transformationMatrix); double [] threeDoubles = new double [3]; int rOrder = 0; //MTransformationMatrix.RotationOrder rOrder ; matrix.getRotation(threeDoubles, out rOrder, MSpace.Space.kWorld); matrix.getScale(threeDoubles, MSpace.Space.kWorld); MVector pos = matrix.getTranslation(MSpace.Space.kWorld); Point3D position = new Point3D(pos.x, pos.y, pos.z); try { MFnPointLight pointLight = new MFnPointLight(lightPath); PointLight point = new PointLight(color, position); //point.ConstantAttenuation =pointLight. ; // LinearAttenuation / QuadraticAttenuation //point.Range =pointLight.rayDepthLimit ; lights.Children.Add(point); continue; } catch { } try { MFnSpotLight spotLight = new MFnSpotLight(lightPath); MAngle InnerConeAngle = new MAngle(spotLight.coneAngle); MAngle OuterConeAngle = new MAngle(spotLight.penumbraAngle); SpotLight spot = new SpotLight(color, position, direction, OuterConeAngle.asDegrees, InnerConeAngle.asDegrees); spot.ConstantAttenuation = spotLight.dropOff; // LinearAttenuation / QuadraticAttenuation //spot.Range =spotLight.rayDepthLimit ; lights.Children.Add(spot); continue; } catch { } } }
public void ResetLights() { //<AmbientLight Color="White" /> //<DirectionalLight Color="White" Direction="-1,-1,-1" /> //<PointLight Color="White" ConstantAttenuation="1" LinearAttenuation="1" Position="0,0,0" QuadraticAttenuation="1" Range="0" /> //<SpotLight Color="White" ConstantAttenuation="1" Direction="-1,-1,-1" InnerConeAngle="10" LinearAttenuation="1" OuterConeAngle="10" Position="0,0,0" QuadraticAttenuation="1" Range="0" /> lights.Children.Clear () ; MItDag dagIterator =new MItDag (MItDag.TraversalType.kDepthFirst, MFn.Type.kLight) ; for ( ; !dagIterator.isDone ; dagIterator.next () ) { MDagPath lightPath =new MDagPath () ; dagIterator.getPath (lightPath) ; MFnLight light =new MFnLight (lightPath) ; bool isAmbient =light.lightAmbient ; MColor mcolor =light.color ; Color color =Color.FromScRgb (1.0f, mcolor.r, mcolor.g, mcolor.b) ; if ( isAmbient ) { AmbientLight ambient =new AmbientLight (color) ; lights.Children.Add (ambient) ; continue ; } MFloatVector lightDirection =light.lightDirection (0, MSpace.Space.kWorld) ; Vector3D direction =new Vector3D (lightDirection.x, lightDirection.y, lightDirection.z) ; bool isDiffuse =light.lightDiffuse ; try { MFnDirectionalLight dirLight =new MFnDirectionalLight (lightPath) ; DirectionalLight directional =new DirectionalLight (color, direction) ; lights.Children.Add (directional) ; continue ; } catch { } MObject transformNode =lightPath.transform ; MFnDagNode transform =new MFnDagNode (transformNode) ; MTransformationMatrix matrix =new MTransformationMatrix (transform.transformationMatrix) ; double [] threeDoubles =new double [3] ; int rOrder =0 ; //MTransformationMatrix.RotationOrder rOrder ; matrix.getRotation (threeDoubles, out rOrder, MSpace.Space.kWorld) ; matrix.getScale (threeDoubles, MSpace.Space.kWorld) ; MVector pos =matrix.getTranslation (MSpace.Space.kWorld) ; Point3D position =new Point3D (pos.x, pos.y, pos.z) ; try { MFnPointLight pointLight =new MFnPointLight (lightPath) ; PointLight point =new PointLight (color, position) ; //point.ConstantAttenuation =pointLight. ; // LinearAttenuation / QuadraticAttenuation //point.Range =pointLight.rayDepthLimit ; lights.Children.Add (point) ; continue ; } catch { } try { MFnSpotLight spotLight =new MFnSpotLight (lightPath) ; MAngle InnerConeAngle =new MAngle (spotLight.coneAngle) ; MAngle OuterConeAngle =new MAngle (spotLight.penumbraAngle) ; SpotLight spot =new SpotLight (color, position, direction, OuterConeAngle.asDegrees, InnerConeAngle.asDegrees) ; spot.ConstantAttenuation =spotLight.dropOff ; // LinearAttenuation / QuadraticAttenuation //spot.Range =spotLight.rayDepthLimit ; lights.Children.Add (spot) ; continue ; } catch { } } }
void printTransformData(MDagPath dagPath, bool quiet) { MObject transformNode = null; try { transformNode = dagPath.transform; } catch (System.Exception) { // This node has no transform - i.e., it's the world node // return; } MFnDagNode transform = null; try { transform = new MFnDagNode(transformNode); } catch (System.Exception ) { return; } MTransformationMatrix matrix = new MTransformationMatrix(transform.transformationMatrix); if (!quiet) { MGlobal.displayInfo(" translation: " + MVectorToString(matrix.translation(MSpace.Space.kWorld)) + Environment.NewLine); } double[] threeDoubles = new double[3]; int rOrder = 0; matrix.getRotation (threeDoubles, out rOrder, MSpace.Space.kWorld); if (!quiet) { MGlobal.displayInfo(string.Format(" rotation: [%f, %f, %f]\n", threeDoubles[0], threeDoubles[1], threeDoubles[2])); } matrix.getScale (threeDoubles, MSpace.Space.kWorld); if (!quiet) { MGlobal.displayInfo(string.Format(" scale: [%f, %f, %f]\n", threeDoubles[0], threeDoubles[1], threeDoubles[2])); } }