protected override void Init() { _meshComponent = Components.Single(c => c.Id == MeshComponentId) as MeshComponent; _meshRenderComponent = Components.Single(c => c.Id == MeshRenderComponentId) as MeshRenderComponent; _meshComponent.MeshResourceName = "cube"; }
protected override void Init() { /* todo: re-use rendercomponent, like cube !! */ _meshComponent = Components.Single(c => c.Id == MeshComponentId) as MeshComponent; _meshRenderComponent = Components.Single(c => c.Id == MeshRenderComponentId) as MeshRenderComponent; Rings = 16; Segments = 16; }
protected override void Init() { _meshComponent = Components.Single(c => c.Id == MeshComponentId) as MeshComponent; _meshRenderComponent = Components.Single(c => c.Id == MeshRenderComponentId) as MeshRenderComponent; _textComponent = Components.Single(c => c.Id == TextComponentId) as TextComponent; _textComponent.FontName = "bmpfont"; _meshComponent.Material.TextureName = "bmpfont_0.text"; DistanceSorting = true; }
public MeshRenderComponent CloneForReuse() { if (!IsLoaded) Load(); var meshRenderComponent = new MeshRenderComponent(); meshRenderComponent._bufferIds = _bufferIds; meshRenderComponent._isClone = true; return meshRenderComponent; }
public override bool InternalLoad() { base.InternalLoad(); _renderComponent = GameObject.Components.FirstOrDefault(c => c is MeshRenderComponent) as MeshRenderComponent; _meshComponent = GameObject.Components.FirstOrDefault(c => c is MeshComponent) as MeshComponent; _rigidBodyComponent = GameObject.Components.FirstOrDefault(c => c is RigidBodyBaseComponent) as RigidBodyBaseComponent; /* loaded if textcomponent is found */ return _renderComponent != null && _meshComponent != null; }
protected override void Init() { /* todo: re-use rendercomponent, like cube !! */ _meshComponent = Components.Single(c => c.Id == MeshComponentId) as MeshComponent; _meshRenderComponent = Components.Single(c => c.Id == MeshRenderComponentId) as MeshRenderComponent; _rigidBodyComponent = Components.Single(c => c.Id == RigidBodyFarseerComponentId) as RigidBodyFarseerComponent; _sphereColliderComponent = Components.Single(c => c.Id == SphereColliderFarseerComponentId) as SphereColliderFarseerComponent; Rings = 16; Segments = 16; }
public Cube(float depth, float height, float width) { Depth = depth; Height = height; Width = width; var halfWidth = Width / 2.0f; var halfHeight = Height / 2.0f; var halfDepth = Depth / 2.0f; _meshComponent = new MeshComponent(this); /* create cube vertices */ var vertices = new Vector3[8]; vertices[0] = new Vector3(-halfWidth, -halfHeight, halfDepth); vertices[1] = new Vector3(halfWidth, -halfHeight, halfDepth); vertices[2] = new Vector3(halfWidth, halfHeight, halfDepth); vertices[3] = new Vector3(-halfWidth, halfHeight, halfDepth); vertices[4] = new Vector3(-halfWidth, -halfHeight, -halfDepth); vertices[5] = new Vector3(halfWidth, -halfHeight, -halfDepth); vertices[6] = new Vector3(halfWidth, halfHeight, -halfDepth); vertices[7] = new Vector3(-halfWidth, halfHeight, -halfDepth); /* create indices */ var indices = new short[]{ // front face 0, 1, 2, 2, 3, 0, // top face 3, 2, 6, 6, 7, 3, // back face 7, 6, 5, 5, 4, 7, // left face 4, 0, 3, 3, 7, 4, // bottom face 0, 1, 5, 5, 4, 0, // right face 1, 5, 6, 6, 2, 1 }; _meshComponent.Vertices = vertices; _meshComponent.Indices = indices; _meshComponent.CalculateNormals(); AddComponent(_meshComponent); _meshRenderComponent = new MeshRenderComponent(this); AddComponent(_meshRenderComponent); }
private void LoadGizmo() { YDirectionArrow.Scale = new Vector3(1, 3, 1); YDirectionArrow.Position = new Vector3(0, ArrowLength, 0); var mesh = new MeshComponent(); var vertices = new Vector3[5]; vertices[0] = new Vector3(-1, -0.5f, -1); vertices[1] = new Vector3(-1, -0.5f, 1); vertices[2] = new Vector3(0, 0.5f, 0); vertices[3] = new Vector3(1, -0.5f, 1); vertices[4] = new Vector3(1, -0.5f, -1); var indices = new short[18]; int index = 0; indices[index++] = 0; indices[index++] = 1; indices[index++] = 2; indices[index++] = 1; indices[index++] = 3; indices[index++] = 2; indices[index++] = 3; indices[index++] = 4; indices[index++] = 2; indices[index++] = 4; indices[index++] = 0; indices[index++] = 2; indices[index++] = 3; indices[index++] = 1; indices[index++] = 0; indices[index++] = 0; indices[index++] = 4; indices[index++] = 3; mesh.Vertices = vertices; mesh.Indices = indices; mesh.UV = new Vector2[vertices.Length]; mesh.Material.Ambient = new Vector4(0, 0, 1, 1); mesh.Material.Diffuse = Vector4.Zero; mesh.CalculateNormals(); var render = new MeshRenderComponent(); YDirectionArrow.AddComponent(mesh); YDirectionArrow.AddComponent(render); ZDirectionArrow.Rotation = new Vector3((float)(System.Math.PI / 2.0f), 0, 0); ZDirectionArrow.Scale = new Vector3(1, 3, 1); ZDirectionArrow.Position = new Vector3(0, 0, ArrowLength); var zMesh = new MeshComponent(); zMesh.Vertices = mesh.Vertices; zMesh.Normals = mesh.Normals; zMesh.Indices = mesh.Indices; zMesh.UV = mesh.UV; zMesh.Material.Ambient = new Vector4(1, 0, 0, 1); zMesh.Material.Diffuse = Vector4.Zero; render = render.CloneForReuse(); ZDirectionArrow.AddComponent(zMesh); ZDirectionArrow.AddComponent(render); XDirectionArrow.Rotation = new Vector3(0, 0, -(float)(System.Math.PI / 2.0f)); XDirectionArrow.Scale = new Vector3(1, 3, 1); XDirectionArrow.Position = new Vector3(ArrowLength, 0, 0); var xMesh = new MeshComponent(); xMesh.Vertices = mesh.Vertices; xMesh.Normals = mesh.Normals; xMesh.Indices = mesh.Indices; xMesh.UV = mesh.UV; xMesh.Material.Ambient = new Vector4(0, 1, 0, 1); xMesh.Material.Diffuse = Vector4.Zero; render = render.CloneForReuse(); XDirectionArrow.AddComponent(xMesh); XDirectionArrow.AddComponent(render); _xDirection.Scale = new Vector3(ArrowLength, 0.5f, 0.5f); _xDirection.Position = new Vector3((ArrowLength / 2.0f) - 0.25f, 0, 0); ((Cube)_xDirection).Material.Ambient = new Vector4(0, 1, 0, 1); ((Cube)_xDirection).Material.Diffuse = Vector4.Zero; _yDirection.Scale = new Vector3(0.5f, ArrowLength, 0.5f); _yDirection.Position = new Vector3(0, (ArrowLength / 2.0f) - 0.25f, 0); ((Cube)_yDirection).Material.Ambient = new Vector4(0, 0, 1, 1); ((Cube)_yDirection).Material.Diffuse = Vector4.Zero; _zDirection.Scale = new Vector3(0.5f, 0.5f, ArrowLength); _zDirection.Position = new Vector3(0, 0, (ArrowLength / 2.0f) - 0.25f); ((Cube)_zDirection).Material.Ambient = new Vector4(1, 0, 0, 1); ((Cube)_zDirection).Material.Diffuse = Vector4.Zero; Scale = new Vector3(0.1f, 0.1f, 0.1f); Designer = true; UniformSphere.Material.Ambient = new Vector4(1, 1, 1, 1); UniformSphere.Scale = new Vector3(3); UniformSphere.Visible = ShowUniformSphere; UniformSphere.Enabled = ShowUniformSphere; }
private void LoadPlane() { MeshRenderComponent cachedMeshRenderComponent = null; MeshComponent cachedMeshComponent = null; GameComponent cachedComponent; Scene.ComponentCache.TryGetValue(MeshRenderComponentId, out cachedComponent); cachedMeshRenderComponent = cachedComponent as MeshRenderComponent; Scene.ComponentCache.TryGetValue(MeshComponentId, out cachedComponent); cachedMeshComponent = cachedComponent as MeshComponent; if (cachedMeshRenderComponent == null) { var halfWidth = 0.5f; var halfHeight = 0.5f; var vertices = new Vector3[6]; var uv = new Vector2[6]; // front (+y) vertices[0] = new Vector3(halfWidth, -halfHeight, 0); vertices[1] = new Vector3(-halfWidth, halfHeight, 0); vertices[2] = new Vector3(-halfWidth, -halfHeight, 0); vertices[3] = new Vector3(halfWidth, -halfHeight, 0); vertices[4] = new Vector3(halfWidth, halfHeight, 0); vertices[5] = new Vector3(-halfWidth, halfHeight, 0); uv[0] = new Vector2(1, 1); uv[1] = new Vector2(0, 0); uv[2] = new Vector2(0, 1); uv[3] = new Vector2(1, 1); uv[4] = new Vector2(1, 0); uv[5] = new Vector2(0, 0); var indices = new short[] { 0, 1, 2, 3, 4, 5 }; _meshComponent.Vertices = vertices; _meshComponent.Indices = indices; _meshComponent.UV = uv; _meshComponent.CalculateNormals(); Scene.ComponentCache.Add(MeshRenderComponentId, _meshRenderComponent); Scene.ComponentCache.Add(MeshComponentId, _meshComponent); } else { /* reuse vertex buffers */ _meshComponent.Vertices = cachedMeshComponent.Vertices; _meshComponent.Normals = cachedMeshComponent.Normals; _meshComponent.Indices = cachedMeshComponent.Indices; _meshComponent.UV = cachedMeshComponent.UV; this.RemoveComponent(_meshRenderComponent); _meshRenderComponent = cachedMeshRenderComponent.CloneForReuse(); this.AddComponent(_meshRenderComponent); } }
protected override void Init() { _meshComponent = Components.Single(c => c.Id == MeshComponentId) as MeshComponent; _meshRenderComponent = Components.Single(c => c.Id == MeshRenderComponentId) as MeshRenderComponent; }
protected override void Init() { _meshComponent = Components.Single(c => c.Id == MeshComponentId) as MeshComponent; _meshRenderComponent = Components.Single(c => c.Id == MeshRenderComponentId) as MeshRenderComponent; _rigidBodyComponent = Components.Single(c => c.Id == RigidBodyFarseerComponentId) as RigidBodyFarseerComponent; _circleColliderComponent = Components.Single(c => c.Id == CircleColliderFarseerComponentId) as CircleColliderFarseerComponent; _fixedRevoluteJoinComponent = Components.Single(c => c.Id == FixedRevoluteJointComponentId) as FixedRevoluteJointComponent; _meshComponent.MeshResourceName = "cylinder"; _meshComponent.Material.TextureName = "fabric"; }
protected override void Init() { _meshComponent = Components.Single(c => c.Id == MeshComponentId) as MeshComponent; _meshRenderComponent = Components.Single(c => c.Id == MeshRenderComponentId) as MeshRenderComponent; _rigidBodyComponent = Components.Single(c => c.Id == RigidBodyFarseerComponentId) as RigidBodyFarseerComponent; _boxColliderComponent = Components.Single(c => c.Id == BoxColliderFarseerComponentId) as BoxColliderFarseerComponent; _meshComponent.MeshResourceName = "cube"; }