protected override void AssembleModel() { // Attach and assemble model wheelsGroupNode.AddChild(playerSphereNode.GameNode); hullGroupNode.AddChild(playerCellsNode.GameNode); hullGroupNode.AddChild(playerMainNode.GameNode); hullGroupNode.AddChild(wheelsGroupNode); hullGroupNode.AddChild(gunGroupNode); modelNode.AddChild(hullGroupNode); controlNode = mSceneMgr.CreateSceneNode(); controlNode.AddChild(modelNode); mSceneMgr.RootSceneNode.AddChild(controlNode); float radius = 12; controlNode.Position += radius * Vector3.UNIT_Y; modelNode.Position -= radius * Vector3.UNIT_Y; physObj = new PhysObj(radius, "Player", 0.1f, 0.7f, 0.3f); physObj.SceneNode = controlNode; physObj.Position = controlNode.Position; physObj.AddForceToList(new WeightForce(physObj.InvMass)); //physObj.AddForceToList(new FrictionForce(physObj)); Physics.AddPhysObj(physObj); this.gameNode = controlNode; //base.AssembleModel(); }
private SceneNode BuildPalmAt(float atZ, String name) { float useXPos = kArmLength + 1f; // add the palm circle radius to it SceneNode palm = new SceneNode(name); palm.Xform.Pivot = new Vector3(kArmLength, 0, atZ); MeshShape c1 = new MeshShape("sphere"); c1.Xform.Scale = new Vector3(kSphereScale); c1.Xform.Translation = new Vector3(useXPos, 0, atZ); c1.Color = Color.Blue; palm.AddShape(c1); MeshShape s1 = new MeshShape("teapot"); s1.Xform.Scale = new Vector3(0.5f); s1.Xform.Translation = new Vector3(useXPos, 1.1f, atZ); s1.Color = Color.DeepPink; palm.AddShape(s1); s1 = new MeshShape("teapot"); s1.Xform.Scale = new Vector3(0.4f); s1.Xform.Translation = new Vector3(useXPos + 1.1f, 0f, atZ); s1.Color = Color.DarkSeaGreen; palm.AddShape(s1); SceneNode finger = BuildFingerAt(kArmLength + 1, atZ + 1.0f, "f1"); palm.AddChild(finger); finger = BuildFingerAt(kArmLength + 1, atZ - 1.0f, "f2"); palm.AddChild(finger); return(palm); }
// hullGroupNode = mSceneMgr.CreateSceneNode(); // hull = mSceneMgr.CreateEntity("Main.mesh"); // hull.GetMesh().BuildEdgeList(); // power = mSceneMgr.CreateEntity("PowerCells.mesh"); // power.GetMesh().BuildEdgeList(); // wheelsGroupNode = mSceneMgr.CreateSceneNode(); // sphere = mSceneMgr.CreateEntity("Sphere.mesh"); // sphere.GetMesh().BuildEdgeList(); // gunsGroupNode = mSceneMgr.CreateSceneNode(); // model = mSceneMgr.CreateSceneNode(); //} /// <summary> /// This method assemble the model attaching the entities to /// each node and appending the nodes to each other /// </summary> private void AssembleModel() { hullGroupNode.AttachObject(hull); hullGroupNode.AttachObject(power); wheelsGroupNode.AttachObject(sphere); hullGroupNode.AddChild(wheelsGroupNode); hullGroupNode.AddChild(gunsGroupNode); model.AddChild(hullGroupNode); mSceneMgr.RootSceneNode.AddChild(model); }
/// <summary> /// This method assemble the model attaching the entities to /// each node and appending the nodes to each other /// </summary> protected override void AssembleModel() { sphere.AttachObject(sphereEntity); mainHull.AttachObject(hullEntity); wheelGroup.AddChild(sphere); hullGroup.AddChild(mainHull); hullGroup.AddChild(powerCells); model.AddChild(hullGroup); hullGroup.AddChild(wheelGroup); hullGroup.AddChild(gunGroup); mSceneMgr.RootSceneNode.AddChild(model); }
private void GameEntityCreateSceneNodes(GameEntity entity, Vector3 scale, IDictionary <string, object> parameters) { /* create main node */ SceneNode mainNode = new SceneNode(); /* rest of nodes */ foreach (MeshSceneNodePrefab scnp in _sceneNodesPrefab.Values) { SceneNode scn = scnp.GetSceneNode(parameters, entity); entity.SceneNodes.Add(scnp.Name, scn); mainNode.AddChild(scn); scn.SetScale(scn.GetScale() * scale); } foreach (ArrayMeshSceneNodePrefab ascnp in _arrayMeshSceneNodesPrefab.Values) { for (int i = ascnp.StartIndex; i <= ascnp.EndIndex; i++) { SceneNode scn = ascnp.GetSceneNode(parameters, entity); mainNode.AddChild(scn); scn.SetScale(scale); if (ascnp.Path != null && entity.PhysicsEntity.GetBodyFromPath(ascnp.Path, i) != null) { BodyController controller = new BodyController(scn, entity.PhysicsEntity.GetBodyFromPath(ascnp.Path, i), entity); entity.BodyControllers.Add(controller); FrameUpdateManager.Instance.Register(controller); } } } foreach (var cameraSceneNodePrefab in _cameraSceneNodesPrefab) { mainNode.AddAttachable( new CameraAttachable(cameraSceneNodePrefab.Value.LookingDirection, cameraSceneNodePrefab.Value.UpVector, cameraSceneNodePrefab.Value.Near, cameraSceneNodePrefab.Value.Far, cameraSceneNodePrefab.Value.Fov, cameraSceneNodePrefab.Value.AspectRatio) ); } /* finish main node */ SceneManager.Instance.RegisterSceneTree(mainNode); entity.MainNode = mainNode; }
protected override void LoadModel() { base.LoadModel(); pUEntity = mSceneMgr.CreateEntity("Sphere.mesh"); pUNode = mSceneMgr.CreateSceneNode(); pUNode.Scale(0.5f, 0.5f, 0.5f); pUNode.AttachObject(pUEntity); controlNode = mSceneMgr.CreateSceneNode(); controlNode.AddChild(pUNode); mSceneMgr.RootSceneNode.AddChild(controlNode); float radius = 0.5f; controlNode.Position += radius * Vector3.UNIT_Y; pUNode.Position -= radius * Vector3.UNIT_Y; physObj = new PhysObj(radius, "Ball", 0.1f, 0.7f, 0.3f); physObj.SceneNode = controlNode; physObj.Position = controlNode.Position; physObj.AddForceToList(new WeightForce(physObj.InvMass)); Physics.AddPhysObj(physObj); physObj.SceneNode = pUNode; pUEntity.GetMesh().BuildEdgeList(); }
/// <summary> /// Constructor /// </summary> public MyModel() { mTheStack = new MatrixStack(); mMajorAxis = new AxisShape(); mMajorAxis.Xform.Scale = new Vector3(10, 10, 10); mRoot = new SceneNode("Root"); SceneNode arm = BuildArm("TopArm"); mRoot.AddChild(arm); arm.Xform.RotateInYByRadian(MathHelper.PiOver2); arm.Xform.Translation = new Vector3(0, 15, 20); InitCameraParameters(arm); arm = BuildArm("BottomArm"); mRoot.AddChild(arm); arm.Xform.Translation = new Vector3(0, 2, 0); SceneNode others = new SceneNode("Other Stuff"); mRoot.AddChild(others); MeshShape m = new MeshShape("cone"); m.Xform.Translation = new Vector3(-10, 3, 0); others.AddShape(m); SquareOnXZ s = new SquareOnXZ(); s.Xform.Scale = new Vector3(20, 20, 20); s.Xform.Translation = new Vector3(0, -2, 0); s.Color = Color.DarkGray; others.AddShape(s); m = new MeshShape("shusui"); m.Xform.Translation = new Vector3(8, 2, -10); m.Xform.Scale = new Vector3(4f); others.AddShape(m); m = new MeshShape("bigship1"); m.Xform.Translation = new Vector3(-5, 2, -5); m.Xform.Scale = new Vector3(0.5f, 0.5f, 0.5f); others.AddShape(m); }
public void TestReaddingOfChildNodeAfterRemovalByName() { Node node = new SceneNode(this.fakeSceneManager); Node childNode = node.CreateChild(Name); node.RemoveChild(Name); node.AddChild(childNode); }
private void CreateWall1() { plane1 = new Plane(Vector3.UNIT_X, -500); //plane = new Plane(Vector3.UNIT_Z, 0); MeshPtr wallMeshPtr = MeshManager.Singleton.CreatePlane("wall", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, plane1, wallWidth, wallHeight, 10, 10, true, 1, uTiles, vTiles, Vector3.UNIT_Z); //MeshPtr wallMeshPtrZ = MeshManager.Singleton.CreatePlane("wall", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, planeZ, wallWidth, wallHeight, 10, 10, true, 1, uTiles, vTiles, Vector3.UNIT_Z); wallEntity1 = mSceneMgr.CreateEntity("wall"); wallNode1 = mSceneMgr.CreateSceneNode(); wallNode1.AttachObject(wallEntity1); wallEntity1.SetMaterialName("Ground"); wallNode1.Rotate(new Quaternion(Mogre.Math.Sqrt(0.5f), -Mogre.Math.Sqrt(0.5f), 0, 0)); // Rotate -90 degrees around X axis wallMainNode.AddChild(wallNode1); }
private SceneNode BuildArm(String name) { SceneNode node = new SceneNode(name); MeshShape m = new MeshShape("cylinder"); m.Color = Color.Blue; node.AddShape(m); // arm and the decorations MeshShape arm = new MeshShape("cylinder"); arm.Xform.RotateInYByRadian(MathHelper.PiOver2); arm.Xform.Scale = new Vector3(kArmWidth * kCylinderRadiusScale, 0.7f, kArmLength * kCylinderLengthScale); arm.Xform.Translation = new Vector3(kArmLength / 2f, 0, 0); node.AddShape(arm); MeshShape c1 = new MeshShape("sphere"); c1.Xform.Scale = new Vector3(1.0f * kSphereScale); c1.Xform.Translation = new Vector3(kArmLength / 4f, 0f, 0); c1.Color = Color.DarkSlateBlue; node.AddShape(c1); c1 = new MeshShape("sphere"); c1.Xform.Scale = new Vector3(1.0f * kSphereScale); c1.Xform.Translation = new Vector3(kArmLength / 2f, 0f, 0); c1.Color = Color.Black; node.AddShape(c1); c1 = new MeshShape("sphere"); c1.Xform.Scale = new Vector3(1.0f * kSphereScale); c1.Xform.Translation = new Vector3(kArmLength * 0.75f, 0f, 0); c1.Color = Color.DarkSlateBlue; node.AddShape(c1); SceneNode palm = BuildPalmAt(kArmWidth / 2f, "Top"); node.AddChild(palm); palm = BuildPalmAt(0, "Mid"); node.AddChild(palm); palm = BuildPalmAt(-kArmWidth / 2f, "Bottom"); node.AddChild(palm); return(node); }
/// <summary> /// This method assemble the model attaching the entities to /// each node and appending the nodes to each other /// </summary> protected override void AssembleModel() { mainHull.AddChild(sphere.getModel()); mainHull.AddChild(power.getModel()); model.AddChild(mainHull.getModel()); model.AddChild(gunGroupNode); mSceneMgr.RootSceneNode.AddChild(model); GameNode = model; float radius = 5; physObj = new PhysObj(radius, "Player", 1f, 0.7f, 1f); physObj.SceneNode = gameNode; physObj.Position = gameNode.Position; physObj.AddForceToList(new WeightForce(physObj.InvMass)); physObj.AddForceToList(new FrictionForce(physObj)); Physics.AddPhysObj(physObj); }
/// <summary> /// This method assemble the model attaching the entities to /// each node and appending the nodes to each other /// </summary> private void AssembleModel() { mainHull.AttachObject(hullEntity); sphere.AttachObject(sphereEntity); mainHull.AddChild(sphere); model.AddChild(mainHull); mSceneMgr.RootSceneNode.AddChild(model); }
/// <summary> /// Moves the node to the right (ie. parent = parent.parent) on the /// scene graph. /// </summary> /// <param name="sender">Object that caused this event to be triggered.</param> /// <param name="e">Arguments explaining why this event occured.</param> private void rightButton_Click(object sender, EventArgs e) { SceneNode node = ((SceneNode)_nodeHashTable[sceneGraphTreeView.SelectedNode]); SceneNode parent = node.Parent; int index = parent.Children.IndexOf(node); SceneNode newParent = (SceneNode)parent.Children[index - 1]; parent.RemoveChild(node); newParent.AddChild(node); SyncronizeData(); }
/// <summary> // Attaches gamenode to the SceneMgr /// </summary> protected override void AssembleModel() { base.AssembleModel(); controlNode.AddChild(Model.GameNode); gameNode = controlNode; mSceneMgr.RootSceneNode.AddChild(gameNode); }
protected override void CreateScene() { // set some ambient light scene.AmbientLight = new ColorEx(1.0f, 0.5f, 0.5f, 0.5f); // create a point light (default) Light light = scene.CreateLight("MainLight"); light.Position = new Vector3(20, 80, 50); // create a prefab plane Entity plane = scene.CreateEntity("Plane", PrefabEntity.Plane); // give the plan a texture plane.MaterialName = "Transparency/BumpyMetal"; // create an entity from a model Entity knot = scene.CreateEntity("Knot", "knot.mesh"); knot.MaterialName = "Transparency/Knot"; // attach the two new entities to the root of the scene SceneNode rootNode = scene.RootSceneNode; rootNode.AttachObject(plane); rootNode.AttachObject(knot); Entity clone = null; for (int i = 0; i < 10; i++) { // create a new node under the root SceneNode node = scene.CreateSceneNode(); // calculate a random position Vector3 nodePosition = new Vector3(); nodePosition.x = MathUtil.SymmetricRandom() * 500.0f; nodePosition.y = MathUtil.SymmetricRandom() * 500.0f; nodePosition.z = MathUtil.SymmetricRandom() * 500.0f; // set the new position node.Position = nodePosition; // attach this node to the root node rootNode.AddChild(node); // clone the knot string cloneName = string.Format("Knot{0}", i); clone = knot.Clone(cloneName); // add the cloned knot to the scene node.AttachObject(clone); } }
private void CreateTranslateEntity() { _translateNode = Engine.Renderer.Scene.CreateSceneNode(); Entity xArrowEntityA; _xArrowNodeA = Engine.Renderer.CreateEntity(out xArrowEntityA, "arrow.mesh", "XA"); _xArrowNodeA.Rotate(Vector3.UNIT_Y, new Degree(90f), Node.TransformSpace.TS_WORLD); xArrowEntityA.SetMaterialName("Translate/X"); _xArrowNodeA.InheritScale = false; _xArrowNodeA.InheritOrientation = false; Entity yArrowEntityA; _yArrowNodeA = Engine.Renderer.CreateEntity(out yArrowEntityA, "arrow.mesh", "YA"); _yArrowNodeA.Rotate(Vector3.UNIT_X, new Degree(-90f), Node.TransformSpace.TS_WORLD); yArrowEntityA.SetMaterialName("Translate/Y"); _yArrowNodeA.InheritScale = false; _yArrowNodeA.InheritOrientation = false; Entity zArrowEntityA; _zArrowNodeA = Engine.Renderer.CreateEntity(out zArrowEntityA, "arrow.mesh", "ZA"); zArrowEntityA.SetMaterialName("Translate/Z"); _zArrowNodeA.InheritScale = false; _zArrowNodeA.InheritOrientation = false; Entity xArrowEntityB; _xArrowNodeB = Engine.Renderer.CreateEntity(out xArrowEntityB, "arrow.mesh", "XB"); _xArrowNodeB.Rotate(Vector3.UNIT_Y, new Degree(-90f), Node.TransformSpace.TS_WORLD); xArrowEntityB.SetMaterialName("Translate/X"); _xArrowNodeB.InheritScale = false; _xArrowNodeB.InheritOrientation = false; Entity yArrowEntityB; _yArrowNodeB = Engine.Renderer.CreateEntity(out yArrowEntityB, "arrow.mesh", "YB"); _yArrowNodeB.Rotate(Vector3.UNIT_X, new Degree(90f), Node.TransformSpace.TS_WORLD); yArrowEntityB.SetMaterialName("Translate/Y"); _yArrowNodeB.InheritScale = false; _yArrowNodeB.InheritOrientation = false; Entity zArrowEntityB; _zArrowNodeB = Engine.Renderer.CreateEntity(out zArrowEntityB, "arrow.mesh", "ZB"); zArrowEntityB.SetMaterialName("Translate/Z"); _zArrowNodeB.Rotate(Vector3.UNIT_Y, new Degree(180f), Node.TransformSpace.TS_WORLD); _zArrowNodeB.InheritScale = false; _zArrowNodeB.InheritOrientation = false; _translateNode.AddChild(_xArrowNodeA); _translateNode.AddChild(_yArrowNodeA); _translateNode.AddChild(_zArrowNodeA); _translateNode.AddChild(_xArrowNodeB); _translateNode.AddChild(_yArrowNodeB); _translateNode.AddChild(_zArrowNodeB); }
private void loadFrame(DPOW.Reader.Animation obj, int time, SceneNode parent) { SceneNode node; if (obj.getFrameOnTime(time) == null) { return; } int objid = obj.getFrameOnTime(time).ElementId; if (mgr.HasSceneNode("Element" + objid.ToString() + "_node")) { node = mgr.GetSceneNode("Element" + objid.ToString() + "_node"); if (node.Parent != null) { node.Parent.RemoveChild(node); } parent.AddChild(node); } else { node = buildElement(dpow.Elements[objid], "Element" + objid.ToString()); parent.AddChild(node); } for (int i = 0; i < obj.Childs.Length; i++) { if (obj.Childs[i].ChildIcon < 0) { loadFrame(dpow.Animations[obj.Childs[i].ChildId], time, node); } else { loadFrame(dpow.Animations[obj.Childs[i].ChildId], time, mgr.GetSceneNode("Element" + objid.ToString() + "_flag" + obj.Childs[i].ChildIcon.ToString() + "_node")); } } }
public void AttachGun(Gun gun) { // Checks whether the gunGroupNode has any child(gunGroupNode.GameNode.NumChildren()!=0) // and if it has children call the RemoveAllChildren() methods from its GameNode // outside of the if statment add the GameNode of the gun passed as parameter as child of the // GameNode of the gunGorupNode if (gunGroupNode.NumChildren() != 0) { gunGroupNode.RemoveAllChildren(); } gunGroupNode.AddChild(gun.GameNode); }
public CameraControlSystem(SceneManager sceneManager, string name, SceneNode customCameraSceneNode, bool reCalcOnTargetMoving = true) { _sceneMgr = sceneManager; _name = name; _targetNode = null; _targetNodeListener = null; _recalcOnTargetMoving = reCalcOnTargetMoving; _currentCameraMode = null; _cameraNode = _sceneMgr.RootSceneNode.CreateChildSceneNode(_name + "SceneNode"); _isOwnCamera = false; _cameraNode.AddChild(customCameraSceneNode); _cameraModes = new Dictionary <string, CameraMode>(); }
public CameraControlSystem(SceneManager sceneManager, string name, SceneNode customCameraSceneNode, bool reCalcOnTargetMoving = true) { _sceneMgr = sceneManager; _name = name; _targetNode = null; _targetNodeListener = null; _recalcOnTargetMoving = reCalcOnTargetMoving; _currentCameraMode = null; _cameraNode = _sceneMgr.RootSceneNode.CreateChildSceneNode(_name + "SceneNode"); _isOwnCamera = false; _cameraNode.AddChild(customCameraSceneNode); _cameraModes = new Dictionary<string, CameraMode>(); }
/************************************************************************/ /* add an object to another object as child */ /************************************************************************/ internal void AddObjectToObject(SceneNode _node, SceneNode _newParent) { // check if object is already has a parent if (_node.Parent != null) { // check if object is in scene already, then we are done if (_node.Parent == _newParent) { return; } // otherwise remove the object from its current parent _node.Parent.RemoveChild(_node); } // add object to scene _newParent.AddChild(_node); }
public static SceneNode CreateSceneNodes(MeshGeometry3D mesh, Point3D center, Size3D size, float modelScaleFactor, int xCount, int yCount, int zCount) { var rootSceneNode = new SceneNode(); var dxMeshGeometry3D = new DXMeshGeometry3D(mesh); float xStep = (float)(size.X / xCount); float yStep = (float)(size.Y / yCount); float zStep = (float)(size.Z / zCount); for (int z = 0; z < zCount; z++) { float zPos = (float)(center.Z - (size.Z / 2.0) + (z * zStep)); float zPercent = (float)z / (float)zCount; for (int y = 0; y < yCount; y++) { float yPos = (float)(center.Y - (size.Y / 2.0) + (y * yStep)); float yPercent = (float)y / (float)yCount; for (int x = 0; x < xCount; x++) { float xPos = (float)(center.X - (size.X / 2.0) + (x * xStep)); var matrix = new SharpDX.Matrix(modelScaleFactor, 0, 0, 0, 0, modelScaleFactor, 0, 0, 0, 0, modelScaleFactor, 0, xPos, yPos, zPos, 1); var standardMaterial = new StandardMaterial() { DiffuseColor = new Color3((float)x / (float)xCount, yPercent, zPercent) }; var meshObjectNode = new Ab3d.DirectX.MeshObjectNode(dxMeshGeometry3D, standardMaterial); meshObjectNode.Transform = new Transformation(matrix); rootSceneNode.AddChild(meshObjectNode); } } } return(rootSceneNode); }
public CollectableGun(SceneManager mSceneMgr, Gun gun, Armoury playerArmoury) { this.mSceneMgr = mSceneMgr; this.gun = gun; this.playerArmoury = playerArmoury; // Initialize the gameNode here, scale it by 1.5f using the Scale funtion, and add as its child the gameNode contained in the Gun object. // Finally attach the gameNode to the sceneGraph. collectabelGunNode = mSceneMgr.CreateSceneNode(); collectabelGunNode.Scale(1.5f, 1.5f, 1.5f); collectabelGunNode.AddChild(Gun.GameNode); mSceneMgr.RootSceneNode.AddChild(collectabelGunNode); // Here goes the link to the physics engine // (ignore until week 8) ... physObj = new PhysObj(10, "CollectabelGun", 0.1f, 0.5f); physObj.SceneNode = collectabelGunNode; physObj.AddForceToList(new WeightForce(physObj.InvMass)); Physics.AddPhysObj(physObj); }
/// <summary> /// This method loads the mesh and attaches it to a node and to the schenegraph /// </summary> private void Load() { robotEntity = mSceneMgr.CreateEntity("robot.mesh"); robotNode = mSceneMgr.CreateSceneNode(); robotNode.AttachObject(robotEntity); //mSceneMgr.RootSceneNode.AddChild(robotNode); controlNode = mSceneMgr.CreateSceneNode(); controlNode.AddChild(robotNode); mSceneMgr.RootSceneNode.AddChild(controlNode); float radius = 50; controlNode.Position += radius * Vector3.UNIT_Y; robotNode.Position -= radius * Vector3.UNIT_Y; physObj = new PhysObj(radius, "Robot", 0.1f, 0.2f, 0.5f); physObj.SceneNode = controlNode; physObj.Position = controlNode.Position; physObj.AddForceToList(new WeightForce(physObj.InvMass)); physObj.AddForceToList(new FrictionForce(physObj)); Physics.AddPhysObj(physObj); }
/// <summary> // Attach the objects of the player model and add to the scenemanager /// </summary> protected override void AssembleModel() { HullGroupNode.AddChild(PowerCells.GameNode); HullGroupNode.AddChild(Hull.GameNode); WheelGroupNode.AddChild(Sphere.GameNode); HullGroupNode.AddChild(WheelGroupNode.GameNode); HullGroupNode.AddChild(GunGroupNode.GameNode); Model.AddChild(HullGroupNode.GameNode); controlNode.AddChild(Model.GameNode); Hull.GameEntity.GetMesh().BuildEdgeList(); //add shadows //you should initialize the gameNode of the PlayerModel class to the gameNode in the ModelElement model object, i.e. gameNode=model.GameNode; gameNode = controlNode; //The assembling of the scene manager should happen in the AssembleModelElements mSceneMgr.RootSceneNode.AddChild(gameNode); }
/// <summary> /// This method adds a child to the node of this model element /// </summary> /// <param name="childNode"></param> public void AddChild(SceneNode childNode) { //YOUR NODE FOR ATTACHING A CHILDNODE TO THE GAMENODE GOES HERE model.AddChild(childNode); }
public void SetGizmoVisual(GizmoVisual visual) { _sceneNode.AddChild(visual.Base); _gizmoVisual = visual; ReloadGizmo(); }
public static SceneNode CreateLineSceneNodes(Point3D center, Size3D size, bool useSingleColor, int xCount, int yCount, int zCount, DisposeList disposables) { var rootSceneNode = new SceneNode(); float xStep = (float)(size.X / xCount); float yStep = (float)(size.Y / yCount); float zStep = (float)(size.Z / zCount); float xHalfLineSize = xStep * 0.3f; //float yHalfLineSize = xStep * 0.3f; float zHalfLineSize = xStep * 0.3f; var singleColorLineMaterial = new LineMaterial() { LineColor = Colors.Orange.ToColor4(), LineThickness = 2 }; if (disposables != null) { disposables.Add(singleColorLineMaterial); } for (int z = 0; z < zCount; z++) { float zPos = (float)(center.Z - (size.Z / 2.0) + (z * zStep)); float zPercent = (float)z / (float)zCount; for (int y = 0; y < yCount; y++) { float yPos = (float)(center.Y - (size.Y / 2.0) + (y * yStep)); float yPercent = (float)y / (float)yCount; for (int x = 0; x < xCount; x++) { float xPos = (float)(center.X - (size.X / 2.0) + (x * xStep)); var linePositions = new Vector3[] { new Vector3(xPos - xHalfLineSize, yPos, zPos - zHalfLineSize), new Vector3(xPos + xHalfLineSize, yPos, zPos + zHalfLineSize), new Vector3(xPos - xHalfLineSize, yPos, zPos + zHalfLineSize), new Vector3(xPos + xHalfLineSize, yPos, zPos - zHalfLineSize), }; LineMaterial usedLineMaterial; if (useSingleColor) { // Using single color improved performance by 30% because we do not need to update per-object constant buffer for each line. usedLineMaterial = singleColorLineMaterial; } else { usedLineMaterial = new LineMaterial() { LineColor = new Color4((float)x / (float)xCount, yPercent, zPercent, 1), LineThickness = 2 }; if (disposables != null) { disposables.Add(usedLineMaterial); } } // NOTE: // The sample can also show many instances of ScreenSpaceLineNode to simulate showing many different 3D lines. // It would be much better to use a single ScreenSpaceLineNode and set all line positions to that object. var screenSpaceLineNode = new ScreenSpaceLineNode(linePositions, isLineStrip: false, isLineClosed: false, lineMaterial: usedLineMaterial); rootSceneNode.AddChild(screenSpaceLineNode); } } } return(rootSceneNode); }
private void MainDXViewportViewOnDXSceneDeviceCreated(object sender, EventArgs e) { var instancedData = CreateInstancesData(center: new Point3D(0, 0, 0), size: new Size3D(4 * XInstancesCount, 4 * YInstancesCount, 4 * ZInstancesCount), modelScaleFactor: 1, xCount: XInstancesCount, yCount: YInstancesCount, zCount: ZInstancesCount, useTransparency: false); // Update colors int dataCount = instancedData.Length; for (int i = 0; i < dataCount; i++) { float percentage = 1.0f - (float)i / (float)dataCount; instancedData[i].DiffuseColor = new Color4(red: percentage, green: 1, blue: percentage, alpha: 1); } var boxMeshGeometry = new Ab3d.Meshes.BoxMesh3D(centerPosition: new Point3D(0, 0, 0), size: new Size3D(3, 3, 3), xSegments: 1, ySegments: 1, zSegments: 1).Geometry; // The first InstancedMeshGeometry3DNode will get the instancedData and // will also create the DirectX instance buffer. _instancedMeshGeometry3DNode1 = new InstancedMeshGeometry3DNode(boxMeshGeometry); _instancedMeshGeometry3DNode1.SetInstanceData(instancedData); // Manually call InitializeResources. // For this to work, the dxViewportView.DXScene must be set. // This is the reason why this method is called inside a DXViewportView.DXSceneDeviceCreated event handler. _instancedMeshGeometry3DNode1.InitializeResources(MainDXViewportView.DXScene); _disposables.Add(_instancedMeshGeometry3DNode1); var instanceBuffer = _instancedMeshGeometry3DNode1.GetInstanceBuffer(); if (instanceBuffer == null) { throw new Exception("GetInstanceBuffer returned null"); // Probably DXScene is not initialized } // Now create another 2 InstancedMeshGeometry3DNode objects // and initialize it with already created instanceBuffer // The next InstancedMeshGeometry3DNode will be also initialized so // that all instances will be rendered with red color instead of the color defined in the instances data. _instancedMeshGeometry3DNode2 = new InstancedMeshGeometry3DNode(boxMeshGeometry); _instancedMeshGeometry3DNode2.SetInstanceBuffer(instanceBuffer, InstanceData.SizeInBytes, instancedData.Length, instancedData); _instancedMeshGeometry3DNode2.UseSingleObjectColor(Colors.Red.ToColor4()); _disposables.Add(_instancedMeshGeometry3DNode2); // The last InstancedMeshGeometry3DNode will render last part of the instances with the color defined in the instance data. _instancedMeshGeometry3DNode3 = new InstancedMeshGeometry3DNode(boxMeshGeometry); _instancedMeshGeometry3DNode3.SetInstanceBuffer(instanceBuffer, InstanceData.SizeInBytes, instancedData.Length, instancedData); _disposables.Add(_instancedMeshGeometry3DNode3); // Set StartInstanceIndex and InstancesCount _startTime = DateTime.Now; _lastStartRowIndex = int.MinValue; UpdateHiddenInstancesPositions(); var rootSceneNode = new SceneNode(); rootSceneNode.AddChild(_instancedMeshGeometry3DNode1); rootSceneNode.AddChild(_instancedMeshGeometry3DNode2); rootSceneNode.AddChild(_instancedMeshGeometry3DNode3); var sceneNodeVisual3D = new SceneNodeVisual3D(rootSceneNode); MainViewport.Children.Add(sceneNodeVisual3D); }
protected override void CreateScene() { mLog = LogManager.Singleton.createLog("RSQTest.log", false, true); mLog.LogMessage(string.Format("RSQTest log {0}", System.DateTime.Now)); create4LineDebugOverLay(); Show4LineDebugOverLay(); //setup RenderTargetListenerDirector mRTListener = new RenderTargetListenerDirector(); mRTListener.SubscribeEvents(); mRTListener.evtPreRenderTargetUpdate += new RenderTargetListenerDirector.RTLD_Delegate_RenderTargetUpdate(event_PreRenderTargetUpdate); mRTListener.evtPostRenderTargetUpdate += new RenderTargetListenerDirector.RTLD_Delegate_RenderTargetUpdate(event_PostRenderTargetUpdate); mSceneManager.SetAmbientLight(Converter.GetColor(0.2f, 0.2f, 0.2f)); mSceneManager.SetSkyBox(true, "Examples/MorningSkyBox"); // Create a light Light l = mSceneManager.CreateLight("MainLight"); l.SetLightType(OgreDotNet.Light.LightTypes.Directional); Math3D.Vector3 dir = new Vector3(0.5f, -1.0f, 0.0f); dir.Normalize(); l.SetDirection(dir); l.SetDiffuseColour(1.0f, 1.0f, 0.8f); l.SetSpecularColour(1.0f, 1.0f, 1.0f); // Create a prefab plane mPlane = new MovablePlane("ReflectPlane"); mPlane.D = 0; mPlane.Normal = OgreVector3.FromVector3(Math3D.Vector3.UnitY); MeshManager.GetSingleton().CreatePlane("ReflectionPlane", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, mPlane, 2000, 2000, 1, 1, true, 1, 1, 1, Vector3.UnitZ); mPlaneEnt = mSceneManager.CreateEntity("Plane", "ReflectionPlane"); // Create an entity from a model (will be loaded automatically) Entity knotEnt = mSceneManager.CreateEntity("Knot", "knot.mesh"); // Create an entity from a model (will be loaded automatically) Entity ogreHead = mSceneManager.CreateEntity("Head", "ogrehead.mesh"); knotEnt.SetMaterialName("Examples/TextureEffect2"); // Attach the rtt entity to the root of the scene SceneNode rootNode = mSceneManager.GetRootSceneNode(); mPlaneNode = rootNode.CreateChildSceneNode(); // Attach both the plane entity, and the plane definition mPlaneNode.AttachObject(mPlaneEnt); //multi Inheritence problem, use the static Get*From function to convert MovableObject mo = MovableObject.GetMovableObjectFrom(mPlane); mPlaneNode.AttachObject(mo); mPlaneNode.Translate(0.0f, -10.0f, 0.0f); // Tilt it a little to make it interesting //mPlaneNode.Roll( new Radian( new Degree( 5.0f)) ); mPlaneNode.Roll(5.0f); rootNode.CreateChildSceneNode("Head").AttachObject(ogreHead); RenderTexture rttTex = mRoot.GetRenderSystem().CreateRenderTexture("RttTex", 512, 512, TextureType.TEX_TYPE_2D, PixelFormat.PF_R8G8B8); { //new scope for some reason mReflectCam = mSceneManager.CreateCamera("ReflectCam"); mReflectCam.SetNearClipDistance(mCamera.GetNearClipDistance()); mReflectCam.SetFarClipDistance(mCamera.GetFarClipDistance()); mReflectCam.SetAspectRatio( (float)mRenderWindow.GetViewport(0).ActualWidth / (float)mRenderWindow.GetViewport(0).ActualHeight); Viewport v = rttTex.AddViewport(mReflectCam); v.ClearEveryFrame = true; v.BackgroundColor = System.Drawing.Color.Black; //Converter.ToColor( ColourValue.Black ); ResourcePtr resPtr = MaterialManager.Instance.Create("RttMat", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME); MaterialPtr mat = new MaterialPtr(ResourcePtr.getCPtr(resPtr).Handle, false); TextureUnitState t = mat.Get().GetTechnique(0).getPass(0).createTextureUnitState("RustedMetal.jpg"); t = mat.Get().GetTechnique(0).getPass(0).createTextureUnitState("RttTex"); // Blend with base texture t.setColourOperationEx(LayerBlendOperationEx.LBX_BLEND_MANUAL, LayerBlendSource.LBS_TEXTURE, LayerBlendSource.LBS_CURRENT, Color.White, Color.White, 0.25f); t.SetTextureAddressingMode(TextureUnitState.TextureAddressingMode.TAM_CLAMP); t.setProjectiveTexturing(true, mReflectCam); rttTex.AddListener(mRTListener); // set up linked reflection mReflectCam.EnableReflection(mPlane); // Also clip mReflectCam.EnableCustomNearClipPlane(mPlane); } // Give the plane a texture mPlaneEnt.SetMaterialName("RttMat"); // Add a whole bunch of extra transparent entities Entity cloneEnt; for (int n = 0; n < 10; ++n) { // Create a new node under the root SceneNode node = mSceneManager.CreateSceneNode(); // Random translate Vector3 nodePos; nodePos.x = OgreMath.SymmetricRandom() * 750.0f; nodePos.y = OgreMath.SymmetricRandom() * 100.0f + 25.0f; nodePos.z = OgreMath.SymmetricRandom() * 750.0f; node.SetPosition(nodePos); rootNode.AddChild(node); // Clone knot string cloneName = string.Format("Knot{0}", n); cloneEnt = knotEnt.Clone(cloneName); // Attach to new node node.AttachObject(cloneEnt); } mCamera.SetPosition(new Vector3(-50.0f, 100.0f, 500.0f)); mCamera.LookAt = new Vector3(0, 0, 0); }
/// <summary> /// create a bunch of crap /// </summary> void CreateThings() { // a directional light to cast shadows /*directionalLight = sceneMgr.CreateLight("sun"); directionalLight.Type = Light.LightTypes.LT_DIRECTIONAL; directionalLight.Direction = new Vector3(0.5f, -1, -0.2f); directionalLight.Direction.Normalise(); directionalLight.DiffuseColour = ColourValue.Red; directionalLight.SpecularColour = ColourValue.Red; directionalLight.Position = new Vector3(0, 10, 0); directionalLight.CastShadows = true;*/ directionalLight2 = sceneMgr.CreateLight("sun2"); directionalLight2.Type = Light.LightTypes.LT_DIRECTIONAL; directionalLight2.Direction = new Vector3(-0.1f, -1, 0.1f); directionalLight2.Direction.Normalise(); directionalLight2.DiffuseColour = new ColourValue(1f, 1f, 1f); directionalLight2.SpecularColour = new ColourValue(1f, 1f, 1f); directionalLight2.Position = new Vector3(0, 10, 0); directionalLight2.CastShadows = true; // and a point light /*pointLight = sceneMgr.CreateLight("pointLight"); pointLight.Type = Light.LightTypes.LT_POINT; pointLight.Position = new Vector3(-3, 10, 3); pointLight.DiffuseColour = ColourValue.Blue; pointLight.SpecularColour = ColourValue.Blue; pointLight.CastShadows = true; // and a spotlight spotLight = sceneMgr.CreateLight("spotLight"); spotLight.Type = Light.LightTypes.LT_SPOTLIGHT; spotLight.DiffuseColour = ColourValue.Green; spotLight.SpecularColour = ColourValue.Green; spotLight.Direction = new Vector3(-1, -1, 0); spotLight.Position = new Vector3(10, 10, 0); spotLight.SetSpotlightRange(new Degree(35), new Degree(50)); spotLight.CastShadows = true;*/ // a plane for the shadows to be cast on Plane plane = new Plane(Vector3.UNIT_Y, 0); MeshManager.Singleton.CreatePlane("ground", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, plane, 100, 100, 10, 10, true, 1, 10, 10, Vector3.UNIT_Z); Entity groundEnt = sceneMgr.CreateEntity("GroundEntity", "ground"); sceneMgr.RootSceneNode.CreateChildSceneNode().AttachObject(groundEnt); groundEnt.SetMaterialName("brick"); groundEnt.CastShadows = false; // and then some boxes that will cast the shadows /*rotatingNode = CreateBox(new Vector3(0, 4, 0), "redbrick"); CreateBox(new Vector3(2, 1.1f, 2), "bluebrick"); CreateBox(new Vector3(-1, 2, -3), "yellowbrick");*/ rotatingNode = CreateNode(new Vector3(0, 0, 0), "BgPonyBody.mesh", "BgPony"); SceneNode wingsNode = CreateNode(new Vector3(0, 0.3848f, 0.0808f), "BgPonyWings.mesh", "BgPonyWings"); wingsNode.ParentSceneNode.RemoveChild(wingsNode); rotatingNode.AddChild(wingsNode); SceneNode hornNode = CreateNode(new Vector3(0, 0.721f, 0.325f), "BgPonyHorn.mesh", "BgPonyHorn"); hornNode.ParentSceneNode.RemoveChild(hornNode); rotatingNode.AddChild(hornNode); SceneNode eyeNode = CreateNode(new Vector3(0, 0.601f, 0.305f), "BgPonyEyes.mesh", "BgPonyEyes"); eyeNode.ParentSceneNode.RemoveChild(eyeNode); rotatingNode.AddChild(eyeNode); SceneNode hairNode = CreateNode(new Vector3(0, 0.765f, 0.229f), "BgPonyHair1.mesh", "BgPonyHair_2Colours"); hairNode.ParentSceneNode.RemoveChild(hairNode); rotatingNode.AddChild(hairNode); SceneNode maneNode = CreateNode(new Vector3(0, 0.7256f, 0.1058f), "BgPonyMane1.mesh", "BgPonyHair_2Colours"); maneNode.ParentSceneNode.RemoveChild(maneNode); rotatingNode.AddChild(maneNode); SceneNode tailNode = CreateNode(new Vector3(0, 0.4536f, -0.0782f), "BgPonyTail1.mesh", "BgPonyHair_2Colours"); tailNode.ParentSceneNode.RemoveChild(tailNode); rotatingNode.AddChild(tailNode); MaterialPtr mat = MaterialManager.Singleton.GetByName("BgPony"); var ps = mat.GetTechnique(0).GetPass(0).GetFragmentProgramParameters(); ps.SetNamedConstant("BodyColour", new ColourValue(1, 0, 0)); mat.GetTechnique(0).GetPass(0).SetFragmentProgramParameters(ps); //mat.Reload(); //(rotatingNode.GetAttachedObject(0) as Entity).SetMaterial(mat); }
public void AddChild(SceneNode child) { robotNode.AddChild(child); }