public void MakeLightWaveScene() { Reset(); LWScene scene = LWSceneParser.Load("res/Scenes/boxi3.lws"); Debug.WriteLine(scene.Objects.Count + " objects"); Debug.WriteLine(scene.Lights.Count + " lights"); Debug.WriteLine(scene.Cameras.Count + " cameras"); Material wood = materialManager["wood"]; var loadedModels = new Dictionary <string, RenderStack.LightWave.LWModel>(); foreach (var @object in scene.Objects) { try { string name = "res/Objects/" + @object.Name.Split('/').Last(); LWModel lwModel = null; if (loadedModels.ContainsKey(name)) { lwModel = loadedModels[name]; } else { loadedModels[name] = lwModel = RenderStack.LightWave.LWModelParser.Load(name); } foreach (var layer in lwModel.Layers.Values) { var mesh = new GeometryMesh(layer.Geometry, NormalStyle.CornerNormals); var model = new Model(layer.Name, mesh, wood, Motion(@object, 0.0f)); AddModel(model); } Debug.WriteLine("\tObject '" + @object.Name + "' " + @object.Bones.Count + " bones @ "); } catch (System.Exception) { } } foreach (var item in scene.Cameras) { Debug.WriteLine("\tCamera '" + item.Name + "'"); } foreach (var item in scene.Lights) { Debug.WriteLine("\tLight '" + item.Name + "'"); } AddCameras(); camera.Frame.LocalToParent.Set( Motion(scene.Cameras.First(), 0.0f) ); AddCameraUserControls(); }
public void End() { if (constraint == null) { return; } model.RigidBody.AllowDeactivation = true; model.Batch.Material = materialStore; materialStore = null; sceneManager.World.RemoveConstraint(constraint); constraint = null; model = null; }
public void MakeBoxScene() { Reset(); float scale = 1.0f; //sceneManager.AddFloor(22.0f * scale, 0, -1.0f); AddFloor(30.0f * scale, 5, -0.5f); #if true float gap = 10.0f; Material magenta = materialManager["magenta"]; for (float x = 0.5f; x <= 2.0f; x += 0.5f) { for (float z = 0.5f; z <= 2.0f; z += 0.5f) { Geometry g = new RenderStack.Geometry.Shapes.Cube( new Vector3(x, 1.0f, z), new IVector3(2, 2, 2) ); //g.Geodesate(); GeometryMesh mesh = new GeometryMesh( g, NormalStyle.CornerNormals ); Shape shape = new BoxShape(x, 1.0f, z); //Shape shape = new RenderStack.Physics.SphereShape(1.0f); AddModel( new Model( "Cube(" + x + ", 1.0, " + z + ")", mesh, magenta, -10.0f + (float)(x * gap), 0.5f, -10.0f + (float)(z * gap) ), shape ); } } #endif AddCameras(); AddCameraUserControls(); }
public void MakeTree(Vector3 pos, TreeTemplate template) { int i = 0; Material wood = materialManager["wood"]; Material leaves = materialManager["leaves"]; float coneHeight = template.Height / (float)template.ConeCount; Matrix4 rotZ = Matrix4.CreateRotation( RenderStack.Math.Conversions.DegreesToRadians(90.0f), Vector3.UnitZ ); float cylHeight = coneHeight; float cylRadius = template.Height / 20.0f; GeometryMesh cylinderMesh = template.Meshes[i]; Shape cylinderShape = template.Shapes[i]; ++i; Model rootModel = new Model("TreeRoot", cylinderMesh, wood, pos.X, pos.Y + cylHeight / 2.0f, pos.Z); AddModel(rootModel, null); Model below = rootModel; float prevOffset = cylHeight / 2.0f; for (int c = 0; c < template.ConeCount; c++) { float topRadius = (template.ConeCount - 1 - c) * template.Radius / (float)template.ConeCount; float bottomRadius = topRadius + template.RadAdd; float R = bottomRadius; float r = topRadius; float fullConeHeight = (R * coneHeight) / (R - r); float minX = -fullConeHeight / 3.0f; //float maxX = 2.0f * fullConeHeight / 3.0f; float offset = -minX; GeometryMesh coneMesh = template.Meshes[i]; Shape coneShape = template.Shapes[i]; ++i; Model coneModel = new Model("TreeCone", coneMesh, leaves, 0.0f, prevOffset + offset, 0.0f); coneModel.Frame.Parent = below.Frame; AddModel(coneModel, null); Bender bender = new Bender(Vector3.UnitZ, 0.1f, 2.0f); bender.Frame = coneModel.Frame; Add(bender); below = coneModel; prevOffset = offset; } }
public void Begin() { if ( (Configuration.physics == false) || (selectionManager == null) || (selectionManager.HoverModel == null) || (selectionManager.HoverModel.RigidBody == null) || (selectionManager.HoverModel.Static == true) ) { return; } model = selectionManager.HoverModel; materialStore = model.Batch.Material; var materialManager = Services.Get <MaterialManager>(); model.Batch.Material = materialManager["EdgeLines"]; sceneManager.UnparentModel(model); Frame frame = model.Frame; RigidBody body = model.RigidBody; //sceneManager.ActivateModel(model); body.IsStatic = false; body.IsActive = true; body.AllowDeactivation = false; frame.Updated = false; //frame.UpdateHierarchical(); Vector3 snap = selectionManager.HoverPosition; Vector3 camera = sceneManager.Camera.Frame.LocalToWorld.Matrix.GetColumn3(3); Vector3 direction = Vector3.Normalize(snap - camera); lockDistance = camera.Distance(snap); snapInLocal = model.Frame.LocalToWorld.InverseMatrix.TransformPoint(snap); //JVector jpos = new JVector(snapInLocal.X, snapInLocal.Y, snapInLocal.Z); constraint = new PointOnPoint( body, snapInLocal ); constraint.Anchor = snap; //new JVector(snap.X, snap.Y, snap.Z); sceneManager.World.AddConstraint(constraint); }
public UnitType( string name, Material material, Mesh mesh, Shape collisionShape, Sphere boundingSphere, float maxHealth, float density, IAI ai, Type controllerType ) { Name = name; Material = material; Mesh = mesh; CollisionShape = collisionShape; BoundingSphere = boundingSphere; MaxHealth = maxHealth; Density = density; AI = ai; ControllerType = controllerType; }
public void MakeSimpleScene() { System.Console.WriteLine("MakeSimpleScene"); int subdiv = 1; Reset(); float scale = 1.0f; //sceneManager.AddFloor(22.0f * scale, 0, -1.0f); AddFloor(22.0f * scale, 5, -0.5f); /* Renderable meshes */ Geometry cubeGeometry = new RenderStack.Geometry.Shapes.Cube(1.0f, 1.0f, 1.0f); //Geometry cubeGeometry = new RenderStack.Geometry.Shapes.Cube(Vector3.One, new IVector3(20, 20, 20), 1.0f); cubeGeometry = Mush(0.04f, cubeGeometry); /*cubeGeometry.BuildEdges(); * cubeGeometry = new SubdivideGeometryOperation(cubeGeometry).Destination; * cubeGeometry = new SubdivideGeometryOperation(cubeGeometry).Destination; * cubeGeometry = new SubdivideGeometryOperation(cubeGeometry).Destination; * cubeGeometry = new CatmullClarkGeometryOperation(cubeGeometry).Destination; * cubeGeometry.ComputePolygonCentroids(); * cubeGeometry.ComputePolygonNormals(); * cubeGeometry.ComputeCornerNormals(0.0f); * cubeGeometry.BuildEdges();*/ GeometryMesh cubeMesh = new GeometryMesh(cubeGeometry, NormalStyle.PolygonNormals); #if OPENRL Geometry geodesatedBoxGeometry = new RenderStack.Geometry.Shapes.Cube( new Vector3(1.0f, 1.0f, 1.0f), new IVector3(2, 2, 2) ); #else Geometry geodesatedBoxGeometry = new RenderStack.Geometry.Shapes.Cube( new Vector3(1.0f, 1.0f, 1.0f), new IVector3(6, 6, 6) ); #endif geodesatedBoxGeometry.Geodesate(0.75f); // This is the best geo shape but somewhat slow to create #if false Geometry subdividedIcosahedron = new RenderStack.Geometry.Shapes.Icosahedron(1.00); //subdividedIcosahedron = Sqrt3(subdividedIcosahedron); //subdividedIcosahedron = Mush(0.01f, subdividedIcosahedron); GeometryMesh sphereMesh2 = new GeometryMesh( subdividedIcosahedron, NormalStyle.PolygonNormals ); #endif #if false GeometryMesh discMesh = new GeometryMesh( new RenderStack.Geometry.Shapes.Disc(1.0, 0.8, 32, 2), NormalStyle.PolygonNormals ); GeometryMesh triangleMesh = new GeometryMesh( new RenderStack.Geometry.Shapes.Triangle(0.8f / 0.57735027f), NormalStyle.PolygonNormals ); #endif GeometryMesh sphereMesh = new GeometryMesh( //new RenderStack.Geometry.Shapes.Sphere(0.75, 24, 14), geodesatedBoxGeometry, NormalStyle.CornerNormals ); #if false #endif //Geometry cylinderGeometry = new RenderStack.Geometry.Shapes.Cylinder(-0.5f, 0.5f, 0.5f, 24); #if OPENRL Geometry cylinderGeometry = new RenderStack.Geometry.Shapes.Cone(-0.5f, 0.5f, 0.5f, 0.5f, true, true, 5, 1); #else Geometry cylinderGeometry = new RenderStack.Geometry.Shapes.Cone(-0.5f, 0.5f, 0.5f, 0.5f, true, true, 24, 1); #endif cylinderGeometry.Transform( Matrix4.CreateRotation( RenderStack.Math.Conversions.DegreesToRadians(90.0f), Vector3.UnitZ ) ); //cylinderGeometry = Mush(0.08f, cylinderGeometry); GeometryMesh cylinderMesh = new GeometryMesh(cylinderGeometry, NormalStyle.CornerNormals); #if OPENRL Geometry coneGeometry = new RenderStack.Geometry.Shapes.Cone(-1.0f / 3.0f, 2.0f / 3.0f, 0.75f, 0.0f, true, false, 5, 5); #else Geometry coneGeometry = new RenderStack.Geometry.Shapes.Cone(-1.0f / 3.0f, 2.0f / 3.0f, 0.75f, 0.0f, true, false, 24 * subdiv, 10 * subdiv); #endif coneGeometry.Transform( Matrix4.CreateRotation( RenderStack.Math.Conversions.DegreesToRadians(90.0f), Vector3.UnitZ ) ); //coneGeometry = Mush(0.08f, coneGeometry); GeometryMesh coneMesh = new GeometryMesh(coneGeometry, NormalStyle.CornerNormals); /* Physics shapes */ Shape cubeShape = new BoxShape(1.0f, 1.0f, 1.0f); Shape sphereShape = new SphereShape(0.75f); Shape cylinderShape = new CylinderShape(1.0f, 0.5f); Shape coneShape = new ConeShape(1.0f, 0.75f); /* Models */ float gap = 2.5f; //var defaultPng = materialManager.Texture("res/images/default.png", true); Material pearl = materialManager["pearl"]; Material gold = materialManager["gold"]; //Material red = materialManager.MakeTextured("red", defaultPng); Material red = materialManager["red"]; //Material green = materialManager["green"] ; Material transparent = materialManager["transparent"]; Material cyan = materialManager["cyan"]; Material blue = materialManager["blue"]; Material magenta = materialManager["magenta"]; Material pink = materialManager["pink"]; Material hsv = materialManager["HSVColorFill"]; Material hsv2 = materialManager["HSVColorFill2"]; for (int z = 0; z < 1; ++z) { float Z = (float)(1 - z) * gap; AddModel(new Model("cube", cubeMesh, z == 0 ? pearl : pearl, -2.5f * gap, 0.5f, Z), cubeShape); AddModel(new Model("box", cubeMesh, z == 0 ? gold : pearl, -1.5f * gap, 0.5f, Z), cubeShape); AddModel(new Model("sphere", sphereMesh, z == 0 ? red : pearl, -0.5f * gap, 0.75f, Z), sphereShape); AddModel(new Model("cylinder", cylinderMesh, z == 0 ? cyan : pearl, 0.5f * gap, 0.5f, Z), cylinderShape); AddModel(new Model("cylinder", cylinderMesh, z == 0 ? blue : pearl, 1.5f * gap, 0.5f, Z), cylinderShape); AddModel(new Model("cone", coneMesh, z == 0 ? magenta : pearl, 2.5f * gap, 1.0f / 3.0f, Z), coneShape); AddModel(new Model("cone", coneMesh, z == 0 ? pink : pearl, 3.5f * gap, 1.0f / 3.0f, Z), coneShape); //AddModel(new Model("disc", discMesh, hsv, 4.5f * gap, 2.0f, Z), null); //AddModel(new Model("triangle", triangleMesh, hsv2, 4.5f * gap, 2.0f, Z), null); //AddModel(new Model("sphere", sphereMesh2, gold, -0.5f * gap, 0.75f, Z), sphereShape); //AddModel(new Model("sphere", sphereMesh, transparent, -0.5f * gap, 0.75f, Z), sphereShape); } AddCameras(); AddCameraUserControls(); #if false if (RenderStack.Graphics.Configuration.useOpenRL) { var rl = Services.Get <OpenRLRenderer>(); rl.BuildScene(renderGroup); } #endif }