Пример #1
0
        public static bool GenerateBoxSubMesh(CSGBrushSubMesh subMesh, UnityEngine.Vector3 min, UnityEngine.Vector3 max, CSGSurfaceAsset[] surfaceAssets, SurfaceDescription[] surfaceDescriptions)
        {
            if (!BoundsExtensions.IsValid(min, max))
            {
                return(false);
            }

            if (surfaceAssets.Length != 6 ||
                surfaceDescriptions.Length != 6)
            {
                return(false);
            }

            if (min.x > max.x)
            {
                float x = min.x; min.x = max.x; max.x = x;
            }
            if (min.y > max.y)
            {
                float y = min.y; min.y = max.y; max.y = y;
            }
            if (min.z > max.z)
            {
                float z = min.z; min.z = max.z; max.z = z;
            }

            subMesh.Polygons  = CreateBoxAssetPolygons(surfaceAssets, surfaceDescriptions);
            subMesh.HalfEdges = boxHalfEdges.ToArray();
            subMesh.Vertices  = BrushMeshFactory.CreateBoxVertices(min, max);
            return(true);
        }
Пример #2
0
        public static bool GenerateBoxAsset(CSGBrushMeshAsset brushMeshAsset, UnityEngine.Vector3 min, UnityEngine.Vector3 max, CSGSurfaceAsset[] surfaceAssets, SurfaceFlags surfaceFlags = SurfaceFlags.None)
        {
            if (!BoundsExtensions.IsValid(min, max))
            {
                brushMeshAsset.Clear();
                return(false);
            }

            if (surfaceAssets.Length != 6)
            {
                brushMeshAsset.Clear();
                return(false);
            }

            if (min.x > max.x)
            {
                float x = min.x; min.x = max.x; max.x = x;
            }
            if (min.y > max.y)
            {
                float y = min.y; min.y = max.y; max.y = y;
            }
            if (min.z > max.z)
            {
                float z = min.z; min.z = max.z; max.z = z;
            }

            brushMeshAsset.Polygons  = CreateBoxAssetPolygons(surfaceAssets, surfaceFlags);
            brushMeshAsset.HalfEdges = boxHalfEdges.ToArray();
            brushMeshAsset.Vertices  = BrushMeshFactory.CreateBoxVertices(min, max);
            brushMeshAsset.CalculatePlanes();
            brushMeshAsset.SetDirty();
            return(true);
        }
Пример #3
0
 public static Float3 FromUnity(UnityEngine.Vector3 vector)
 {
     return(new Float3
     {
         X = vector.x,
         Y = vector.y,
         Z = vector.z
     });
 }
Пример #4
0
        public static bool IsValid(UnityEngine.Vector3 min, UnityEngine.Vector3 max)
        {
            const float kMinSize = 0.0001f;

            if (Mathf.Abs(max.x - min.x) < kMinSize ||
                Mathf.Abs(max.y - min.y) < kMinSize ||
                Mathf.Abs(max.z - min.z) < kMinSize ||
                float.IsInfinity(min.x) || float.IsInfinity(min.y) || float.IsInfinity(min.z) ||
                float.IsInfinity(max.x) || float.IsInfinity(max.y) || float.IsInfinity(max.z) ||
                float.IsNaN(min.x) || float.IsNaN(min.y) || float.IsNaN(min.z) ||
                float.IsNaN(max.x) || float.IsNaN(max.y) || float.IsNaN(max.z))
            {
                return(false);
            }
            return(true);
        }
Пример #5
0
        public static bool GenerateBoxAsset(CSGBrushMeshAsset brushMeshAsset, UnityEngine.Vector3 min, UnityEngine.Vector3 max, CSGSurfaceAsset[] surfaceAssets, SurfaceDescription[] surfaceDescriptions)
        {
            if (!BoundsExtensions.IsValid(min, max))
            {
                brushMeshAsset.Clear();
                Debug.LogError("bounds is of an invalid size " + (max - min));
                return(false);
            }

            if (surfaceDescriptions == null || surfaceDescriptions.Length != 6)
            {
                brushMeshAsset.Clear();
                Debug.LogError("surfaceDescriptions needs to be an array of length 6");
                return(false);
            }

            if (surfaceAssets == null || surfaceAssets.Length != 6)
            {
                brushMeshAsset.Clear();
                Debug.LogError("surfaceAssets needs to be an array of length 6");
                return(false);
            }

            if (min.x > max.x)
            {
                float x = min.x; min.x = max.x; max.x = x;
            }
            if (min.y > max.y)
            {
                float y = min.y; min.y = max.y; max.y = y;
            }
            if (min.z > max.z)
            {
                float z = min.z; min.z = max.z; max.z = z;
            }

            brushMeshAsset.Polygons  = CreateBoxAssetPolygons(surfaceAssets, surfaceDescriptions);
            brushMeshAsset.HalfEdges = boxHalfEdges.ToArray();
            brushMeshAsset.Vertices  = BrushMeshFactory.CreateBoxVertices(min, max);
            brushMeshAsset.CalculatePlanes();
            brushMeshAsset.SetDirty();
            return(true);
        }
Пример #6
0
        public static CSGBrushMeshAsset CreateBoxAsset(UnityEngine.Vector3 min, UnityEngine.Vector3 max, CSGSurfaceAsset[] surfaceAssets, SurfaceFlags surfaceFlags = SurfaceFlags.None)
        {
            if (min.x == max.x || min.y == max.y || min.z == max.z)
            {
                return(null);
            }

            if (surfaceAssets.Length != 6)
            {
                return(null);
            }

            var brushMeshAsset = UnityEngine.ScriptableObject.CreateInstance <CSGBrushMeshAsset>();

            brushMeshAsset.name = "Box";
            if (!GenerateBoxAsset(brushMeshAsset, min, max, surfaceAssets, surfaceFlags))
            {
                CSGObjectUtility.SafeDestroy(brushMeshAsset);
            }
            return(brushMeshAsset);
        }
Пример #7
0
        /// <summary>
        /// It's purpose is to wrap LoadAgent(agentName, pos)
        /// </summary>
        /// <returns>Failure, success, or the continuation of a coroutine which attempts to establish a connection with the OpenCog embodiment.</returns>
        /// <param name="agentName">The name of the agent to instantiate.</param>
        private IEnumerator LoadAgent(string agentName)
        {
            //get the player object, if it exists
            UnityEngine.GameObject playerObject = GameObject.FindGameObjectWithTag("Player");

            //if it does not exist, we cannot run this wrapper
            if (playerObject == null)
            {
                Debug.LogError("No object tagged with player.");
                yield break;
            }

            //we want to place it ahead of the player
            UnityEngine.Vector3 eulerAngle = playerObject.transform.rotation.eulerAngles;
            UnityEngine.Vector3 position   = playerObject.transform.position;

            //find a position slightly in front of us
            float zFront = 3.0f * (float)Math.Cos((eulerAngle.y / 180) * Math.PI);
            float xFront = 3.0f * (float)Math.Sin((eulerAngle.y / 180) * Math.PI);

            //add the position data together.
            UnityEngine.Vector3 newPos = new Vector3(position.x + xFront, position.y + 2, position.z + zFront);

            // TODO [MULTI-AVATAR] Currently we use the tag "player". However, when there are multiple
            // players in the world, we need to figure out a way to identify.
            // Set agentType and agentTraits in the future.
            // leave agentType and agentTraits to null just for test.
            //get data about the player
            string masterId   = playerObject.GetInstanceID().ToString();
            string masterName = playerObject.name;

            //Attack of the top level management decisions!
            yield return(StartCoroutine(GameManager.entity.load.AtRunTime(newPos, _NPCAgent, agentName, masterName, masterId)));

            //this is unnecessary
            //yield break;
        }
Пример #8
0
    // Start is called before the first frame update
    void Start()
    {
        var      p         = new MVector3(1, 0, 0);
        var      aaaaa     = new UnityEngine.Quaternion(1, 1, 1, 1);
        var      ptemp     = new UnityEngine.Vector3(0.5f, 0, 0);
        var      a         = aaaaa * aaaaa * aaaaa * ptemp;
        Matrix33 rotation  = Matrix33.AngleAxis(45, new MVector3(0, 0, 1));
        Matrix33 rotation2 = Matrix33.AngleAxis(-45, new MVector3(0, 0, 1));

        Debug.Log(p * rotation);
        Debug.Log(p * rotation * rotation2);
        Debug.Log(p * (rotation * rotation2));

        Debug.Log("-------------------------------------------------------------");
        Matrix44 mul = Matrix44.AngleAxisTranslate(45, new MVector3(0, 0, 1), new MVector3(1, 1, 0));

        Debug.Log(p * mul);
        Debug.Log(p * (mul * mul.Inverse()));

        Debug.Log("-------------------------------------------------------------");
        Matrix44 r          = Matrix44.AngleAxis(45, new MVector3(0, 0, 1));
        Matrix44 t          = Matrix44.Translate(new MVector3(1, 1, 0));
        Matrix44 composite  = r * t;
        Matrix44 composite2 = t.Inverse() * r.Inverse();

        Debug.Log(p * composite);
        Debug.Log(p * composite * composite2);
        Debug.Log(p * composite * composite.Inverse());

        mMesh     = GetComponent <MeshFilter>().mesh;
        mVertices = mMesh.vertices;
        mNormals  = mMesh.normals;


        var temp = new Matrix33(10, 0, 0, 0, 10, 0, 0, 0, 1);

        var temp2       = temp.Inverse();
        var tempInverse = new Matrix33(0, 0, 0, 0, 0, 0, -3, -4, 1);

        p   = new MVector3(0, 0, 1);
        p   = p * temp;
        p.z = 1;
        p   = p * tempInverse;
        var t3 = temp * tempInverse;

        t = Matrix44.Translate(new MVector3(3, 4, 5));
        r = Matrix44.AngleAxis(30, new MVector3(0, 1, 0));
        var s = Matrix44.Scale(new MVector3(0.5f, 2, 1));

        p = new MVector3(1, 1, 1);
        var p1 = p * s * r * t;

        p = p1 * t.Inverse() * r.Inverse() * s.Inverse();

        var ray2d1 = new MRay(new MVector3(1, -1, 0), new MVector3(1, 1, 0));

        var   aaa  = ray2d1.GetNearestPos(new MVector3(1, 1, 0));
        float aaaa = 1;

        var plane1 = new MPlane(new MVector3(1, 1, 1), 1);
        var pos1   = plane1.GetNearestPos(new MVector3(5, 5, 5));
        var pos2   = plane1.GetNearestPos(new MVector3(-5, -5, -5));

        var plane2 = new MPlane(new MVector3(-1, -1, -1), -1);
        var pos3   = plane2.GetNearestPos(new MVector3(5, 5, 5));
        var pos4   = plane2.GetNearestPos(new MVector3(-5, -5, -5));

        var plane3 = new MPlane(new MVector3(-1, -1, -1), 1);
        var pos5   = plane3.GetNearestPos(new MVector3(5, 5, 5));
        var pos6   = plane3.GetNearestPos(new MVector3(-5, -5, -5));

        // 三角形测试
        pos1 = new MVector3(0, 0, 3);
        pos2 = new MVector3(0, 1, 3);
        pos3 = new MVector3(1, 0, 3);
        var triangle1 = new Triangle(pos1, pos2, pos3);
        var result    = triangle1.InclusionPos(pos1);
        var targetPos = MVector3.zero;

        result = triangle1.InclusionPos(pos2);
        result = triangle1.GetGravityPos(pos2, out targetPos);
        result = triangle1.InclusionPos(pos3);
        result = triangle1.GetGravityPos(pos3, out targetPos);
        float dis = 0;

        result = triangle1.Raycast(new MRay(new MVector3(0.4f, 0.6f, -0.2567f), new MVector3(0, 0, 1)), out dis);
        pos4   = new MVector3(0.5f, 0.5f, 3);
        result = triangle1.InclusionPos(pos4);
        result = triangle1.GetGravityPos(pos4, out targetPos);
        result = triangle1.GetGravityPos(pos4, out targetPos);
        pos4   = new MVector3(0.4f, 0.4f, 0.1f);
        result = triangle1.InclusionPos(pos4);
        result = triangle1.GetGravityPos(pos4, out targetPos);
        result = triangle1.GetGravityPos(pos4, out targetPos);
        pos4   = new MVector3(0.6f, 0.6f, 3);
        result = triangle1.InclusionPos(pos4);
        result = triangle1.GetGravityPos(pos4, out targetPos);
        result = triangle1.GetGravityPos(pos4, out targetPos);
        pos4   = new MVector3(-0.1f, -0.1f, 3);
        result = triangle1.InclusionPos(pos4);
        result = triangle1.GetGravityPos(pos4, out targetPos);
        result = triangle1.GetGravityPos(pos4, out targetPos);
        result = triangle1.InclusionPos(pos3);
        result = triangle1.GetGravityPos(pos3, out targetPos);
        result = triangle1.GetGravityPos(pos3, out targetPos);
        var tempxxx = 0;

        Circle2D c1 = new Circle2D(MVector2.zero, 1);
        var      t1 = c1.GetNearestPos(new MVector2(2, 0));
        var      t2 = c1.GetNearestPos(new MVector2(0.5f, 0));

        tempxxx = 0;

        var      r1 = new MRay2D(new MVector2(1, 1), new MVector2(0, -1));
        var      r2 = new MRay2D(new MVector2(10, 0), new MVector2(1, 0));
        MVector2 r12v;
        bool     r12r = r1.Interact(r2, out r12v);

        float c10, c11;
        bool  r10 = c1.IntersectRay(r1, out c10, out c11);

        tempxxx = 0;
    }
Пример #9
0
    public bool vision_set(ImageSamples currSamples)
    {
        try
        {
            if (!bodyTransitionReady)
            {
                return(true);
            }

            if (!visionEnabled)
            {
                Debug.Log("Vision modality not enabled. Cannot set");
                return(false);
            }

            if (currSamples == null)
            {
                return(false);
            }

            var currSample = currSamples.Samples[0];


            var currShape = currSample.DataShape;
            // Debug.Log($"{currShape[0]}, {currShape[1]}");
#if ANIMUS_USE_OPENCV
            if (!initMats)
            {
                yuv      = new Mat((int)(currShape[1] * 1.5), (int)currShape[0], CvType.CV_8UC1);
                rgb      = new Mat();
                initMats = true;
            }

            if (currSample.Data.Length != currShape[0] * currShape[1] * 1.5)
            {
                return(true);
            }

            if (currShape[0] <= 100 || currShape[1] <= 100)
            {
                return(true);
            }
            // Debug.Log("cvt Color ops");

            yuv.put(0, 0, currSample.Data.ToByteArray());

            Imgproc.cvtColor(yuv, rgb, Imgproc.COLOR_YUV2BGR_I420);

            if (_imageDims.Count == 0 || currShape[0] != _imageDims[0] || currShape[1] != _imageDims[1] || currShape[2] != _imageDims[2])
            {
                _imageDims = currShape;
                var scaleX = (float)_imageDims[0] / (float)_imageDims[1];

                Debug.Log("Resize triggered. Setting texture resolution to " + currShape[0] + "x" + currShape[1]);
                Debug.Log("Setting horizontal scale to " + scaleX + " " + (float)_imageDims[0] + " " + (float)_imageDims[1]);

                UnityEngine.Vector3 currentScale = _leftPlane.transform.localScale;
                currentScale.x = scaleX;

                _leftPlane.transform.localScale = currentScale;
                _leftTexture = new Texture2D(rgb.width(), rgb.height(), TextureFormat.ARGB32, false)
                {
                    wrapMode = TextureWrapMode.Clamp
                };

                // _rightPlane.transform.localScale = currentScale;
                // _rightTexture = new Texture2D(rgb.width(), rgb.height(), TextureFormat.ARGB32, false)
                // {
                //  wrapMode = TextureWrapMode.Clamp
                // };
//              return true;
            }
            // Debug.Log("matToTexture2D");

            //TODO apply stereo images
            Utils.matToTexture2D(rgb, _leftTexture);
            _leftRenderer.material.mainTexture = _leftTexture;
#endif
        }
        catch (Exception e)
        {
            Debug.Log(e);
        }
//      Debug.Log("done vision set");
        return(true);
    }
 /// <summary>
 /// Inverses the transformation provided from world space to the local space of the component which this NetworkP2P
 /// component is attached to.
 /// </summary>
 /// <param name="pos">The position of the transform that you want to apply the transformation on.</param>
 /// <param name="rot">The rotation of the transform that you want to apply the transformation on.</param>
 public override void InverseTransform(ref UnityEngine.Vector3 pos, ref Quaternion rot)
 {
     pos = transform.InverseTransformPoint(pos);
     rot = Quaternion.Inverse(transform.rotation) * rot;
 }
Пример #11
0
        /// <summary>
        /// Creates a cube <see cref="RealtimeCSG.Foundation.BrushMesh"/> with bounds defined by <paramref name="min"/> and <paramref name="max"/>, its <paramref name="layers"/> and optional <paramref name="surfaceFlags"/>
        /// </summary>
        /// <remarks><note>These methods are a work in progress and may change somewhat over time</note></remarks>
        /// <param name="min">The corner of the cube with the smallest x,y,z values</param>
        /// <param name="max">The corner of the cube with the largest x,y,z values</param>
        /// <param name="layers">The <see cref="RealtimeCSG.Foundation.SurfaceLayers"/> that define how the surfaces of this cube are rendered or if they need to be part of a collider etc.</param>
        /// <param name="surfaceFlags">Optional flags that modify surface behavior.</param>
        /// <returns>A <see cref="RealtimeCSG.Foundation.BrushMesh"/> on success, null on failure</returns>
        public static BrushMesh CreateCube(UnityEngine.Vector3 min, UnityEngine.Vector3 max, SurfaceLayers layers, SurfaceFlags surfaceFlags = SurfaceFlags.None)
        {
            if (min.x == max.x || min.y == max.y || min.z == max.z)
            {
                return(null);
            }

            if (min.x > max.x)
            {
                float x = min.x; min.x = max.x; max.x = x;
            }
            if (min.y > max.y)
            {
                float y = min.y; min.y = max.y; max.y = y;
            }
            if (min.z > max.z)
            {
                float z = min.z; min.z = max.z; max.z = z;
            }

            var surfaceMatrices = new[]
            {
                // left/right
                new UVMatrix {
                    U = new Vector4(-1, 0, 0, -min.x), V = new Vector4(0, 1, 0, min.y)
                },
                new UVMatrix {
                    U = new Vector4(1, 0, 0, min.x), V = new Vector4(0, 1, 0, min.y)
                },

                // front/back
                new UVMatrix {
                    U = new Vector4(0, 0, 1, min.z), V = new Vector4(0, 1, 0, min.y)
                },
                new UVMatrix {
                    U = new Vector4(0, 0, -1, -min.z), V = new Vector4(0, 1, 0, min.y)
                },

                // top/down
                new UVMatrix {
                    U = new Vector4(-1, 0, 0, -min.x), V = new Vector4(0, 0, -1, -min.z)
                },
                new UVMatrix {
                    U = new Vector4(1, 0, 0, min.x), V = new Vector4(0, 0, -1, -min.z)
                },
            };

            return(new BrushMesh
            {
                polygons = new[]
                {
                    // left/right
                    new BrushMesh.Polygon {
                        polygonID = 0, firstEdge = 0, edgeCount = 4, surface = new SurfaceDescription {
                            UV0 = surfaceMatrices[0], surfaceFlags = surfaceFlags, smoothingGroup = 0
                        }, layers = layers
                    },
                    new BrushMesh.Polygon {
                        polygonID = 1, firstEdge = 4, edgeCount = 4, surface = new SurfaceDescription {
                            UV0 = surfaceMatrices[1], surfaceFlags = surfaceFlags, smoothingGroup = 0
                        }, layers = layers
                    },

                    // front/back
                    new BrushMesh.Polygon {
                        polygonID = 2, firstEdge = 8, edgeCount = 4, surface = new SurfaceDescription {
                            UV0 = surfaceMatrices[2], surfaceFlags = surfaceFlags, smoothingGroup = 0
                        }, layers = layers
                    },
                    new BrushMesh.Polygon {
                        polygonID = 3, firstEdge = 12, edgeCount = 4, surface = new SurfaceDescription {
                            UV0 = surfaceMatrices[3], surfaceFlags = surfaceFlags, smoothingGroup = 0
                        }, layers = layers
                    },

                    // top/down
                    new BrushMesh.Polygon {
                        polygonID = 4, firstEdge = 16, edgeCount = 4, surface = new SurfaceDescription {
                            UV0 = surfaceMatrices[4], surfaceFlags = surfaceFlags, smoothingGroup = 0
                        }, layers = layers
                    },
                    new BrushMesh.Polygon {
                        polygonID = 5, firstEdge = 20, edgeCount = 4, surface = new SurfaceDescription {
                            UV0 = surfaceMatrices[5], surfaceFlags = surfaceFlags, smoothingGroup = 0
                        }, layers = layers
                    }
                },

                halfEdges = new[]
                {
                    // polygon 0
                    new BrushMesh.HalfEdge {
                        twinIndex = 17, vertexIndex = 0
                    },                                                                                  //  0
                    new BrushMesh.HalfEdge {
                        twinIndex = 8, vertexIndex = 1
                    },                                                                                  //  1
                    new BrushMesh.HalfEdge {
                        twinIndex = 20, vertexIndex = 2
                    },                                                                                  //  2
                    new BrushMesh.HalfEdge {
                        twinIndex = 13, vertexIndex = 3
                    },                                                                                  //  3

                    // polygon 1
                    new BrushMesh.HalfEdge {
                        twinIndex = 10, vertexIndex = 4
                    },                                                                                  //  4
                    new BrushMesh.HalfEdge {
                        twinIndex = 19, vertexIndex = 5
                    },                                                                                  //  5
                    new BrushMesh.HalfEdge {
                        twinIndex = 15, vertexIndex = 6
                    },                                                                                  //  6
                    new BrushMesh.HalfEdge {
                        twinIndex = 22, vertexIndex = 7
                    },                                                                                  //  7

                    // polygon 2
                    new BrushMesh.HalfEdge {
                        twinIndex = 1, vertexIndex = 0
                    },                                                                                  //  8
                    new BrushMesh.HalfEdge {
                        twinIndex = 16, vertexIndex = 4
                    },                                                                                  //  9
                    new BrushMesh.HalfEdge {
                        twinIndex = 4, vertexIndex = 7
                    },                                                                                  // 10
                    new BrushMesh.HalfEdge {
                        twinIndex = 21, vertexIndex = 1
                    },                                                                                  // 11

                    // polygon 3
                    new BrushMesh.HalfEdge {
                        twinIndex = 18, vertexIndex = 3
                    },                                                                                  // 16
                    new BrushMesh.HalfEdge {
                        twinIndex = 3, vertexIndex = 2
                    },                                                                                  // 17
                    new BrushMesh.HalfEdge {
                        twinIndex = 23, vertexIndex = 6
                    },                                                                                  // 18
                    new BrushMesh.HalfEdge {
                        twinIndex = 6, vertexIndex = 5
                    },                                                                                  // 19

                    // polygon 4
                    new BrushMesh.HalfEdge {
                        twinIndex = 9, vertexIndex = 0
                    },                                                                                  // 20
                    new BrushMesh.HalfEdge {
                        twinIndex = 0, vertexIndex = 3
                    },                                                                                  // 21
                    new BrushMesh.HalfEdge {
                        twinIndex = 12, vertexIndex = 5
                    },                                                                                  // 22
                    new BrushMesh.HalfEdge {
                        twinIndex = 5, vertexIndex = 4
                    },                                                                                  // 23

                    // polygon 5
                    new BrushMesh.HalfEdge {
                        twinIndex = 2, vertexIndex = 1
                    },                                                                                  // 12
                    new BrushMesh.HalfEdge {
                        twinIndex = 11, vertexIndex = 7
                    },                                                                                  // 13
                    new BrushMesh.HalfEdge {
                        twinIndex = 7, vertexIndex = 6
                    },                                                                                  // 14
                    new BrushMesh.HalfEdge {
                        twinIndex = 14, vertexIndex = 2
                    }                                                                                   // 15
                },

                vertices = new[]
                {
                    new Vector3(min.x, min.y, min.z),                      // 0
                    new Vector3(min.x, max.y, min.z),                      // 1
                    new Vector3(max.x, max.y, min.z),                      // 2
                    new Vector3(max.x, min.y, min.z),                      // 3

                    new Vector3(min.x, min.y, max.z),                      // 4
                    new Vector3(max.x, min.y, max.z),                      // 5
                    new Vector3(max.x, max.y, max.z),                      // 6
                    new Vector3(min.x, max.y, max.z)                       // 7
                }
            });
        }
Пример #12
0
        /// <summary>
        /// Creates a cube <see cref="RealtimeCSG.Foundation.BrushMesh"/> with <paramref name="size"/> and <paramref name="layers"/> and optional <paramref name="surfaceFlags"/>
        /// </summary>
        /// <remarks><note>These methods are a work in progress and may change somewhat over time</note></remarks>
        /// <param name="size">The size of the cube</param>
        /// <param name="layers">The <see cref="RealtimeCSG.Foundation.SurfaceLayers"/> that define how the surfaces of this cube are rendered or if they need to be part of a collider etc.</param>
        /// <param name="surfaceFlags">Optional flags that modify surface behavior.</param>
        /// <returns>A <see cref="RealtimeCSG.Foundation.BrushMesh"/> on success, null on failure</returns>
        public static BrushMesh CreateCube(UnityEngine.Vector3 size, SurfaceLayers layers, SurfaceFlags surfaceFlags = SurfaceFlags.None)
        {
            var halfSize = size * 0.5f;

            return(CreateCube(-halfSize, halfSize, layers, surfaceFlags));
        }
Пример #13
0
		private IEnumerator LoadAgent (string agentName)
		{
			UnityEngine.GameObject agentClone;
		
			UnityEngine.GameObject playerObject = GameObject.FindGameObjectWithTag ("Player");
			if (playerObject == null) {
				Debug.Log ("No object tagged with player.");
				yield return "No object tagged with player.";
			}

			// Record the player's position and make the OCAvatar spawn near it.
			UnityEngine.Vector3 playerPos = playerObject.transform.position;
			
			//Debug.Log ("PlayerPos = [" + playerPos.x + ", " + playerPos.y + ", " + playerPos.z + "]");

			// Calculate the player's forward direction
			UnityEngine.Vector3 eulerAngle = playerObject.transform.rotation.eulerAngles;
			
			//Debug.Log ("eulerAngle = [" + eulerAngle.x + ", " + eulerAngle.y + ", " + eulerAngle.z + "]");

			float zFront = 3.0f * (float)Math.Cos ((eulerAngle.y / 180) * Math.PI);
			float xFront = 3.0f * (float)Math.Sin ((eulerAngle.y / 180) * Math.PI);
			
			UnityEngine.Vector3 spawnPosition = new UnityEngine.Vector3(playerPos.x + xFront, playerPos.y + 2, playerPos.z + zFront);
			spawnPosition.x = (float)((int)spawnPosition.x);
			spawnPosition.y = (float)((int)spawnPosition.y);
			spawnPosition.z = (float)((int)spawnPosition.z);
			
			//Debug.Log ("spawnPosition = [" + spawnPosition.x + ", " + spawnPosition.y + ", " + spawnPosition.z + "]");

			// Instantiate an OCAvatar in front of the player.
			
			//Debug.Log ("_NPCAgent is" + (_NPCAgent == null ? " null " : " not null"));
			
			agentClone = (GameObject)UnityEngine.Object.Instantiate (_NPCAgent, spawnPosition, Quaternion.identity);
			agentClone.transform.parent = GameObject.Find("Characters").transform;
			OCActionController agiAC = agiAC = agentClone.GetComponent<OCActionController>();
			agiAC.DefaultEndTarget = GameObject.Find("EndPointStub");
			agiAC.DefaultStartTarget = GameObject.Find("StartPointStub");
			
			//Debug.Log ("agentClone is" + (agentClone == null ? " null " : " not null"));

			OCConnectorSingleton connector = OCConnectorSingleton.Instance;
			
			UnityEngine.Debug.Log ("The GUID of our OCC instance in LoadAgent is " + connector.VerificationGuid);
			
			//Debug.Log ("connector is" + (connector == null ? " null " : " not null"));

			if (agentName == "")
				agentName = CreateRandomAgentName ();
			
			//Debug.Log("We shall name him '" + agentName + "'");
        
			agentClone.name = agentName;
        
//			if (agentClone != null) {
//				if (!OCARepository.AddOCA (agentClone)) {
//					// An avatar with given name is already there.
//					yield break;
//				}
//				Debug.Log ("Add avatar[" + agentName + "] to avatar map.");
//			}
			
			// Get the player id as the master id of the avatar.
			// TODO Currently we use the tag "player". However, when there are multiple 
			// players in the world, we need to figure out a way to identify.
			string masterId = playerObject.GetInstanceID ().ToString ();
			string masterName = playerObject.name;
		
			// TODO Set agentType and agentTraits in the future.
			// leave agentType and agentTraits to null just for test.
			connector.Init (agentName, null, null, masterId, masterName);

			yield return StartCoroutine(connector.ConnectOAC());
		
			if (!connector.IsInitialized) {
				// OAC is not loaded normally, destroy the avatar instance.
				Debug.LogError ("Cannot connect to the OAC, avatar loading failed.");
				connector.SaveAndExit ();
				Destroy (agentClone);
				yield break;
			} 
		}
        private IEnumerator LoadAgent(string agentName)
        {
            UnityEngine.GameObject agentClone;

            UnityEngine.GameObject playerObject = GameObject.FindGameObjectWithTag("Player");
            if (playerObject == null)
            {
                Debug.Log("No object tagged with player.");
                yield return("No object tagged with player.");
            }

            // Record the player's position and make the OCAvatar spawn near it.
            UnityEngine.Vector3 playerPos = playerObject.transform.position;

            //Debug.Log ("PlayerPos = [" + playerPos.x + ", " + playerPos.y + ", " + playerPos.z + "]");

            // Calculate the player's forward direction
            UnityEngine.Vector3 eulerAngle = playerObject.transform.rotation.eulerAngles;

            //Debug.Log ("eulerAngle = [" + eulerAngle.x + ", " + eulerAngle.y + ", " + eulerAngle.z + "]");

            float zFront = 3.0f * (float)Math.Cos((eulerAngle.y / 180) * Math.PI);
            float xFront = 3.0f * (float)Math.Sin((eulerAngle.y / 180) * Math.PI);

            UnityEngine.Vector3 spawnPosition = new UnityEngine.Vector3(playerPos.x + xFront, playerPos.y + 2, playerPos.z + zFront);
            spawnPosition.x = (float)((int)spawnPosition.x);
            spawnPosition.y = (float)((int)spawnPosition.y);
            spawnPosition.z = (float)((int)spawnPosition.z);

            //Debug.Log ("spawnPosition = [" + spawnPosition.x + ", " + spawnPosition.y + ", " + spawnPosition.z + "]");

            // Instantiate an OCAvatar in front of the player.

            //Debug.Log ("_NPCAgent is" + (_NPCAgent == null ? " null " : " not null"));

            agentClone = (GameObject)UnityEngine.Object.Instantiate(_NPCAgent, spawnPosition, Quaternion.identity);
            agentClone.transform.parent = GameObject.Find("Characters").transform;
            OCActionController agiAC = agiAC = agentClone.GetComponent <OCActionController>();

            agiAC.DefaultEndTarget   = GameObject.Find("EndPointStub");
            agiAC.DefaultStartTarget = GameObject.Find("StartPointStub");

            //Debug.Log ("agentClone is" + (agentClone == null ? " null " : " not null"));

            OCConnectorSingleton connector = OCConnectorSingleton.Instance;

            UnityEngine.Debug.Log("The GUID of our OCC instance in LoadAgent is " + connector.VerificationGuid);

            //Debug.Log ("connector is" + (connector == null ? " null " : " not null"));

            if (agentName == "")
            {
                agentName = CreateRandomAgentName();
            }

            //Debug.Log("We shall name him '" + agentName + "'");

            agentClone.name = agentName;

//			if (agentClone != null) {
//				if (!OCARepository.AddOCA (agentClone)) {
//					// An avatar with given name is already there.
//					yield break;
//				}
//				Debug.Log ("Add avatar[" + agentName + "] to avatar map.");
//			}

            // Get the player id as the master id of the avatar.
            // TODO Currently we use the tag "player". However, when there are multiple
            // players in the world, we need to figure out a way to identify.
            string masterId   = playerObject.GetInstanceID().ToString();
            string masterName = playerObject.name;

            // TODO Set agentType and agentTraits in the future.
            // leave agentType and agentTraits to null just for test.
            connector.Init(agentName, null, null, masterId, masterName);

            yield return(StartCoroutine(connector.ConnectOAC()));

            if (!connector.IsInitialized)
            {
                // OAC is not loaded normally, destroy the avatar instance.
                Debug.LogError("Cannot connect to the OAC, avatar loading failed.");
                connector.SaveAndExit();
                Destroy(agentClone);
                yield break;
            }
        }
Пример #15
0
 public static CSGBrushMeshAsset CreateBoxAsset(UnityEngine.Vector3 min, UnityEngine.Vector3 max, CSGSurfaceAsset surfaceAsset, SurfaceFlags surfaceFlags = SurfaceFlags.None)
 {
     return(CreateBoxAsset(min, max, new CSGSurfaceAsset[] { surfaceAsset, surfaceAsset, surfaceAsset, surfaceAsset, surfaceAsset, surfaceAsset }, surfaceFlags));
 }
Пример #16
0
        public static CSGBrushMeshAsset CreateBoxAsset(UnityEngine.Vector3 size, CSGSurfaceAsset surfaceAsset, SurfaceFlags surfaceFlags = SurfaceFlags.None)
        {
            var halfSize = size * 0.5f;

            return(CreateBoxAsset(-halfSize, halfSize, surfaceAsset, surfaceFlags));
        }