0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

cscの作法 その598

Posted at

概要

cscの作法、調べてみた。
wpf3d、やってみた。
練習問題やってみた。

練習問題

テクスチャに、画像を貼れ。

写真

image.png

サンプルコード

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Media3D;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

class Main3d: Window {
	public Main3d() {
		var mesh = new MeshGeometry3D();
		mesh.Positions.Add(new Point3D(0.5, -0.5, 0));
		mesh.Positions.Add(new Point3D(0.5, 0.5, 0));
		mesh.Positions.Add(new Point3D(-0.5, 0.5, 0));
		mesh.Normals.Add(new Vector3D(0, 0, 1));
		mesh.Normals.Add(new Vector3D(0, 0, 1));
		mesh.Normals.Add(new Vector3D(0, 0, 1));
		mesh.TextureCoordinates.Add(new System.Windows.Point(7.0 / 8.0, 7.0 / 8.0));
		mesh.TextureCoordinates.Add(new System.Windows.Point(7.0 / 8.0, 1.0 / 8.0));
		mesh.TextureCoordinates.Add(new System.Windows.Point(1.0 / 8.0, 1.0 / 8.0));
		mesh.TriangleIndices.Add(0);
		mesh.TriangleIndices.Add(1);
		mesh.TriangleIndices.Add(2);
		var imageSrc = new BitmapImage(new Uri(@"C:\Users\ore\csc\cat8.png"));
		var material = new DiffuseMaterial(new ImageBrush(imageSrc));
		var geometry = new GeometryModel3D(mesh, material);
		var modelVisual = new ModelVisual3D();
		modelVisual.Content = geometry;
		var cam = new PerspectiveCamera();
		cam.Position = new Point3D(0, 0, 2);
		var light = new DirectionalLight();
		var vp3d = new Viewport3D();
		vp3d.Camera = cam;
		vp3d.Children.Add(modelVisual);
		vp3d.Children.Add(new ModelVisual3D() {
			Content = light
		});
		Width = 400;
		Height = 400;
		Content = vp3d;
	}
	[STAThread]
	static void Main() {
		var wnd = new Main3d();
		wnd.ShowDialog();
	}
}





以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?