示例#1
0
        static Bounds GetBounds(PF.Vector3[] points, Vector3 right, Vector3 up, Vector3 forward, Vector3 origin, float minimumHeight)
        {
            if (points == null || points.Length == 0)
            {
                return(new Bounds());
            }
            float miny = points[0].y, maxy = points[0].y;

            for (int i = 0; i < points.Length; i++)
            {
                miny = Mathf.Min(miny, points[i].y);
                maxy = Mathf.Max(maxy, points[i].y);
            }
            var extraHeight = Mathf.Max(minimumHeight - (maxy - miny), 0) * 0.5f;

            miny -= extraHeight;
            maxy += extraHeight;

            Vector3 min = right * points[0].x + up * points[0].y + forward * points[0].z;
            Vector3 max = min;

            for (int i = 0; i < points.Length; i++)
            {
                var p  = right * points[i].x + forward * points[i].z;
                var p1 = p + up * miny;
                var p2 = p + up * maxy;
                min = Vector3.Min(min, p1);
                min = Vector3.Min(min, p2);
                max = Vector3.Max(max, p1);
                max = Vector3.Max(max, p2);
            }
            return(new Bounds((min + max) * 0.5F + origin, max - min));
        }
        protected override void OnPointCloudUpdated(PointCloudUpdatedEventArgs e)
        {
            base.OnPointCloudUpdated(e);

            if (!_indices.IsCreated)
            {
                InitializeIndices();
            }

            var vertices = new NativeArray <Vertex>(e.count, Allocator.Temp);

            for (var i = 0; i < vertices.Length; i++)
            {
                vertices[i] = new Vertex(e.pointCloud.points[e.startIndex + i], e.pointCloud.colors[e.startIndex + i]);

                _boundsMin = Vector3.Min(_boundsMin, vertices[i].position);
                _boundsMax = Vector3.Max(_boundsMax, vertices[i].position);
            }

            _mesh.SetVertexBufferParams(pointCloud.count, _vertexAttributeDescriptors);
            _mesh.SetVertexBufferData(vertices, 0, e.startIndex, e.count, 0);

            _mesh.SetIndexBufferParams(pointCloud.count, IndexFormat.UInt32);
            _mesh.SetIndexBufferData(_indices, e.startIndex, e.startIndex, e.count);
            _mesh.SetSubMesh(0, new SubMeshDescriptor(0, pointCloud.count, MeshTopology.Points));

            var bounds = new Bounds();

            bounds.SetMinMax(_boundsMin, _boundsMax);
            _mesh.bounds = bounds;
        }
示例#3
0
        public static Bounds InverseTransform(this GraphTransform self, Bounds bounds)
        {
            if (self.onlyTranslational)
            {
                return(new Bounds(bounds.center - self.translation.ToUnityV3(), bounds.size));
            }

            var corners = PF.ArrayPool <Vector3> .Claim(8);

            var extents = bounds.extents;

            corners[0] = self.InverseTransform(bounds.center + new Vector3(extents.x, extents.y, extents.z));
            corners[1] = self.InverseTransform(bounds.center + new Vector3(extents.x, extents.y, -extents.z));
            corners[2] = self.InverseTransform(bounds.center + new Vector3(extents.x, -extents.y, extents.z));
            corners[3] = self.InverseTransform(bounds.center + new Vector3(extents.x, -extents.y, -extents.z));
            corners[4] = self.InverseTransform(bounds.center + new Vector3(-extents.x, extents.y, extents.z));
            corners[5] = self.InverseTransform(bounds.center + new Vector3(-extents.x, extents.y, -extents.z));
            corners[6] = self.InverseTransform(bounds.center + new Vector3(-extents.x, -extents.y, extents.z));
            corners[7] = self.InverseTransform(bounds.center + new Vector3(-extents.x, -extents.y, -extents.z));

            var min = corners[0];
            var max = corners[0];

            for (int i = 1; i < 8; i++)
            {
                min = Vector3.Min(min, corners[i]);
                max = Vector3.Max(max, corners[i]);
            }
            PF.ArrayPool <Vector3> .Release(ref corners);

            return(new Bounds((min + max) * 0.5f, max - min));
        }
示例#4
0
 public void Encapsulate(Vector3 point)
 {
     this.SetMinMax(Vector3.Min(this.min, point), Vector3.Max(this.max, point));
 }
示例#5
0
 // Grows the Bounds to include the /point/.
 public void Encapsulate(Vector3 point)
 {
     SetMinMax(Vector3.Min(min, point), Vector3.Max(max, point));
 }
示例#6
0
 public Bounds Encapsulate(Bounds bounds)
 {
     return(Bounds.FromMinMax(Vector3.Min(this.min, bounds.min), Vector3.Max(this.max, bounds.max)));
 }
示例#7
0
 public Bounds Encapsulate(Vector3 point)
 {
     return(Bounds.FromMinMax(Vector3.Min(this.min, point), Vector3.Max(this.max, point)));
 }
示例#8
0
        private void SelectAvatar(int index)
        {
            DestroyInstances();
            if (Asset.avatars.Length == 0)
            {
                return;
            }

            index = (index + Asset.avatars.Length) % Asset.avatars.Length;
            selectedAvatarIndex = index;

            var asset = Asset;

            if (selectedAvatarIndex >= asset.avatars.Length)
            {
                selectedAvatarIndex = 0;
            }
            if (selectedAvatarIndex < asset.avatars.Length)
            {
                avatarRes = avatars[selectedAvatarIndex];
            }

            if (avatarRes != null)
            {
                if (avatarRes.skeleton)
                {
                    skeleton = Instantiate(avatarRes.skeleton);
                    //skeleton.transform.forward = -Vector3.forward;
                    skeleton.transform.eulerAngles = new Vector3(0, 90, 0);
                    skeleton.transform.parent      = root;
                    bool    first = true;
                    Vector3 min = new Vector3(), max = new Vector3();
                    foreach (var smr in skeleton.GetComponentsInChildren <SkinnedMeshRenderer>())
                    {
                        if (first)
                        {
                            min = smr.bounds.min;
                            max = smr.bounds.max;
                        }
                        else
                        {
                            min = Vector3.Min(min, smr.bounds.min);
                            max = Vector3.Max(max, smr.bounds.max);
                        }
                    }
                    size      = (max - min).magnitude;
                    distance  = size * 1.3f;
                    height    = (max - min).y;
                    skinned   = skeleton.AddComponent <SkinnedCombine>();
                    animation = skeleton.GetComponent <Animation>();
                    animator  = skeleton.GetComponent <Animator>();

                    if (animator)
                    {
                        if (avatarRes.config.animator)
                        {
                            animator.runtimeAnimatorController = avatarRes.config.animator;
                        }
                    }

                    var smrs = skeleton.GetComponentsInChildren <SkinnedMeshRenderer>();

                    if (avatarRes.awatarParts.Length > 0)
                    {
                        foreach (var smr in smrs)
                        {
                            //if (smr.gameObject!=skeleton&& avatarRes.awatarParts.Where(o => string.Equals(o.partName, smr.name, StringComparison.InvariantCultureIgnoreCase)).Count() == 0)
                            //    continue;
                            smr.materials = new Material[0];
                        }
                        skinned.Clear();
                        for (int i = 0; i < avatarRes.awatarParts.Length; i++)
                        {
                            var part      = avatarRes.awatarParts[i];
                            int partIndex = avatarRes.selectedIndexs[i];
                            if (!(0 <= partIndex && partIndex < avatarRes.selectedIndexs.Length))
                            {
                                continue;
                            }
                            if (partIndex >= part.parts.Length)
                            {
                                continue;
                            }
                            skinned.AddPart(part.partName, part.parts[partIndex], combine);
                        }

                        skinned.GennerateSkin();
                    }
                }
            }
            SelectAnimation(avatarRes.selectedAnimationIndex);
        }