Пример #1
0
        private void SetBlendState(BlendState blendState)
        {
            var index = _blendStates.Count;

            _blendStates.Add(blendState);
            _buffer.Add(new GraphicsStateChange(CommandTypes.Blend, index));
        }
Пример #2
0
        public void Update()
        {
            collection_mesh_job.FinishUpdateMesh();

            NativeBuffer <JobHandle> handles = new NativeBuffer <JobHandle>(batches.Count, Allocator.Temp);
            bool has_job = false;

            foreach (var b in batches)
            {
                var handle = b.BuildJob(out has_job);
                if (has_job)
                {
                    handles.Add(handle);
                }
            }

            //if(handles.Length > 0)
            {
                collection_mesh_job.BeginCollectionMeshInfo();
                foreach (var g in group_rebuild_mesh)
                {
                    if (g.mesh == null)
                    {
                        continue;
                    }

                    collection_mesh_job.CollectionMeshfInfo(g);
                }
                collection_mesh_job.EndCollectionMeshInfo(JobHandle.CombineDependencies(handles));
                group_rebuild_mesh.Clear();
            }
            handles.Dispose();
        }
        /// <summary>
        /// Populates a list with transformed face vertices.
        /// </summary>
        public static unsafe void ComputeFaceClippingPolygon(ref NativeBuffer <ClipVertex> output, int faceIndex, RigidTransform t, NativeHull hull)
        {
            Debug.Assert(output.IsCreated);

            NativeFace *    face    = hull.GetFacePtr(faceIndex);
            NativePlane     plane   = hull.GetPlane(faceIndex);
            NativeHalfEdge *start   = hull.GetEdgePtr(face->Edge);
            NativeHalfEdge *current = start;

            do
            {
                NativeHalfEdge *twin   = hull.GetEdgePtr(current->Twin);
                float3          vertex = hull.GetVertex(current->Origin);
                float3          P      = math.transform(t, vertex);

                ClipVertex clipVertex;
                clipVertex.featurePair.InEdge1  = -1;
                clipVertex.featurePair.OutEdge1 = -1;
                clipVertex.featurePair.InEdge2  = (sbyte)current->Next;
                clipVertex.featurePair.OutEdge2 = (sbyte)twin->Twin;
                clipVertex.position             = P;
                clipVertex.hull2local           = vertex;
                clipVertex.plane = plane;

                output.Add(clipVertex);

                current = hull.GetEdgePtr(current->Next);
            } while (current != start);
        }
Пример #4
0
 private void AddIndexToDirty(int index)
 {
     if (!dirtyset.Contains(index))
     {
         dirtyset.Add(index);
         dirty_indices.Add(index);
     }
 }
        /// <summary>
        /// Populates a list with transformed face planes
        /// </summary>
        public static unsafe void GetClippingPlanes(ref NativeBuffer <ClipPlane> output, NativePlane facePlane, int faceIndex, RigidTransform transform, NativeHull hull)
        {
            Debug.Assert(output.IsCreated);

            for (int i = 0; i < hull.FaceCount; i++)
            {
                var p = hull.GetPlane(i);
                output.Add(new ClipPlane
                {
                    plane = transform * p,
                });
            }
        }
        public void CollectionMeshfInfo(HUDGroup group)
        {
            CheckCapacity(group.items.Count);
            CollectionMeshInfoOffset offset = new CollectionMeshInfoOffset()
            {
                group = group.unique_id
            };
            int count           = 0;
            int mesh_quad_count = 0;

            offset.offset = transform_indices.Length;
            foreach (var itm in group.items)
            {
                if (itm.build_data_index < 0 || itm.batch == null)
                {
                    continue;
                }

                if (itm.batch.buffer_info.transform_job_datas[itm.build_data_index].is_active == 0)
                {
                    continue;
                }

                transform_indices.Add(new TransformIndex()
                {
                    index              = itm.build_data_index,
                    quad_count         = (int)itm.size,
                    buffer_offset      = itm.batch.buffer_info.info.offset,
                    quad_buffer_offset = itm.batch.buffer_info.info.quad_offset
                });
                count++;
                mesh_quad_count += itm.valid_quad;
            }

            offset.length = count;
            //if(offset.length > 0)
            {
                indeices_offset.Add(offset);
                offset.out_index = output_index;
                output_index++;
                building_group.Add(group.unique_id, group);
            }
            if (mesh_quad_count > max_mesh_quad_count)
            {
                max_mesh_quad_count = mesh_quad_count;
            }
        }
        public static unsafe void GetFaceSidePlanes(ref NativeBuffer <ClipPlane> output, NativePlane facePlane, int faceIndex, RigidTransform transform, NativeHull hull)
        {
            NativeHalfEdge *start   = hull.GetEdgePtr(hull.GetFacePtr(faceIndex)->Edge);
            NativeHalfEdge *current = start;

            do
            {
                NativeHalfEdge *twin = hull.GetEdgePtr(current->Twin);
                float3          P    = math.transform(transform, hull.GetVertex(current->Origin));
                float3          Q    = math.transform(transform, hull.GetVertex(twin->Origin));

                ClipPlane clipPlane = default;
                clipPlane.edgeId       = twin->Twin; //edge ID.
                clipPlane.plane.Normal = math.normalize(math.cross(Q - P, facePlane.Normal));
                clipPlane.plane.Offset = math.dot(clipPlane.plane.Normal, P);
                output.Add(clipPlane);

                current = hull.GetEdgePtr(current->Next);
            }while (current != start);
        }
        /// <summary>
        /// Perform the Sutherland-Hodgman polygon clipping. Since all side planes are pointing outwards the points that are *behind* the plane are kept.
        /// </summary>
        public static void Clip(ClipPlane clipPlane, ref NativeBuffer <ClipVertex> input, ref NativeBuffer <ClipVertex> output)
        {
            //Debug.Assert(output.IsCreated && output.Length == 0);
            Debug.Assert(input.IsCreated && input.Length != 0);
            ClipVertex vertex1 = input[input.Length - 1];

            float distance1 = clipPlane.plane.Distance(vertex1.position);

            for (int i = 0; i < input.Length; ++i)
            {
                ClipVertex vertex2 = input[i];

                float distance2 = clipPlane.plane.Distance(vertex2.position);
                if (distance1 <= 0 && distance2 <= 0)
                {
                    // Both vertices are behind or lying on the plane -> keep vertex2
                    output.Add(vertex2);
                }
                else if (distance1 <= 0 && distance2 > 0)
                {
                    // vertex1 is behind the plane, vertex2 is in front -> intersection point
                    float  fraction = distance1 / (distance1 - distance2);
                    float3 position = vertex1.position + fraction * (vertex2.position - vertex1.position);

                    // Keep intersection point
                    ClipVertex vertex;
                    vertex.position             = position;
                    vertex.featurePair.InEdge1  = -1;
                    vertex.featurePair.InEdge2  = vertex1.featurePair.OutEdge2;
                    vertex.featurePair.OutEdge1 = (sbyte)clipPlane.edgeId;
                    vertex.featurePair.OutEdge2 = -1;
                    vertex.plane      = clipPlane.plane;
                    vertex.hull2local = position;
                    output.Add(vertex);
                }
                else if (distance2 <= 0 && distance1 > 0)
                {
                    // vertex2 is behind of the plane, vertex1 is in front -> intersection point
                    float  fraction = distance1 / (distance1 - distance2);
                    float3 position = vertex1.position + fraction * (vertex2.position - vertex1.position);

                    // Keep intersection point
                    ClipVertex vertex;
                    vertex.position             = position;
                    vertex.featurePair.InEdge1  = (sbyte)clipPlane.edgeId;
                    vertex.featurePair.OutEdge1 = -1;
                    vertex.featurePair.InEdge2  = -1;
                    vertex.featurePair.OutEdge2 = vertex1.featurePair.OutEdge2;
                    vertex.plane      = clipPlane.plane;
                    vertex.hull2local = position;
                    output.Add(vertex);

                    // Keep vertex2 as well
                    output.Add(vertex2);
                }

                // Keep vertex2 as starting vertex for next edge
                vertex1   = vertex2;
                distance1 = distance2;
            }
        }