Example #1
0
        public TerrainRenderer(GraphicsDevice graphicsDevice, ContentManager content, Settings settings)
        {
            GraphicsDevice = graphicsDevice;
            Content = content;
            this.settings = settings;

            instanceVertexBuffer = new WritableVertexBuffer<PatchInstanceVertex>(GraphicsDevice, Selection.MaxSelectedNodeCount * 2);

            // TODO: I want to change a patch resolution at runtime.
            // patchGridSize = leafNodeSize * patchResolution;
            patchMesh = new PatchMesh(GraphicsDevice, settings.LeafNodeSize * DefaultPatchResolution);

            sourceEffect = Content.Load<Effect>("TerrainEffect");
            effect = new TerrainEffect(sourceEffect);
            effect.PatchGridSize = patchMesh.GridSize;
            effect.LevelCount = settings.LevelCount;

            lightDirection = new Vector3(0, -1, -1);
            lightDirection.Normalize();

            boundingBoxDrawer = new BoundingBoxDrawer(GraphicsDevice);
            debugEffect = new BasicEffect(GraphicsDevice);
            debugEffect.AmbientLightColor = Vector3.One;
            debugEffect.VertexColorEnabled = true;

            HeightColorVisible = true;
            LightEnabled = true;

            WireframeGap = 0.01f;
        }
Example #2
0
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            font        = Content.Load <SpriteFont>("Fonts/Default");
            fillTexture = Texture2DHelper.CreateFillTexture(GraphicsDevice);

            float aspectRatio = GraphicsDevice.Viewport.AspectRatio;

            cameraPosition = new Vector3(0, 0, 30);
            view           = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Up);
            projection     = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(30), aspectRatio, 1, 1000);

            // インスタンス情報を格納する為の頂点バッファの生成
            instanceVertexBuffer      = new WritableVertexBuffer <ObjectInstanceVertex>(GraphicsDevice, MaxGameObjectCount * 2);
            directMappingVertexBuffer = new WritableVertexBuffer <GameObject>(GraphicsDevice, MaxGameObjectCount * 2);

            // モデルの移動範囲の設定
            float sandBoxSize = 20.0f;

            Sandbox.Min.X = sandBoxSize * -0.5f * aspectRatio;
            Sandbox.Min.Y = sandBoxSize * -0.5f;
            Sandbox.Max.X = sandBoxSize * 0.5f * aspectRatio;
            Sandbox.Max.Y = sandBoxSize * 0.5f;

            // BlockMesh をロードします。
            LoadBlockMesh();

            // ゲームオブジェクトの初期化
            InitializeGameObjects();
        }
 public InstancedModelRenderData( InstancedModel model )
 {
     this.model = model;
       this.model.SetInstancingTechnique( InstancingTechnique.HardwareInstancing,
                                  StaticInstanceVertex.VertexElements );
       instances = new StaticInstanceVertex[MaxInstances];
       vertexBuffer = new WritableVertexBuffer( ZombieCraft.Instance.GraphicsDevice,
                                        typeof( StaticInstanceVertex ),
                                        MaxInstances, 3 );
       instanceCount = 0;
 }
Example #4
0
        public CDLODTerrainRenderer(GraphicsDevice graphicsDevice, CDLODSettings settings)
        {
            if (graphicsDevice == null) throw new ArgumentNullException("graphicsDevice");

            GraphicsDevice = graphicsDevice;
            this.settings = settings;

            instanceVertexBuffer = new WritableVertexBuffer<PatchInstanceVertex>(GraphicsDevice, CDLODSelection.MaxSelectedNodeCount * 2);

            // TODO: I want to change a patch resolution at runtime.
            // patchGridSize = leafNodeSize * patchResolution;
            patchMesh = new PatchMesh(GraphicsDevice, settings.PatchGridSize);
        }
Example #5
0
 /// <summary>
 /// コンストラクタ
 /// </summary>
 /// <param name="triangleCount">三角形の個数</param>
 /// <param name="vertices">頂点配列</param>
 /// <param name="vertMap">モデルの頂点とMMDの頂点対応</param>
 /// <param name="indexBuffer">インデックスバッファ</param>
 public MMDGPUModelPartPNm(int triangleCount, MMDVertexNm[] vertices, Dictionary<long, int[]> vertMap, IndexBuffer indexBuffer)
     : base(triangleCount, vertices.Length, vertMap, indexBuffer)
 {
     this.vertices = vertices;
     //GPUリソース作成
     gpuVertices = new VertexPositionNormal[vertices.Length];
     vertexBuffer = new WritableVertexBuffer(indexBuffer.GraphicsDevice, vertices.Length * 4, typeof(VertexPositionNormal));
     //初期値代入
     for (int i = 0; i < vertices.Length; i++)
     {
         gpuVertices[i].Position = vertices[i].Position;
         gpuVertices[i].Normal = vertices[i].Normal;
     }
     // put the vertices into our vertex buffer
     vertexOffset = vertexBuffer.SetData(gpuVertices);
 }
Example #6
0
        /// <summary>
        /// コンストラクタ
        /// </summary>
        /// <param name="modelParts">モデルパーツ</param>
        /// <param name="boneManager">ボーンマネージャ</param>
        /// <param name="faceManager">表情マネージャ</param>
        /// <param name="attachedMotion">付属モーション</param>
        /// <param name="rigids">剛体</param>
        /// <param name="joints">ジョイント</param>
        public MMDXModel(List<IMMDModelPart> modelParts, MMDBoneManager boneManager, IMMDFaceManager faceManager, Dictionary<string, MMDMotion> attachedMotion, MMDRigid[] rigids, MMDJoint[] joints)
            : base(modelParts, boneManager, faceManager, attachedMotion, rigids, joints)
        {
#if XBOX
            //ボーンマネージャ・表情マネージャを変換しておく
            this.boneManager = (MMDXBoxBoneManager)boneManager;
            this.faceManager = (MMDXBoxFaceManager)faceManager;
            //グラフィックデバイスの抜き出し
            if (modelParts.Count > 0)
            {
                GraphicsDevice graphics = ((MMDModelPart)modelParts[0]).GraphicsDevice;
                //頂点バッファの作成
                skinVertexBuffer = new WritableVertexBuffer(graphics, this.boneManager.SKinTransformXBox.Length * 4, typeof(VertexSkinning));
                this.faceManager.SetUp(graphics);
            }
#endif
        }
Example #7
0
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            font = Content.Load<SpriteFont>("Fonts/Default");
            fillTexture = Texture2DHelper.CreateFillTexture(GraphicsDevice);

            float aspectRatio = GraphicsDevice.Viewport.AspectRatio;
            cameraPosition = new Vector3(0, 0, 30);
            view = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Up);
            projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(30), aspectRatio, 1, 1000);

            // インスタンス情報を格納する為の頂点バッファの生成
            instanceVertexBuffer = new WritableVertexBuffer<ObjectInstanceVertex>(GraphicsDevice, MaxGameObjectCount * 2);
            directMappingVertexBuffer = new WritableVertexBuffer<GameObject>(GraphicsDevice, MaxGameObjectCount * 2);

            // モデルの移動範囲の設定
            float sandBoxSize = 20.0f;
            Sandbox.Min.X = sandBoxSize * -0.5f * aspectRatio;
            Sandbox.Min.Y = sandBoxSize * -0.5f;
            Sandbox.Max.X = sandBoxSize * 0.5f * aspectRatio;
            Sandbox.Max.Y = sandBoxSize * 0.5f;

            // BlockMesh をロードします。
            LoadBlockMesh();

            // ゲームオブジェクトの初期化
            InitializeGameObjects();
        }