void SetupCollisionNodes(SCNNode node) { if (node.Geometry != null) { Console.WriteLine(node.Name); node.PhysicsBody = SCNPhysicsBody.CreateStaticBody(); node.PhysicsBody.CategoryBitMask = (nuint)(int)Bitmask.Collision; var options = new SCNPhysicsShapeOptions { ShapeType = SCNPhysicsShapeType.ConcavePolyhedron }; node.PhysicsBody.PhysicsShape = SCNPhysicsShape.Create(node, options); // Get grass area to play the right sound steps if (node.Geometry.FirstMaterial.Name == "grass-area") { if (grassArea != null) { node.Geometry.FirstMaterial = grassArea; } else { grassArea = node.Geometry.FirstMaterial; } } // Get the water area if (node.Geometry.FirstMaterial.Name == "water") { waterArea = node.Geometry.FirstMaterial; } // Temporary workaround because concave shape created from geometry instead of node fails SCNNode child = SCNNode.Create(); node.AddChildNode(child); child.Hidden = true; child.Geometry = node.Geometry; node.Geometry = null; node.Hidden = false; if (node.Name == "water") { node.PhysicsBody.CategoryBitMask = (nuint)(int)Bitmask.Water; } } foreach (SCNNode child in node.ChildNodes) { if (!child.Hidden) { SetupCollisionNodes(child); } } }
public SCNPhysicsBody MakePhysicsBody(SCNGeometry geometry) { var option = new SCNPhysicsShapeOptions(); option.KeepAsCompound = true; option.ShapeType = SCNPhysicsShapeType.ConcavePolyhedron; var shape = SCNPhysicsShape.Create(geometry, option); return(SCNPhysicsBody.CreateBody(type: SCNPhysicsBodyType.Static, shape)); }
void SetupPathColliders() { // Collect all the nodes that start with path_ under the dummy_front object. // Set those objects as Physics category ground and create a static concave mesh collider. // The simulation will use these as the ground to walk on. SCNNode front = RootNode.FindChildNode("dummy_front", true); foreach (var fronChild in front.ChildNodes) { foreach (var child in fronChild.ChildNodes) { if (child.Name.Contains("path_")) { //the geometry is attached to the first child node of the node named path SCNNode path = child.ChildNodes [0]; var options = new SCNPhysicsShapeOptions { ShapeType = SCNPhysicsShapeType.ConcavePolyhedron }; path.PhysicsBody = SCNPhysicsBody.CreateBody(SCNPhysicsBodyType.Static, SCNPhysicsShape.Create(path.Geometry, options)); path.PhysicsBody.CategoryBitMask = GameCollisionCategory.Ground; } } } }
void SetupPathColliders () { // Collect all the nodes that start with path_ under the dummy_front object. // Set those objects as Physics category ground and create a static concave mesh collider. // The simulation will use these as the ground to walk on. SCNNode front = RootNode.FindChildNode ("dummy_front", true); foreach (var fronChild in front.ChildNodes) foreach (var child in fronChild.ChildNodes) { if (child.Name.Contains ("path_")) { //the geometry is attached to the first child node of the node named path SCNNode path = child.ChildNodes [0]; var options = new SCNPhysicsShapeOptions { ShapeType = SCNPhysicsShapeType.ConcavePolyhedron }; path.PhysicsBody = SCNPhysicsBody.CreateBody (SCNPhysicsBodyType.Static, SCNPhysicsShape.Create (path.Geometry, options)); path.PhysicsBody.CategoryBitMask = GameCollisionCategory.Ground; } } }
void SetupCollisionNodes (SCNNode node) { if (node.Geometry != null) { Console.WriteLine (node.Name); node.PhysicsBody = SCNPhysicsBody.CreateStaticBody (); node.PhysicsBody.CategoryBitMask = (nuint)(int)Bitmask.Collision; var options = new SCNPhysicsShapeOptions { ShapeType = SCNPhysicsShapeType.ConcavePolyhedron }; node.PhysicsBody.PhysicsShape = SCNPhysicsShape.Create (node, options); // Get grass area to play the right sound steps if (node.Geometry.FirstMaterial.Name == "grass-area") { if (grassArea != null) node.Geometry.FirstMaterial = grassArea; else grassArea = node.Geometry.FirstMaterial; } // Get the water area if (node.Geometry.FirstMaterial.Name == "water") waterArea = node.Geometry.FirstMaterial; // Temporary workaround because concave shape created from geometry instead of node fails SCNNode child = SCNNode.Create (); node.AddChildNode (child); child.Hidden = true; child.Geometry = node.Geometry; node.Geometry = null; node.Hidden = false; if (node.Name == "water") node.PhysicsBody.CategoryBitMask = (nuint)(int)Bitmask.Water; } foreach (SCNNode child in node.ChildNodes) { if (!child.Hidden) SetupCollisionNodes (child); } }