public int FindClosestIndex(MFloatVector pos, float tolerance = 0.001f)
            {
                int resultIndex = -1;
                int areaIndex   = GetAreaIndex(pos);

                if (areas.ContainsKey(areaIndex))
                {
                    List <int> areaIndexList = areas[areaIndex];
                    float      minDist       = float.MaxValue;
                    for (int i = 0; i < areaIndexList.Count; i++)
                    {
                        MFloatVector p = points[areaIndexList[i]];
                        if (Math.Abs(p.y - pos.y) > tolerance || Math.Abs(p.x - pos.x) > tolerance || Math.Abs(p.z - pos.z) > tolerance)
                        {
                            //如果某一个轴已经超过tolerance,没救告辞
                            continue;
                        }
                        float dist = p.minus(pos).length;
                        if (minDist > dist)
                        {
                            resultIndex = i;
                            minDist     = dist;
                        }
                    }
                }


                return(resultIndex);
            }
        public override void writeFloatVectorArray(MFloatVectorArray array)
        {
            if (myCurrentChanelNode != null)
            {
                uint    size     = array.length;
                XmlNode sizeNode = myXmlDoc.CreateElement(sizeTag);
                sizeNode.InnerText = Convert.ToString(size);
                myCurrentChanelNode.AppendChild(sizeNode);

                XmlNode arrayNode = myXmlDoc.CreateElement(floatVectorArrayTag);
                myCurrentChanelNode.AppendChild(arrayNode);

                for (int i = 0; i < size; i++)
                {
                    MFloatVector value     = array[i];
                    XmlNode      valueNode = myXmlDoc.CreateElement("value");
                    arrayNode.AppendChild(valueNode);

                    XmlNode xValueNode = myXmlDoc.CreateElement("x");
                    xValueNode.InnerText = Convert.ToString(value.x);
                    valueNode.AppendChild(xValueNode);

                    XmlNode yValueNode = myXmlDoc.CreateElement("y");
                    yValueNode.InnerText = Convert.ToString(value.y);
                    valueNode.AppendChild(yValueNode);

                    XmlNode zValueNode = myXmlDoc.CreateElement("z");
                    zValueNode.InnerText = Convert.ToString(value.z);
                    valueNode.AppendChild(zValueNode);
                }
            }

            return;
        }
        public override void readFloatVectorArray(MFloatVectorArray array, uint arraySize)
        {
            Trace.Assert(myCurrentChanelNode != null);

            XmlNode     floatVectorArrayNode = myCurrentChanelNode.SelectSingleNode(floatVectorArrayTag);
            XmlNodeList valueNodeList        = floatVectorArrayNode.SelectNodes("value");
            uint        i = 0;

            array.clear();
            array.length = arraySize;

            foreach (XmlNode valueNode in valueNodeList)
            {
                XmlNode xNode  = valueNode.SelectSingleNode("x");
                double  valueX = Convert.ToDouble(xNode.InnerText);

                XmlNode yNode  = valueNode.SelectSingleNode("y");
                double  valuey = Convert.ToDouble(yNode.InnerText);

                XmlNode zNode  = valueNode.SelectSingleNode("z");
                double  valuez = Convert.ToDouble(zNode.InnerText);

                MFloatVector v = new MFloatVector((float)valueX, (float)valuey, (float)valuez);
                array.set(v, i);
                i++;
            }
            return;
        }
            int GetAreaIndex(MFloatVector pos)
            {
                int ai_x      = (int)((pos.x - xMin) / xWidth / gridStep);
                int ai_y      = (int)((pos.y - yMin) / yWidth / gridStep);
                int ai_z      = (int)((pos.z - zMin) / zWidth / gridStep);
                int areaIndex = ai_x + ai_y * xAreaCount + ai_z * xAreaCount * yAreaCount;

                return(areaIndex);
            }
示例#5
0
 public static float[] toArray(this MFloatVector mFloatVector)
 {
     float[] array = new float[3];
     for (uint index = 0; index < 3; index++)
     {
         array[index] = mFloatVector[index];
     }
     return(array);
 }
示例#6
0
        public override bool compute(MPlug plug, MDataBlock dataBlock)
        //
        //	Description:
        //		Computes a color value
        //	from a surface noraml angle.
        //
        {
            if ((plug.notEqual(aOutColor)) && (plug.parent.notEqual(aOutColor)))
            {
                return(false);
            }

            MFloatVector resultColor;

            MFloatVector walkable      = dataBlock.inputValue(aColor1).asFloatVector;
            MFloatVector nonWalkable   = dataBlock.inputValue(aColor2).asFloatVector;
            MFloatVector surfaceNormal = dataBlock.inputValue(aTriangleNormalCamera).asFloatVector;
            MFloatMatrix viewMatrix    = dataBlock.inputValue(aMatrixEyeToWorld).asFloatMatrix;
            float        angle         = dataBlock.inputValue(aAngle).asFloat;

            // Normalize the view vector
            //
            surfaceNormal.normalize();
            MFloatVector WSVector = surfaceNormal.multiply(viewMatrix);

            // find dot product
            //
            float scalarNormal = WSVector.multiply(new MFloatVector(0, 1, 0));

            // take the absolute value
            //
            if (scalarNormal < 0.0)
            {
                scalarNormal *= -1.0f;
            }

            if (Math.Cos(angle * AWdegreesToRadians) < scalarNormal)
            {
                resultColor = walkable;
            }
            else
            {
                resultColor = nonWalkable;
            }

            // set ouput color attribute
            //
            MDataHandle  outColorHandle = dataBlock.outputValue(aOutColor);
            MFloatVector outColor       = outColorHandle.asFloatVector;

            outColor = resultColor;
            outColorHandle.setClean();

            return(true);
        }
示例#7
0
        public static MayaM2Vertex Create(MFloatPoint pos, MFloatVector norm, List <Tuple <float, float> > uv,
                                          List <Tuple <MayaM2Bone, double> > weights, List <MayaM2Vertex> globalVertexList)
        {
            var compositeKey = new Tuple <MFloatPoint, MFloatVector, List <Tuple <float, float> > >(
                pos,
                norm,
                uv);

            if (_instances.ContainsKey(compositeKey))
            {
                return(_instances[compositeKey]);
            }
            var vert = new MayaM2Vertex
            {
                Position      = pos,
                Normal        = norm,
                UvCoordinates = uv,
                Weights       = weights
            };

            _instances[compositeKey] = vert;
            globalVertexList.Add(vert);
            return(vert);
        }
示例#8
0
 public static C3Vector AxisInvert(MFloatVector point) => AxisInvert(point.x, point.y, point.z);
        public override void readFloatVectorArray(MFloatVectorArray array, uint arraySize)
        {
            Trace.Assert(myCurrentChanelNode != null);

            XmlNode floatVectorArrayNode = myCurrentChanelNode.SelectSingleNode(floatVectorArrayTag);
            XmlNodeList valueNodeList = floatVectorArrayNode.SelectNodes("value");
            uint i = 0;
            array.clear();
            array.length = arraySize;

            foreach (XmlNode valueNode in valueNodeList)
            {
                XmlNode xNode = valueNode.SelectSingleNode("x");
                double valueX = Convert.ToDouble(xNode.InnerText);

                XmlNode yNode = valueNode.SelectSingleNode("y");
                double valuey = Convert.ToDouble(yNode.InnerText);

                XmlNode zNode = valueNode.SelectSingleNode("z");
                double valuez = Convert.ToDouble(zNode.InnerText);

                MFloatVector v = new MFloatVector((float)valueX, (float)valuey, (float)valuez);
                array.set(v, i);
                i++;
            }
            return;
        }
示例#10
0
        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 {
                }
            }
        }
示例#11
0
 public static string toString(this MFloatVector mFloatVector)
 {
     return(mFloatVector == null ? "" : mFloatVector.toArray().toString());
 }
示例#12
0
        private MVector direction(MDataBlock block)
        {
            MFloatVector fV = block.inputValue(mDirection).asFloatVector;

            return(new MVector(fV.x, fV.y, fV.z));
        }