Esempio n. 1
0
 public MeshSet(GeometrySet gs, List <Vector2> _uvs, List <Vector2> _colors, List <Color32> _color32s, List <Vector4> _tangents)
 {
     this.geometrySet = gs; this.uvs = _uvs;
     deltaVertexCount = 0;
     color32s         = _color32s;
     colors           = _colors;
     tangents         = _tangents;
 }
Esempio n. 2
0
    private MeshSet collectMeshDataWithFaceAggregators(FaceAggregator[] faceAggs, ref int starting_tri_index, bool wantToRecalculate)
    {
        // TODO: keep track of the lowest and highest (vertical only) face aggs.
        // then avoid iterating over empty faceAggs.

        List <Vector3> temp_vertices  = new List <Vector3>();
        List <Vector2> temp_uvs       = new List <Vector2>();
        List <int>     temp_triangles = new List <int>();
        List <Color32> temp_col32s    = new List <Color32>();
        List <Vector4> temp_v4s       = new List <Vector4>();

        FaceAggregator fa;

        for (int i = 0; i < faceAggs.Length; ++i)
        {
            fa = faceAggs[i];


            if (fa != null)
            {
                MeshSet mset;
                if (wantToRecalculate)
                {
                    mset = fa.getFaceGeometry(i);
                }
                else
                {
                    mset = fa.meshSet;
                }

                AssertUtil.Assert(mset.geometrySet.vertices != null, "huh? how did this get in here? face ag at index: "
                                  + i + " \n" + fa.toString());

                List <int> geomSetIndices = new List <int>(mset.geometrySet.indices);               //copy list... //getting arg cannot be null here
                // when adding blocks (perhaps flush with other blocks?) but only sometimes...(only in flat world??)
                GeometrySet gset = new GeometrySet(geomSetIndices, mset.geometrySet.vertices);

                temp_vertices.AddRange(gset.vertices);
                int j = 0;
                for (; j < gset.indices.Count; ++j)
                {
                    gset.indices[j] += starting_tri_index;
                }

                temp_triangles.AddRange(gset.indices);
                temp_uvs.AddRange(mset.uvs);
                temp_col32s.AddRange(mset.color32s);
                temp_v4s.AddRange(mset.tangents);


                fa.baseTriangleIndex = starting_tri_index;                 // for editing mesh (potentially)
                starting_tri_index  += gset.vertices.Count;
            }
        }
        return(new MeshSet(new GeometrySet(temp_triangles, temp_vertices), temp_uvs, temp_col32s, temp_v4s));
    }
        /// <summary>
        ///
        /// </summary>
        /// <param name="id">id of this mesh</param>
        /// <param name="geoSet">the Geometry set this mesh belongs to</param>
        public MeshGeometry(string id, GeometrySet geoSet)
        {
            this.id           = id;
            parentGeometrySet = geoSet;

            inputSources      = new Dictionary <int, List <InputSourceCollection> >();
            pointSets         = new List <PointComponents>();
            faces             = new List <int[]>();
            vertexDict        = new Dictionary <string, VertexSet>();
            vertexIds         = new Dictionary <int, List <int> >();
            subMeshes         = new List <SubMeshInfo>();
            vertexDataEntries = new List <VertexDataEntry>();
        }
        public MeshGeometry Clone(string id, GeometrySet geoSet)
        {
            MeshGeometry clone = new MeshGeometry(id, geoSet);

            foreach (int ii in this.inputSources.Keys)
            {
                clone.AddInputs(ii, this.inputSources[ii]);
            }
            foreach (PointComponents pc in this.pointSets)
            {
                clone.pointSets.Add(pc);
            }
            foreach (int[] f in this.faces)
            {
                clone.faces.Add(f);
            }
            foreach (string vs in this.vertexDict.Keys)
            {
                clone.vertexDict[vs] = this.vertexDict[vs];
            }
            foreach (int vi in this.vertexIds.Keys)
            {
                clone.vertexIds[vi] = this.vertexIds[vi];
            }
            foreach (VertexDataEntry vde in this.vertexDataEntries)
            {
                clone.vertexDataEntries.Add(vde.Clone());
            }

            clone.VertexData = this.VertexData.Clone();

            if (this.boneAssignmentList != null)
            {
                foreach (int vba in this.boneAssignmentList.Keys)
                {
                    clone.boneAssignmentList[vba] = this.boneAssignmentList[vba];
                }
            }

            int smi_count = 0;

            foreach (SubMeshInfo smi in this.subMeshes)
            {
                SubMeshInfo new_smi = new SubMeshInfo();
                new_smi.name     = this.subMeshes.Count > 1 ? id + "." + (smi_count++).ToString() : id;
                new_smi.material = smi.material;
                clone.subMeshes.Add(new_smi);
            }
            return(clone);
        }
Esempio n. 5
0
    private void addAggregatedFaceGeomToMesh(int starting_tri_index)
    {
#if MESH_BUILDER_BUILDS_MESH
        meshBuilder.compileGeometryAndKeepMeshSet(ref starting_tri_index);
        return;
#endif

#if NO_MESHBUILDER
        FaceAggregator fa;
        for (int i = 0; i < faceAggregators.Length; ++i)
        {
            fa = faceAggregators[i];
            if (fa != null)
            {
                MeshSet     mset = fa.getFaceGeometry(i);
                GeometrySet gset = mset.geometrySet;

                vertices_list.AddRange(gset.vertices);

                for (int j = 0; j < gset.indices.Count; ++j)
                {
                    gset.indices[j] += starting_tri_index;
                }

                triangles_list.AddRange(gset.indices);

                starting_tri_index += gset.vertices.Count;

                uvcoords_list.AddRange(mset.uvs);
            }
        }
#else
        MeshSet mesh_set = meshBuilder.compileGeometry(ref starting_tri_index);

//		triangles_list.AddRange(mesh_set.geometrySet.indices);
//		uvcoords_list.AddRange(mesh_set.uvs);
//		vertices_list.AddRange(mesh_set.geometrySet.vertices);
//		col32s_list.AddRange(mesh_set.color32s);
#endif
    }
Esempio n. 6
0
 public MeshSet(GeometrySet gs, List <Vector2> _uvs)
 {
     this = new MeshSet(gs, _uvs, new List <Vector2>());
 }
Esempio n. 7
0
 public MeshSet(GeometrySet gs, List <Vector2> _uvs, List <Vector4> _tangents)
 {
     this = new MeshSet(gs, _uvs, new List <Vector2>(), new List <Color32>(), _tangents);
 }
Esempio n. 8
0
 public MeshSet(GeometrySet gs, List <Vector2> _uvs, List <Color32> _color32s)
 {
     this = new MeshSet(gs, _uvs, new List <Vector2>(), _color32s, new List <Vector4>());
 }
Esempio n. 9
0
        /// <summary>
        /// Draw all the model batch instances
        /// </summary>
        /// <param name="state"></param>
        public void Draw(DrawState state)
        {
            if (modelData == null)
            {
                throw new InvalidOperationException("ModelData is null");
            }

            if (geometry == null)
            {
                SetupGeometry();
            }

            int geometryIndex = 0;

            BatchModelShaderProvider shaderProvider = this.shaderProvider;
            MaterialLightCollection  lights         = this.lights;

            ShaderProviderFlag providerFlag;

            MaterialLightCollection.LightCollectionFlag lightsFlag;

            state.GetDrawFlag(out providerFlag);
            if (providerFlag.OverrideShaderProvider)
            {
                shaderProvider = providerFlag.ShaderProvider;
            }

            state.GetDrawFlag(out lightsFlag);
            if (lightsFlag.OverrideLightCollection)
            {
                lights = lightsFlag.LightCollection;
            }

            if (shaderProvider != null)
            {
                shaderProvider.BeginDraw(state);
            }

            //loop through the model data
            for (int m = 0; m < modelData.meshes.Length; m++)
            {
                MeshData mesh = modelData.meshes[m];

                if (shaderProvider != null)
                {
                    shaderProvider.BeginMesh(state, mesh);
                }

                for (int g = 0; g < mesh.geometry.Length; g++)
                {
                    GeometryData geom = mesh.geometry[g];
                    GeometrySet  set  = this.geometry[geometryIndex];

                    if (set.count > 0)
                    {
                        bool instancing = state.SupportsHardwareInstancing && set.count > 2;

                        if (shaderProvider == null || !shaderProvider.BeginGeometryShaderOverride(state, geom, lights, instancing))
                        {
                            MaterialShader shader = geom.MaterialShader;

                            shader.AnimationTransforms   = null;
                            shader.UseHardwareInstancing = instancing;
                            shader.Lights = lights;

                            shader.Bind(state);
                        }

                        //draw the geometry
                        if (instancing)
                        {
                            state.DrawBatch(geom.Vertices, geom.Indices, PrimitiveType.TriangleList, null, set.instances, set.count);
                        }
                        else
                        {
                            for (int i = 0; i < set.count; i++)
                            {
                                state.PushWorldMatrixMultiply(ref set.instances[i]);

                                geom.Vertices.Draw(state, geom.Indices, PrimitiveType.TriangleList);

                                state.PopWorldMatrix();
                            }
                        }

                        if (shaderProvider != null)
                        {
                            shaderProvider.EndGeometry(state, geom);
                        }
                    }


                    set.count = 0;
                    geometryIndex++;
                }

                if (shaderProvider != null)
                {
                    shaderProvider.EndMesh(state, mesh);
                }
            }

            if (shaderProvider != null)
            {
                shaderProvider.EndDraw(state);
            }

            drawCount = 0;
        }
Esempio n. 10
0
        //the child isn't drawn right now, but for every bit of geometry that is visible, the world matrix is stored
        internal void DrawChild(DrawState state)
        {
            if (modelData == null)
            {
                throw new InvalidOperationException("ModelData is null");
            }

            if (geometry == null)
            {
                SetupGeometry();
            }

            ContainmentType cullModel = ContainmentType.Contains;

            //if there is just one geometry object, then the ICullable.CullTest() call will have been suficient.
            bool skipCullTest = this.modelData != null && this.modelData.meshes.Length == 1 && this.modelData.meshes[0].geometry.Length == 1;

            if (!skipCullTest)
            {
                cullModel = state.Culler.IntersectBox(ref modelData.staticBounds.minimum, ref modelData.staticBounds.maximum);
            }

            int  geometryIndex = 0;
            bool drawn         = false;

            //loop through the model data
            if (cullModel != ContainmentType.Disjoint)
            {
                for (int m = 0; m < modelData.meshes.Length; m++)
                {
                    MeshData mesh = modelData.meshes[m];

                    ContainmentType cullMesh = cullModel;

                    //cull testing along the way
                    if (cullModel == ContainmentType.Intersects && modelData.meshes.Length > 1)
                    {
                        cullMesh = state.Culler.IntersectBox(ref mesh.staticBounds.minimum, ref mesh.staticBounds.maximum);
                    }

                    if (cullMesh != ContainmentType.Disjoint)
                    {
                        for (int g = 0; g < mesh.geometry.Length; g++)
                        {
                            GeometryData geom = mesh.geometry[g];

                            bool cullTest = true;

                            if (cullMesh == ContainmentType.Intersects && mesh.geometry.Length > 1)
                            {
                                cullTest = state.Culler.TestBox(ref geom.staticBounds.minimum, ref geom.staticBounds.maximum);
                            }

                            //finally, is the geometry visible?
                            if (cullTest)
                            {
                                //add the world matrix to the geometry set
                                GeometrySet set = this.geometry[geometryIndex];

                                if (set.count == set.instances.Length)
                                {
                                    Array.Resize(ref set.instances, set.instances.Length * 2);
                                }

                                state.GetWorldMatrix(out set.instances[set.count++]);

                                drawn = true;
                            }

                            geometryIndex++;
                        }
                    }
                    else
                    {
                        geometryIndex += mesh.geometry.Length;
                    }
                }
            }
            if (drawn)
            {
                drawCount++;
            }
        }
 /// <summary>
 ///   Get the pose info object that contains information about
 ///   the pose indices for pose entries for the morph from src
 ///   to dst.
 /// </summary>
 /// <param name="src"></param>
 /// <param name="dst"></param>
 /// <returns></returns>
 public PoseInfo GetPoseInfo( GeometrySet src, GeometrySet dst )
 {
     return m_PoseInfoCatalog.FindInfo( src, dst );
 }