public void onEnter() { OBJModelLoader modelLoader = new OBJModelLoader(); modelLoader.loadModel("Assets/Models/spaceship.obj"); return; }
private void GenerateMesh() { //for(int z = 0; z < this.resolutionY - 1; z++) //{ // for(int x = 0; x < this.resolutionX - 1; x++) // { // } //} OBJModelLoader modelLoader = new OBJModelLoader(); Tuple <MeshGeometry3D, GeometryModel3D> modelLoadResults = ModelUtil.ConvertModel(modelLoader.LoadModel(@"C:\Users\Kenley Strik\Desktop\M4.obj")); this.model = modelLoadResults.Item2; this.mesh = modelLoadResults.Item1; }
static void Main(string[] args) { OBJModelLoader modelLoader = new OBJModelLoader(); bool isRunning = true; while (isRunning) { Console.WriteLine("Type filepath of model: "); string filename = Console.ReadLine(); Model model = modelLoader.LoadModel(filename); switch (Console.ReadKey().Key) { case ConsoleKey.Backspace: { isRunning = false; break; } } } }
public MainWindow() { InitializeComponent(); modelLoader = new OBJModelLoader(); this.Closing += MainWindow_Closing; wave = new Wave(); stopwatch.Start(); // Declare scene objects. Viewport3D myViewport3D = new Viewport3D(); Model3DGroup myModel3DGroup = new Model3DGroup(); GeometryModel3D myGeometryModel = ConvertModel(modelLoader.LoadModel(@"C:\Users\Kenley Strik\Desktop\M4.obj")); ModelVisual3D myModelVisual3D = new ModelVisual3D(); // Defines the camera used to view the 3D object. In order to view the 3D object, // the camera must be positioned and pointed such that the object is within view // of the camera. PerspectiveCamera myPCamera = new PerspectiveCamera(); //myPCamera.Position = new Point3D(0, 1.5f, 10); //myPCamera.Position = new Point3D(0, 0.5f, 2); //myPCamera.Position = new Point3D(0, 2.5f, 10); //myPCamera.Position = new Point3D(0, 10f, 100); myPCamera.Position = new Point3D(0, 20f, 20); //myPCamera.LookDirection = new Vector3D(0, 0, -1); //myPCamera.LookDirection = new System.Windows.Media.Media3D.Vector3D(0, -0.6, -1); //myPCamera.LookDirection = new System.Windows.Media.Media3D.Vector3D(0, -0.4, -1); myPCamera.LookDirection = new System.Windows.Media.Media3D.Vector3D(0, -1, -1); myPCamera.FieldOfView = 60; myViewport3D.Camera = myPCamera; DirectionalLight myDirectionalLight = new DirectionalLight(); myDirectionalLight.Color = Colors.White; //myDirectionalLight.Direction = new System.Windows.Media.Media3D.Vector3D(-0.61, -0.5, -0.61); myDirectionalLight.Direction = new System.Windows.Media.Media3D.Vector3D(0, -1, -1); myModel3DGroup.Children.Add(myDirectionalLight); ImageBrush colors_brush = new ImageBrush(); colors_brush.ImageSource = new BitmapImage(new Uri(@"C:\Users\Kenley Strik\Desktop\M4_Albedo.png", UriKind.Absolute)); DiffuseMaterial myDiffuseMaterial = new DiffuseMaterial(colors_brush); myGeometryModel.Material = myDiffuseMaterial; myGeometryModel.BackMaterial = myDiffuseMaterial; RotateTransform3D myRotateTransform3D = new RotateTransform3D(); AxisAngleRotation3D myAxisAngleRotation3d = new AxisAngleRotation3D(); //myAxisAngleRotation3d.Axis = new System.Windows.Media.Media3D.Vector3D(0, 3, 0); //myAxisAngleRotation3d.Angle = angle; myRotateTransform3D.Rotation = myAxisAngleRotation3d; //myGeometryModel.Transform = myRotateTransform3D; float time = 0; this.timer = new Timer(1); this.timer.Elapsed += new ElapsedEventHandler((object sender, ElapsedEventArgs e) => { angle += 0.5f; time += 0.01f; if (time >= 100.0f) { time = 0; } Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => { for (int i = 0; i < mesh.Positions.Count; i++) { Vertex vertex = new Vertex(new MLlib.Vectors.Vector3D((float)verticesS[i].X, (float)verticesS[i].Y, (float)verticesS[i].Z), new MLlib.Vectors.Vector2D((float)uvCoordinatesS[i].X, (float)uvCoordinatesS[i].Y), new MLlib.Vectors.Vector3D((float)normalsS[i].X, (float)normalsS[i].Y, (float)normalsS[i].Z)); wave.CalucluateVertexPosition(vertex, time); mesh.Positions[i] = new Point3D(vertex.Vertice.X, vertex.Vertice.Y, vertex.Vertice.Z); //mesh.Normals[i] = new System.Windows.Media.Media3D.Vector3D(vertex.Normal.X, vertex.Normal.Y, vertex.Normal.Z); } //myAxisAngleRotation3d.Angle = angle; })); }); //this.timer.Start(); //for(int i = 0; i < mesh.Positions.Count; i++) //{ // Vertex vertex = new Vertex(new MLlib.Vectors.Vector3D((float)verticesS[i].X, (float)verticesS[i].Y, (float)verticesS[i].Z), // new MLlib.Vectors.Vector2D((float)uvCoordinatesS[i].X, (float)uvCoordinatesS[i].Y), // new MLlib.Vectors.Vector3D((float)normalsS[i].X, (float)normalsS[i].Y, (float)normalsS[i].Z)); // wave.CalucluateVertexPosition(ref vertex, 0); // mesh.Positions[i] = new Point3D(vertex.Vertice.X, vertex.Vertice.Y, vertex.Vertice.Z); // mesh.Normals[i] = new System.Windows.Media.Media3D.Vector3D(vertex.Normal.X, vertex.Normal.Y, vertex.Normal.Z); //} Water water1 = new Water(Application.Current.Dispatcher); Water water2 = new Water(Application.Current.Dispatcher); water1.GetWaterPlane().GetModel().Transform = new TranslateTransform3D(5.2, 0, 0); water2.GetWaterPlane().GetModel().Transform = new TranslateTransform3D(-5.2, 0, 0); RotateTransform3D rotateTransform = new RotateTransform3D(); AxisAngleRotation3D axisAngleRotation = new AxisAngleRotation3D(); axisAngleRotation.Axis = new System.Windows.Media.Media3D.Vector3D(1, 0, 0); axisAngleRotation.Angle = 45; rotateTransform.Rotation = axisAngleRotation; Transform3DGroup transform3DGroup = new Transform3DGroup(); transform3DGroup.Children.Add(rotateTransform); //transform3DGroup.Children.Add(new TranslateTransform3D(0, 5, -10)); //water2.GetWaterPlane().GetModel().Transform = transform3DGroup; myModel3DGroup.Children.Add(water1.GetWaterPlane().GetModel()); myModel3DGroup.Children.Add(water2.GetWaterPlane().GetModel()); //myModel3DGroup.Children.Add(myGeometryModel); myModelVisual3D.Content = myModel3DGroup; myViewport3D.Children.Add(myModelVisual3D); this.Content = myViewport3D; water1.Start(); water2.Start(); }