Esempio n. 1
0
        public void Update(SharpDevice device, Matrix View, Matrix Projection)
        {
            TransUpdate( );

            SendGPUData(device, View, Projection);

            MMDModelMorph.UpdateMorph(OrigVertice, Vertice);

            UpdateMesh( );

            Mesh.Begin( );
            for (int i = 0; i < Mesh.SubSets.Count; i++)
            {
                SharpSubSet      sharpSubSet  = Mesh.SubSets[i];
                PixelShaderStage pixelShader  = device.DeviceContext.PixelShader;
                MaterialGPUData  materialData = Materials[i].MaterialData;
                device.DeviceContext.PixelShader.SetShaderResource(0, sharpSubSet.DiffuseMap);
                device.DeviceContext.PixelShader.SetShaderResource(1, sharpSubSet.SphereMap);
                pixelShader.SetConstantBuffer(1, MaterialDataBuffer);
                device.UpdateData(MaterialDataBuffer, materialData);
                //set texture
                Mesh.Draw(i);
            }
            // https://gamedev.stackexchange.com/questions/49779/different-shaders-for-different-objects-directx-11
        }
Esempio n. 2
0
        SharpMesh GetSharpMesh(SharpDevice device)
        {
            SharpMesh     mesh            = new SharpMesh(device);
            List <int>    indices         = new List <int>( );
            List <Face>   faces           = new List <Face>( );
            List <string> texList         = new List <string>( );
            List <string> notFoundTexList = new List <string>( );
            int           icount          = 0;

            foreach (Material item in Materials)
            {
                indices.AddRange(item.FlattenFace);
                int faceCount = item.FlattenFace.Count( );

                SharpSubSet subSet = new SharpSubSet( )
                {
                    IndexCount = faceCount,
                    StartIndex = icount,
                };

                if (item.TexName != string.Empty)
                {
                    var filename = TryGetResource(device, item.TexName);
                    // 存在しないパスなら読まない
                    filename.Match(() => notFoundTexList.Add(item.TexName), r => subSet.DiffuseMap = r);
                }


                if (item.SphereName != string.Empty)
                {
                    var filename = TryGetResource(device, item.SphereName);
                    filename.Match(() => notFoundTexList.Add(item.SphereName), r => subSet.SphereMap = r);
                }

                mesh.SubSets.Add(subSet);

                for (int i = icount; i < icount + faceCount; i += 3)
                {
                    int  ind1  = indices[i];
                    int  ind2  = indices[i + 1];
                    int  ind3  = indices[i + 2];
                    Face item1 = new Face(Vertice[ind1].Position, Vertice[ind2].Position, Vertice[ind3].Position, item.Name);
                    //Debug.WriteLine("first " + item1.TriString);
                    faces.Add(item1);
                }
                icount += faceCount;
            }
            Index = indices.ToArray( );
            Faces = faces.ToArray( );
            var inds   = Index.Select(x => x.ToString( ));
            var facesS = Faces.Select(x => x.ToString( ));

            //inds.Concat( facesS ).Concat( texList ).WriteFile( DirPath + "loadedFile.txt" );
            notFoundTexList.WriteFile(DirPath + "notFoundTextures.txt");

            ModelStr = Faces.Select(f => f.TriString).ConcatStr( );
            mesh.SetOnly(Vertice, Index);
            return(mesh);
        }