void CreateScene() { ResourceCache cache = GetSubsystem <ResourceCache>(); scene_ = new Scene(context_); // Create the Octree component to the scene. This is required before adding any drawable components, or else nothing will // show up. The default octree volume will be from (-1000, -1000, -1000) to (1000, 1000, 1000) in world coordinates; it // is also legal to place objects outside the volume but their visibility can then not be checked in a hierarchically // optimizing manner scene_.CreateComponent <Octree>(); // Create a child scene node (at world origin) and a StaticModel component into it. Set the StaticModel to show a simple // plane mesh with a "stone" material. Note that naming the scene nodes is optional. Scale the scene node larger // (100 x 100 world units) Node planeNode = scene_.CreateChild("Plane"); planeNode.SetScale(new Vector3(100.0f, 1.0f, 100.0f)); StaticModel planeObject = planeNode.CreateComponent <StaticModel>(); planeObject.SetModel(cache.GetResource <Model>("Models/Plane.mdl")); planeObject.SetMaterial(cache.GetResource <Material>("Materials/StoneTiled.xml")); // Create a directional light to the world so that we can see something. The light scene node's orientation controls the // light direction; we will use the SetDirection() function which calculates the orientation from a forward direction vector. // The light will use default settings (white light, no shadows) Node lightNode = scene_.CreateChild("DirectionalLight"); lightNode.SetDirection(new Vector3(0.6f, -1.0f, 0.8f)); // The direction vector does not need to be normalized Light light = lightNode.CreateComponent <Light>(); light.SetLightType(LightType.LIGHT_DIRECTIONAL); // Create more StaticModel objects to the scene, randomly positioned, rotated and scaled. For rotation, we construct a // quaternion from Euler angles where the Y angle (rotation about the Y axis) is randomized. The mushroom model contains // LOD levels, so the StaticModel component will automatically select the LOD level according to the view distance (you'll // see the model get simpler as it moves further away). Finally, rendering a large number of the same object with the // same material allows instancing to be used, if the GPU supports it. This reduces the amount of CPU work in rendering the // scene. const uint NUM_OBJECTS = 200; for (uint i = 0; i < NUM_OBJECTS; ++i) { Node mushroomNode = scene_.CreateChild("Mushroom"); mushroomNode.SetPosition(new Vector3(Math.Random(90.0f) - 45.0f, 0.0f, Math.Random(90.0f) - 45.0f)); mushroomNode.SetRotation(Quaternion.FromEulerAngles(0.0f, Math.Random(360.0f), 0.0f)); mushroomNode.SetScale(0.5f + Math.Random(2.0f)); StaticModel mushroomObject = mushroomNode.CreateComponent <StaticModel>(); mushroomObject.SetModel(cache.GetResource <Model>("Models/Mushroom.mdl")); mushroomObject.SetMaterial(cache.GetResource <Material>("Materials/Mushroom.xml")); } // Create a scene node for the camera, which we will move around // The camera will use default settings (1000 far clip distance, 45 degrees FOV, set aspect ratio automatically) cameraNode_ = scene_.CreateChild("Camera"); cameraNode_.CreateComponent <Camera>(); // Set an initial position for the camera scene node above the plane cameraNode_.SetPosition(new Vector3(0.0f, 5.0f, 0.0f)); }
public Engn_Plan(Scene scene) { // Create scene node & StaticModel component for showing a static plane planeNode = scene.CreateChild("Plane"); planeNode.SetScale(new Vector3(100, 1, 100)); plane = planeNode.CreateComponent <StaticModel>(); plane.SetModel(scene.Context.Cache.GetResource <Urho3DNet.Model>("Models/Plane.mdl")); plane.SetMaterial(scene.Context.Cache.GetResource <Material>("Materials/StoneTiled.xml")); }
public StaticModel CreateStaticModel(Node node, Model model, Material material) { StaticModel staticModel = node.CreateComponent <StaticModel>(); staticModel.SetModel(model); staticModel.SetMaterial(material); staticModel.CastShadows = true; return(staticModel); }
void SetModel(string filePath) { var model = Resources.Load <Model>(filePath); staticModel.SetModel(model); }
void CreateModelfromScratch() { const int numVertices = 18; float[] vertexData = { // Position Normal Texture 0.0f, 0.5f, 0.0f, 0.5f, 0.5f, 0.5f, 0.0f, 0.0f, -0.5f, -0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, -0.5f, 0.5f, 0.5f, 0.0f, 0.5f, 1.0f, 1.0f, 0.0f, 0.5f, 0.0f, -0.5f, 0.5f, 0.0f, 0.0f, 0.0f, -0.5f, -0.5f, -0.5f, -0.5f, 0.5f, 0.0f, 0.5f, 0.5f, -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 0.0f, 0.5f, 0.0f, -0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 0.5f, -0.5f, -0.5f, -0.5f, -0.5f, 0.5f, 0.5f, 0.5f, -0.5f, -0.5f, -0.5f, -0.5f, -0.5f, 0.5f, 1.0f, 1.0f, 0.0f, 0.5f, 0.0f, -0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 0.5f, -0.5f, 0.5f, -0.5f, -0.5f, 0.5f, 1.0f, 1.0f, 0.5f, -0.5f, -0.5f, -0.5f, -0.5f, 0.5f, 0.5f, 0.5f, 0.5f, -0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 0.0f, 0.5f, 0.5f, -0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.5f, -0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 0.0f, 0.5f, 0.5f, -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f }; short[] indexData = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 }; Urho3DNet.Model fromScratchModel = new Urho3DNet.Model(Context); VertexBuffer vb = new VertexBuffer(Context, false); IndexBuffer ib = new IndexBuffer(Context, false); Geometry geom = new Geometry(Context); // Shadowed buffer needed for raycasts to work, and so that data can be automatically restored on device loss vb.SetShadowed(true); vb.SetSize(numVertices, VertexMask.MaskPosition | VertexMask.MaskNormal | VertexMask.MaskTexcoord1, false); var res = vb.SetData(vertexData); ib.SetShadowed(true); ib.SetSize(numVertices, false, false); res = ib.SetData(indexData); geom.SetVertexBuffer(0, vb); geom.IndexBuffer = ib; geom.SetDrawRange(PrimitiveType.TriangleList, 0, numVertices, true); fromScratchModel.NumGeometries = 1; fromScratchModel.SetGeometry(0, 0, geom); fromScratchModel.BoundingBox = new BoundingBox(new Vector3(-0.5f, -0.5f, -0.5f), new Vector3(0.5f, 0.5f, 0.5f)); Node node = RootNode.CreateChild("FromScratchObject"); node.Position = (new Vector3(0.0f, 3.0f, 0.0f)); StaticModel sm = node.CreateComponent <StaticModel>(); sm.SetModel(fromScratchModel); sm.CastShadows = true; //var mat = RootNode.Cache.GetResource<Material>("Materials/Stone.xml"); //sm.SetMaterial(mat); sm.SetMaterial(Material_Ext.SelectedMaterial); sm.SetModel(fromScratchModel); node.CreateComponent <RotateObject>(); }