public override void Init() { RC.ClearColor = new float4(0, 0, 0, 1); Mesh = new Cube(); var sp = MoreShaders.GetDiffuseColorShader(RC); RC.SetShader(sp); _vColor = RC.GetShaderParam(sp, "color"); RC.SetShaderParam(_vColor, new float4(0.8f, 0.1f, 0.1f, 1)); // sound by http://www.soundjay.com _audio1 = Audio.Instance.LoadFile("Assets/beep.ogg"); // excerpt from "the final rewind" by tryad (http://www.tryad.org) - cc-by-sa _audio2 = Audio.Instance.LoadFile("Assets/music.ogg"); _state = 0; _testID = 1; _timeStep = 1.0f; _curTime = 2.0f; _tests = new Tests(); }
// is called on startup public override void Init() { RC.ClearColor = new float4(0.1f, 0.1f, 0.5f, 1); // IMPORTANT: You are supposed to use either one SetWindowSize() or VideoWall(). You can't use both. // It's possible to resize a window to fit on a video wall or display. // Here are some different variants how to use this functionality. Uncomment to test. //SetWindowSize(800, 600); SetWindowSize(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height/9 * 2, true, 0, 0); //SetWindowSize(Screen.PrimaryScreen.Bounds.Width/9 * 2, Screen.PrimaryScreen.Bounds.Height, true, 0, 0); //SetWindowSize(640, 480, false, Screen.PrimaryScreen.Bounds.Width/2 - 640/2, Screen.PrimaryScreen.Bounds.Height/2 - 480/2); // IMPORTANT: For video Walls or projector matrices it's possible to let the system do the magic by // giving it the number of monitors/projectors per axis and specify some border information. // This only works in pseudo-fullscreen mode a.k.a borderless fullscreen-window. //VideoWall(0, 0, true, false); // This is the old method. More than this could not be done directly in a project code(?) //Width = 640; //Height = 480; // Initialize an ui. _guiHandler = new GUIHandler(); _guiHandler.AttachToContext(RC); // Create a new element. GUIElement element = new GUIImage("Assets/image.png", 0, 0, -10, 320, 130); // Add the element to the gui. _guiHandler.Add(element); // Add something to render. _cube = new Cube(); _spcolor = MoreShaders.GetDiffuseColorShader(RC); _colorParam = _spcolor.GetShaderParam("color"); }
public Skybox(RenderContext rc) { // load texture imgData = rc.LoadImage("Assets/skyboxOberflächenfarbe.jpg"); _iTex = rc.CreateTexture(imgData); _rc = rc; _syboxMesh = MeshReader.LoadMesh(@"Assets/skybox.obj.model"); }
public override void Init() { Input.Instance.InitializeDevices(); _meshTea = MeshReader.LoadMesh(@"Assets/Teapot.obj.model"); _spColor = MoreShaders.GetDiffuseColorShader(RC); _colorParam = _spColor.GetShaderParam("color"); }
public Object(Geometry geo, ShaderMaterial m, int x, int y, int z) { _mesh = geo.ToMesh(); _material = m; _posX = x; _posY = y; _posZ = z; _angX = .0f; _angY = .0f; _angY = .0f; }
// is called on startup public override void Init() { _theColor = new float4(0.5f, 0.8f, 0, 1); RC.ClearColor = new float4(1, 1, 1, 1); // initialize the variables _meshTea = MeshReader.LoadMesh(@"Assets/Teapot.obj.model"); _meshFace = MeshReader.LoadMesh(@"Assets/Face.obj.model"); _spColor = MoreShaders.GetShader("simple", RC); _spTexture = MoreShaders.GetShader("texture", RC); _colorParam = _spColor.GetShaderParam("vColor"); _textureParam = _spTexture.GetShaderParam("texture1"); // load texture var imgData = RC.LoadImage("Assets/world_map.jpg"); _iTex = RC.CreateTexture(imgData); }
// is called on startup public override void Init() { RC.ClearColor = new float4(1, 1, 1, 1); skypox = LoadSkybox(); var img = RC.LoadImage("Assets/skyboxOberflächenfarbe.jpg"); _iTex = RC.CreateTexture(img); // initialize the variables _meshTea = MeshReader.LoadMesh(@"Assets/Teapot.obj.model"); // _meshFace = MeshReader.LoadMesh(@"Assets/coords.obj.model"); ; _meshFace = new Cube(); _spColor = MoreShaders.GetDiffuseColorShader(RC); _spTexture = MoreShaders.GetTextureShader(RC); _colorParam = _spColor.GetShaderParam("color"); _textureParam = _spTexture.GetShaderParam("texture1"); // load texture //var imgData = RC.LoadImage("Assets/coords.jpg"); //_iTex = RC.CreateTexture(imgData); _zz = 0.0f; }
// constructor public RollingCube(Level curLevel) { _curLevel = curLevel; _cubeMesh = _curLevel.GlobalCubeMesh; _cubeMoveSound = Audio.Instance.LoadFile("Assets/cube.ogg"); _cubeMoveSound.Volume = 5; _cubeColor = new float3(1, 0.1f, 0.1f); PosCurXY = new int[2]; PosLastXY = new int[2]; _rotateYX = new float[2]; _curDirXY = new int[2]; _orientQuat = Quaternion.Identity; _posZ = 2; _veloZ = 0.0f; _curBright = 0.0f; ResetCube(0, 0); }
public GameEntity(String meshPath, RenderContext rc, float posX = 0, float posY = 0, float posZ = 0, float angX = 0, float angY = 0, float angZ = 0) { if (meshPath.Contains("protobuf")) { _ser = new FuseeSerializer(); using (var file = File.OpenRead(meshPath)) { _mesh = _ser.Deserialize(file, null, typeof(Mesh)) as Mesh; } } else { _mesh = MeshReader.LoadMesh(meshPath); } _rc = rc; Position = float4x4.CreateRotationX(angX) * float4x4.CreateRotationY(angY) * float4x4.CreateRotationZ(angZ) * float4x4.CreateTranslation(posX, posY, posZ); SetShader(_color); }
// is called on startup public override void Init() { // ColorUint constructor test ColorUint ui1 = new ColorUint((uint) 4711); ColorUint ui2 = new ColorUint((byte)42, (byte)43, (byte)44, (byte)45); ColorUint u3 = new ColorUint((float)1, (float)43, (float)44, (float)45); RC.ClearColor = new float4(1f, 1f, 1f, 1); // initialize the variables _meshTea = MeshReader.LoadMesh(@"Assets/Teapot.obj.model"); _shaderEffect.AttachToContext(RC); _spColor = MoreShaders.GetDiffuseColorShader(RC); _colorParam = _spColor.GetShaderParam("vColor"); /* RC.SetRenderState(RenderState.ZEnable, (uint) 1); RC.SetRenderState(RenderState.AlphaBlendEnable, (uint) 1); RC.SetRenderState(RenderState.BlendFactor, (uint)new ColorUint(0.25f, 0.25f, 0.25f, 0.25f)); RC.SetRenderState(RenderState.BlendOperation, (uint)(BlendOperation.Add)); RC.SetRenderState(RenderState.SourceBlend, (uint)(Blend.BlendFactor)); RC.SetRenderState(RenderState.DestinationBlend, (uint)(Blend.InverseBlendFactor)); */ RC.SetRenderState(new RenderStateSet { AlphaBlendEnable = true, BlendFactor = new float4(0.5f, 0.5f, 0.5f, 0.5f), BlendOperation = BlendOperation.Add, SourceBlend = Blend.BlendFactor, DestinationBlend = Blend.InverseBlendFactor }); RC.SetRenderState(RenderState.AlphaBlendEnable, (uint)0); }
/// <summary> /// Converts the whole geomentry to a <see cref="Mesh"/>. /// </summary> /// <returns>An equivalent instance of <see cref="Mesh"/>.</returns> public Mesh ToMesh() { // TODO: make a big case decision based on HasTexCoords and HasNormals around the implementation and implement each case individually Dictionary<TripleInx, int> _vDict = new Dictionary<TripleInx, int>(); List<ushort> mTris = new List<ushort>(); List<float3> mVerts = new List<float3>(); List<float2> mTexCoords = (HasTexCoords) ? new List<float2>() : null; List<float3> mNormals = (HasNormals) ? new List<float3>() : null; foreach (Face f in _faces) { int[] mFace = new int[f.InxVert.Length]; for (int i = 0; i < f.InxVert.Length; i++) { TripleInx ti = new TripleInx() { iV = f.InxVert[i], iT = (HasTexCoords) ? f.InxTexCoord[i] : 0, iN = (HasNormals) ? f.InxNormal[i] : 0 }; int inx; if (!_vDict.TryGetValue(ti, out inx)) { // Create a new vertex triplet combination int vInx = f.InxVert[i]; mVerts.Add(new float3((float) _vertices[vInx].x, (float) _vertices[vInx].y, (float) _vertices[vInx].z)); if (HasTexCoords) { int tInx = f.InxTexCoord[i]; mTexCoords.Add(new float2((float) _texCoords[tInx].x, (float) _texCoords[tInx].y)); } if (HasNormals) { int nInx = f.InxNormal[i]; mNormals.Add(new float3((float) _normals[nInx].x, (float) _normals[nInx].y, (float) _normals[nInx].z)); } inx = mVerts.Count - 1; _vDict.Add(ti, inx); } mFace[i] = inx; } mTris.AddRange(Triangulate(f, mFace)); } Mesh m = new Mesh(); m.Vertices = mVerts.ToArray(); if (HasNormals) m.Normals = mNormals.ToArray(); if (HasTexCoords) m.UVs = mTexCoords.ToArray(); m.Triangles = mTris.ToArray(); return m; }
private void LoadMeshWithProtobuf() { RC.Clear(ClearFlags.Color | ClearFlags.Depth); _isCurrentlyLoading = true; _currentMesh = null; Debug.WriteLine("Started loading Mesh using Protobuf."); RC.Clear(ClearFlags.Color | ClearFlags.Depth); _watch.Start(); using (var file = File.OpenRead(@"Assets/Teapot.protobuf.model")) { _currentMesh = _ser.Deserialize(file, null, typeof(Mesh)) as Mesh; } _watch.Stop(); Debug.WriteLine("Mesh loaded using protobuf in " + _watch.ElapsedMilliseconds + "ms"); _watch.Reset(); _isCurrentlyLoading = false; }
private void LoadMeshWithObjParser() { RC.Clear(ClearFlags.Color | ClearFlags.Depth); _isCurrentlyLoading = true; _currentMesh = null; Debug.WriteLine("Started loading Mesh using MeshReader."); RC.Clear(ClearFlags.Color | ClearFlags.Depth); _watch.Start(); _currentMesh = MeshReader.LoadMesh(@"Assets/Teapot.obj.model"); _watch.Stop(); Debug.WriteLine("Mesh loaded using MeshReader in " + _watch.ElapsedMilliseconds + "ms"); _watch.Reset(); _isCurrentlyLoading = false; }
// is called on startup public override void Init() { InitShader(); RC.ClearColor = new float4(1f, 1f, 1f, 0.0f); _meshTea = MeshReader.LoadMesh(@"Assets/handhipolynorm.obj.model"); }
public void InitColliders() { MyBoxCollider = _world.AddBoxShape(2); MySphereCollider = _world.AddSphereShape(2); MyCylinderCollider = _world.AddCylinderShape(new float3(2, 4, 2)); BoxMesh = MeshReader.LoadMesh(@"Assets/Cube.obj.model"); TeaPotMesh = MeshReader.LoadMesh(@"Assets/Teapot.obj.model"); PlatonicMesh = MeshReader.LoadMesh(@"Assets/Platonic.obj.model"); float3[] verts = PlatonicMesh.Vertices; MyConvHull = _world.AddConvexHullShape(verts, true); float3[] vertsTeaPot = TeaPotMesh.Vertices; TeaPotHull = _world.AddConvexHullShape(vertsTeaPot, true); TeaPotHull.LocalScaling = new float3(0.05f, 0.05f,0.05f); }
/// <summary> /// This method is used for a demo rotation on the models. It uses an interval to rotate in one direction. /// </summary> /// <param name="intervall">A interval in seconds. e.g. 3.0f for 3 sec.</param> /// <param name="rSpeed">The rotation speed. Typically 1.0f</param> private void DemoRotation(float interval, float rSpeed) { if (_demotimeDone < interval) { float deltaTime = (float)Time.Instance.DeltaTime; if (demoRaxis == 0) Transformations.RotateX(rSpeed * deltaTime, ref _Geo); if (demoRaxis == 1) Transformations.RotateY(rSpeed * deltaTime, ref _Geo); if (demoRaxis == 2) Transformations.RotateZ(rSpeed * deltaTime, ref _Geo); _Geo._Changes = true; _lfgmesh = _Geo.ToMesh(); _Geo._Changes = false; _demotimeDone += deltaTime; } else { _demotimeDone = 0; if (demoRaxis < 2) { demoRaxis++; } else { demoRaxis = 0; } } }
public override void Init() { // is called on startup RC.ClearColor = new float4(1, 1, 1, 1); // initialize the variables _meshTea = MeshReader.LoadMesh(@"Assets/Teapot.obj.model"); _meshCube = MeshReader.LoadMesh(@"Assets/Cube.obj.model"); _meshSphere = MeshReader.LoadMesh(@"Assets/Sphere.obj.model"); _meshCylinder = MeshReader.LoadMesh(@"Assets/Cylinder.obj.model"); _meshPlatinic = MeshReader.LoadMesh(@"Assets/Platonic.obj.model"); //RC.CreateShader(Vs, Ps); _spColor = RC.CreateShader(Vs, Ps); //MoreShaders.GetShader("simple", RC); _spTexture = RC.CreateShader(Vt, Pt);//MoreShaders.GetShader("texture", RC); _spCustom = RC.CreateShader(VLin, PLin); _colorParam = _spColor.GetShaderParam("vColor"); _colorCustom = _spCustom.GetShaderParam("vColor"); _textureParam = _spTexture.GetShaderParam("vTexture"); // load texture var imgData = RC.LoadImage("Assets/world_map.jpg"); _iTex = RC.CreateTexture(imgData); _physic = new Physics(); _gui= new GUI(RC); _gui.SetUp(_physic.GetNumRB(), _physic.GetShapes()); }
/// <summary> /// Initializes a new instance of the <see cref="Renderer"/> class. /// </summary> /// <param name="geo">The geo.</param> /// <param name="shaderProgram">The shader program.</param> public Renderer(Geometry geo, ShaderProgram shaderProgram) { mesh = geo.ToMesh(); material = new Material(shaderProgram); }
public override void Init() { VSync = false; // Start the application in demo mode? demoMode = true; #region MeshImports _Geo = new Geometry(); //_Geo.LoadAsset("Assets/Cube.obj.model"); //_Geo.LoadAsset("Assets/Cube_quads.obj.model"); //_Geo.LoadAsset("Assets/Sphere.obj.model"); //_Geo.LoadAsset("Assets/Sphere_quads.obj.model"); //_Geo.LoadAsset("Assets/SharedCorners.obj.model"); //_Geo.LoadAsset("Assets/Cylinder.obj.model"); //_Geo.LoadAsset("Assets/Cylinder_quads.obj.model"); //_Geo.LoadAsset("Assets/SharedCorners_pro.obj.model"); _Geo.LoadAsset("Assets/Teapot.obj.model"); // Due to copyright reasons, this file will not be delivered with the project. //_Geo.LoadAsset("Assets/Hellknight.obj.model"); #endregion MeshImports // Set the smoothing angle for the edge based vertex normal calculation // Feel free to test around. _Geo._SmoothingAngle = 89.0; // The shader colors here are not supposed to be changed. They don't have an effect. If you want to change the shaders // then please change the values in the ShaderChanger() method. These ones are just for declaration. #region Shaders #region TextureShader _msDiffuse = MoreShaders.GetDiffuseTextureShader(RC); _vLightShaderParam = _msDiffuse.GetShaderParam("texture1"); //ImageData imgData = RC.LoadImage("Assets/Cube_Mat_uv.jpg"); ImageData imgData = RC.LoadImage("Assets/world_map.jpg"); //ImageData imgData = RC.LoadImage("Assets/Teapot_Texture.jpg"); // Due to copyright reasons, this file will not be delivered with the project. //ImageData imgData = RC.LoadImage("Assets/Hellknight.jpg"); _tex = RC.CreateTexture(imgData); #endregion TextureShader #region ColorShader _spColor = MoreShaders.GetDiffuseColorShader(RC); _colorParam = _spColor.GetShaderParam("color"); RC.SetShader(_spColor); RC.SetShaderParam(_colorParam, new float4(0f, 0f, 0f, 1)); #endregion ColorShader #region LightPos RC.SetLightActive(0, 0f); RC.SetLightAmbient(0, new float4(0.0f, 0.0f, 0.0f, 1.0f)); RC.SetLightDiffuse(0, new float4(1.0f, 1.0f, 1.0f, 1.0f)); RC.SetLightDirection(0, new float3(0.0f, -1.0f, 0.0f)); RC.SetLightActive(1, 0f); RC.SetLightAmbient(1, new float4(0.0f, 0.0f, 0.0f, 1.0f)); RC.SetLightDiffuse(1, new float4(0.5f, 0.5f, 0.5f, 1.0f)); RC.SetLightDirection(1, new float3(1.0f, 0.0f, 0.0f)); #endregion LightPos #endregion // Convert the loaded lfg model to a fusee mesh the first time. _lfgmesh = _Geo.ToMesh(); RC.ClearColor = new float4(0.2f, 0.2f, 0.2f, 1f); // TODO: For Benchmarking only. _ShaderType = 1; runDemoAnimation = true; _Geo._DoCalcVertexNormals = true; }
/// <summary> /// Initializes a new instance of the <see cref="Renderer"/> class. /// </summary> /// <param name="mesh">The Mesh of this Renderer.</param> /// <param name="sp">The Shaderprogram is used to initialize the Material of the Renderer.</param> public Renderer(Mesh mesh, ShaderProgram sp) { this.mesh = mesh; material = new Material(sp); }
/// <summary> /// Initializes a new instance of the <see cref="Renderer"/> class. /// </summary> /// <param name="mesh">The mesh of this Renderer.</param> public Renderer(Mesh mesh) { this.mesh = mesh; }
/// <summary> /// Initializes a new instance of the <see cref="Renderer"/> class. /// </summary> /// <param name="geo">The geometry information is parsed to a Mesh<see cref="Mesh"/> object upon initilization of Renderer.</param> public Renderer(Geometry geo) { mesh = geo.ToMesh(); }
/// <summary> /// This method converts the data structure to a fusee readable mesh structure /// </summary> /// <param name="shouldUseTriangulation">Boolean. True if the mesh should be triangulated.</param> /// <returns>A fusee readable Mesh object</returns> public Mesh ToMesh(bool shouldUseTriangulation = true) { if (shouldUseTriangulation && !_UsesTriangles) { TriangulateGeometry(); _UsesTriangles = true; } _LfaceNormals.Clear(); foreach (HandleFace faceHandle in _LfaceHndl) { CalcFaceNormal(faceHandle); } if (_VertexNormalActive) { if (System.Diagnostics.Debugger.IsAttached) { _NormalCalcStopWatch.Reset(); _NormalCalcStopWatch.Start(); } _LVertexNormals.Clear(); _LverticeHndl.ForEach(CalcVertexNormal); if (System.Diagnostics.Debugger.IsAttached) { _NormalCalcStopWatch.Stop(); Debug.WriteLine("Time taken to compute vertex normals: " + _NormalCalcStopWatch.ElapsedMilliseconds + " ms"); } } _LtrianglesFuseeMesh.Clear(); _LvertDataFuseeMesh.Clear(); _LvertNormalsFuseeMesh.Clear(); _LvertuvFuseeMesh.Clear(); foreach (HandleFace faceHandle in _LfaceHndl) { foreach (HEdgePtrCont currentContainer in EnFaceAdjacentHalfEdges(faceHandle).Select(handleHalfEdge => _LhedgePtrCont[handleHalfEdge])) { _LvertDataFuseeMesh.Add(_LvertexVal[currentContainer._v]); if (_VertexNormalActive || _LVertexNormals != null) { if (currentContainer._vn.isValid) _LvertNormalsFuseeMesh.Add(_LVertexNormals[currentContainer._vn]); } if (_LuvCoordinates.Count > 0) { _LvertuvFuseeMesh.Add(_LuvCoordinates[currentContainer._vuv]); } _LtrianglesFuseeMesh.Add((short)(_LvertDataFuseeMesh.Count - 1)); } } Mesh fuseeMesh = new Mesh(); fuseeMesh.Vertices = _LvertDataFuseeMesh.ToArray(); if (_VertexNormalActive || _LvertNormalsFuseeMesh != null) fuseeMesh.Normals = _LvertNormalsFuseeMesh.ToArray(); fuseeMesh.UVs = _LvertuvFuseeMesh.ToArray(); fuseeMesh.Triangles = _LtrianglesFuseeMesh.ToArray(); return fuseeMesh; }
public override void Init() { // Set ToonShaderEffect _shaderEffect.AttachToContext(RC); // Setup GUI // GUIHandler _guiHandler = new GUIHandler(); _guiHandler.AttachToContext(RC); // font + text _guiFontCabin18 = RC.LoadFont("Assets/Cabin.ttf", 18); _guiFontCabin24 = RC.LoadFont("Assets/Cabin.ttf", 24); _guiText = new GUIText("FUSEE Shader Demo", _guiFontCabin24, 30, Height - 30) { TextColor = new float4(1, 1, 1, 1) }; _guiHandler.Add(_guiText); // image _guiImage = new GUIImage("Assets/repbg.jpg", 0, 0, -5, Width, Height); _guiHandler.Add(_guiImage); _borderImage = new GUIImage("Assets/redbg.png", 0, 0, -4, 230, 32); //_guiHandler.Add(_borderImage); //* Menu1: Select Shader _panelSelectShader = new GUIPanel("Select Shader", _guiFontCabin24, 10, 10, 230, 230); _panelSelectShader.ChildElements.Add(_borderImage); _guiHandler.Add(_panelSelectShader); //** Possible Shader Buttons _btnDiffuseColorShader = new GUIButton("Diffuse Color", _guiFontCabin18, 25, 40, 180, 25); _btnTextureShader = new GUIButton("Texture Only", _guiFontCabin18, 25, 70, 180, 25); _btnDiffuseTextureShader = new GUIButton("Diffuse Texture", _guiFontCabin18, 25, 100, 180, 25); _btnDiffuseBumpTextureShader = new GUIButton("Diffuse Bump Texture", _guiFontCabin18, 25, 130, 180, 25); _btnSpecularTexture = new GUIButton("Specular Texture", _guiFontCabin18, 25, 160, 180, 25); _btnToon = new GUIButton("Toon", _guiFontCabin18, 25, 190, 180, 25); //*** Add Handlers _btnDiffuseColorShader.OnGUIButtonDown += OnMenuButtonDown; _btnDiffuseColorShader.OnGUIButtonUp += OnMenuButtonUp; _btnDiffuseColorShader.OnGUIButtonEnter += OnMenuButtonEnter; _btnDiffuseColorShader.OnGUIButtonLeave += OnMenuButtonLeave; _btnTextureShader.OnGUIButtonDown += OnMenuButtonDown; _btnTextureShader.OnGUIButtonUp += OnMenuButtonUp; _btnTextureShader.OnGUIButtonEnter += OnMenuButtonEnter; _btnTextureShader.OnGUIButtonLeave += OnMenuButtonLeave; _btnDiffuseTextureShader.OnGUIButtonDown += OnMenuButtonDown; _btnDiffuseTextureShader.OnGUIButtonUp += OnMenuButtonUp; _btnDiffuseTextureShader.OnGUIButtonEnter += OnMenuButtonEnter; _btnDiffuseTextureShader.OnGUIButtonLeave += OnMenuButtonLeave; _btnDiffuseBumpTextureShader.OnGUIButtonDown += OnMenuButtonDown; _btnDiffuseBumpTextureShader.OnGUIButtonUp += OnMenuButtonUp; _btnDiffuseBumpTextureShader.OnGUIButtonEnter += OnMenuButtonEnter; _btnDiffuseBumpTextureShader.OnGUIButtonLeave += OnMenuButtonLeave; _btnSpecularTexture.OnGUIButtonDown += OnMenuButtonDown; _btnSpecularTexture.OnGUIButtonUp += OnMenuButtonUp; _btnSpecularTexture.OnGUIButtonEnter += OnMenuButtonEnter; _btnSpecularTexture.OnGUIButtonLeave += OnMenuButtonLeave; _btnToon.OnGUIButtonDown += OnMenuButtonDown; _btnToon.OnGUIButtonUp += OnMenuButtonUp; _btnToon.OnGUIButtonEnter += OnMenuButtonEnter; _btnToon.OnGUIButtonLeave += OnMenuButtonLeave; //**** Add Buttons to Panel _panelSelectShader.ChildElements.Add(_btnDiffuseColorShader); _panelSelectShader.ChildElements.Add(_btnTextureShader); _panelSelectShader.ChildElements.Add(_btnDiffuseTextureShader); _panelSelectShader.ChildElements.Add(_btnDiffuseBumpTextureShader); _panelSelectShader.ChildElements.Add(_btnSpecularTexture); _panelSelectShader.ChildElements.Add(_btnToon); //* Menu3: Select Mesh _panelSelectMesh = new GUIPanel("Select Mesh", _guiFontCabin24, 270, 10, 230, 130); _panelSelectMesh.ChildElements.Add(_borderImage); _guiHandler.Add(_panelSelectMesh); //** Possible Meshes _btnCube = new GUIButton("Cube", _guiFontCabin18, 25, 40, 180, 25); _btnSphere = new GUIButton("Sphere", _guiFontCabin18, 25, 70, 180, 25); _btnTeapot = new GUIButton("Teapot", _guiFontCabin18, 25, 100, 180, 25); _panelSelectMesh.ChildElements.Add(_btnCube); _panelSelectMesh.ChildElements.Add(_btnSphere); _panelSelectMesh.ChildElements.Add(_btnTeapot); //** Add handlers _btnCube.OnGUIButtonDown += OnMenuButtonDown; _btnCube.OnGUIButtonUp += OnMenuButtonUp; _btnCube.OnGUIButtonEnter += OnMenuButtonEnter; _btnCube.OnGUIButtonLeave += OnMenuButtonLeave; _btnSphere.OnGUIButtonDown += OnMenuButtonDown; _btnSphere.OnGUIButtonUp += OnMenuButtonUp; _btnSphere.OnGUIButtonEnter += OnMenuButtonEnter; _btnSphere.OnGUIButtonLeave += OnMenuButtonLeave; _btnTeapot.OnGUIButtonDown += OnMenuButtonDown; _btnTeapot.OnGUIButtonUp += OnMenuButtonUp; _btnTeapot.OnGUIButtonEnter += OnMenuButtonEnter; _btnTeapot.OnGUIButtonLeave += OnMenuButtonLeave; //* Menu2: Light Settings _panelLightSettings = new GUIPanel("Light Settings", _guiFontCabin24, 530, 10, 230, 130); _panelLightSettings.ChildElements.Add(_borderImage); _guiHandler.Add(_panelLightSettings); //** Possible Light Settings _btnDirectionalLight = new GUIButton("Directional Light", _guiFontCabin18, 25, 40, 180, 25); _btnPointLight = new GUIButton("Point Light", _guiFontCabin18, 25, 70, 180, 25); _btnSpotLight = new GUIButton("Spot Light", _guiFontCabin18, 25, 100, 180, 25); _panelLightSettings.ChildElements.Add(_btnDirectionalLight); _panelLightSettings.ChildElements.Add(_btnPointLight); _panelLightSettings.ChildElements.Add(_btnSpotLight); //*** Add Handlers _btnDirectionalLight.OnGUIButtonDown += OnMenuButtonDown; _btnDirectionalLight.OnGUIButtonUp += OnMenuButtonUp; _btnDirectionalLight.OnGUIButtonEnter += OnMenuButtonEnter; _btnDirectionalLight.OnGUIButtonLeave += OnMenuButtonLeave; _btnPointLight.OnGUIButtonDown += OnMenuButtonDown; _btnPointLight.OnGUIButtonUp += OnMenuButtonUp; _btnPointLight.OnGUIButtonEnter += OnMenuButtonEnter; _btnPointLight.OnGUIButtonLeave += OnMenuButtonLeave; _btnSpotLight.OnGUIButtonDown += OnMenuButtonDown; _btnSpotLight.OnGUIButtonUp += OnMenuButtonUp; _btnSpotLight.OnGUIButtonEnter += OnMenuButtonEnter; _btnSpotLight.OnGUIButtonLeave += OnMenuButtonLeave; // Setup 3D Scene // Load Images and Assign iTextures var imgTexture = RC.LoadImage("Assets/crateTexture.jpg"); var imgBumpTexture = RC.LoadImage("Assets/crateNormal.jpg"); _texCube = RC.CreateTexture(imgTexture); _texBumpCube = RC.CreateTexture(imgBumpTexture); imgTexture = RC.LoadImage("Assets/earthTexture.jpg"); imgBumpTexture = RC.LoadImage("Assets/earthNormal.jpg"); _texSphere = RC.CreateTexture(imgTexture); _texBumpSphere = RC.CreateTexture(imgBumpTexture); imgTexture = RC.LoadImage("Assets/porcelainTexture.png"); imgBumpTexture = RC.LoadImage("Assets/normalRust.jpg"); _texTeapot = RC.CreateTexture(imgTexture); _texBumpTeapot = RC.CreateTexture(imgBumpTexture); _currentTexture = _texCube; _currentBumpTexture = _texBumpCube; // Load Meshes _meshCube = MeshReader.LoadMesh(@"Assets/Cube.obj.model"); _meshSphere = MeshReader.LoadMesh(@"Assets/Sphere.obj.model"); _meshTeapot = MeshReader.LoadMesh(@"Assets/Teapot.obj.model"); // Set current Mesh and Update GUI _currentMesh = _meshCube; _btnCube.ButtonColor = ColorHighlightedButton; // Setup Shaderprograms and Update GUI _shaderDiffuseColor = MoreShaders.GetDiffuseColorShader(RC); _shaderDiffuseTexture = MoreShaders.GetDiffuseTextureShader(RC); _shaderTexture = MoreShaders.GetSkyboxShader(RC); _shaderDiffuseBumpTexture = MoreShaders.GetBumpDiffuseShader(RC); _shaderSpecularTexture = MoreShaders.GetSpecularShader(RC); _btnDiffuseColorShader.ButtonColor = ColorHighlightedButton; _currentShader = _shaderDiffuseColor; RC.SetShader(_shaderDiffuseColor); // Setup ShaderParams _paramColor = _shaderDiffuseColor.GetShaderParam("color"); // Setup Light and Update GUI RC.SetLightActive(0, 1); RC.SetLightPosition(0, new float3(5.0f, 0.0f, -2.0f)); RC.SetLightAmbient(0, new float4(0.2f, 0.2f, 0.2f, 1.0f)); RC.SetLightSpecular(0, new float4(0.1f, 0.1f, 0.1f, 1.0f)); RC.SetLightDiffuse(0, new float4(0.8f, 0.8f, 0.8f, 1.0f)); RC.SetLightDirection(0, new float3(-1.0f, 0.0f, 0.0f)); RC.SetLightSpotAngle(0, 10); _btnDirectionalLight.ButtonColor = ColorHighlightedButton; }
// Pull the users input public void PullUserInput() { #region Mouse if (Input.Instance.IsButton(MouseButtons.Left)) { _angleVelHorz = RotationSpeed * Input.Instance.GetAxis(InputAxis.MouseX); _angleVelVert = RotationSpeed * Input.Instance.GetAxis(InputAxis.MouseY); if (Transformations.RotateY(_angleVelHorz * _InvertMouseAxis, ref _Geo)) { if (Transformations.RotateX(_angleVelVert * _InvertMouseAxis, ref _Geo)) { _Geo._Changes = true; } } } // Scale the model up with the middle mouse button if (Input.Instance.IsButton(MouseButtons.Middle)) { if (Transformations.Scale(1.1f, 1.1f, 1.1f, ref _Geo)) { _Geo._Changes = true; } } // Reset the model with the right mouse button if (Input.Instance.IsButton(MouseButtons.Right)) { if (_Geo.ResetGeometryToDefault()) { _Geo._Changes = true; } } #endregion Mouse #region Scaling if (Input.Instance.IsKey(KeyCodes.Q)) { if (Transformations.Scale(1.1f, 1.1f, 1.1f, ref _Geo)) { _Geo._Changes = true; } } else if (Input.Instance.IsKey(KeyCodes.A)) { if (Transformations.Scale(0.9f, 0.9f, 0.9f, ref _Geo)) { _Geo._Changes = true; } } // Scale only x direction if (Input.Instance.IsKey(KeyCodes.W)) { if (Transformations.Scale(1.1f, 1.0f, 1.0f, ref _Geo)) { _Geo._Changes = true; } } else if (Input.Instance.IsKey(KeyCodes.S)) { if (Transformations.Scale(0.9f, 1.0f, 1.0f, ref _Geo)) { _Geo._Changes = true; } } // Scale only y direction if (Input.Instance.IsKey(KeyCodes.E)) { if (Transformations.Scale(1.0f, 1.1f, 1.0f, ref _Geo)) { _Geo._Changes = true; } } else if (Input.Instance.IsKey(KeyCodes.D)) { if (Transformations.Scale(1.0f, 0.9f, 1.0f, ref _Geo)) { _Geo._Changes = true; } } // Scale only z direction if (Input.Instance.IsKey(KeyCodes.R)) { if (Transformations.Scale(1.0f, 1.0f, 1.1f, ref _Geo)) { _Geo._Changes = true; } } else if (Input.Instance.IsKey(KeyCodes.F)) { if (Transformations.Scale(1.0f, 1.0f, 0.9f, ref _Geo)) { _Geo._Changes = true; } } #endregion Scaling #region Translation if (Input.Instance.IsKey(KeyCodes.U)) { if (Transformations.Translate(0f, (_MovementSpeed * (float)Time.Instance.DeltaTime) * 20, 0f, ref _Geo)) { _Geo._Changes = true; } } else if (Input.Instance.IsKey(KeyCodes.J)) { if (Transformations.Translate(0f, (-_MovementSpeed * (float)Time.Instance.DeltaTime) * 20, 0f, ref _Geo)) { _Geo._Changes = true; } } if (Input.Instance.IsKey(KeyCodes.H)) { if (Transformations.Translate(-(_MovementSpeed * (float)Time.Instance.DeltaTime) * 20, 0f, 0f, ref _Geo)) { _Geo._Changes = true; } } else if (Input.Instance.IsKey(KeyCodes.K)) { if (Transformations.Translate((_MovementSpeed * (float)Time.Instance.DeltaTime) * 20, 0f, 0f, ref _Geo)) { _Geo._Changes = true; } } if (Input.Instance.IsKey(KeyCodes.Z)) { if (Transformations.Translate(0f, 0f, -(_MovementSpeed * (float)Time.Instance.DeltaTime) * 20, ref _Geo)) { _Geo._Changes = true; } } else if (Input.Instance.IsKey(KeyCodes.I)) { if (Transformations.Translate(0f, 0f, (_MovementSpeed * (float)Time.Instance.DeltaTime) * 20, ref _Geo)) { _Geo._Changes = true; } } #endregion Translation #region Rotation if (Input.Instance.IsKey(KeyCodes.Up)) { if (Transformations.RotateX(1f * (float)Time.Instance.DeltaTime, ref _Geo)) { _Geo._Changes = true; } } else if (Input.Instance.IsKey(KeyCodes.Down)) { if (Transformations.RotateX(-1f * (float)Time.Instance.DeltaTime, ref _Geo)) { _Geo._Changes = true; } } if (Input.Instance.IsKey(KeyCodes.Left)) { if (Transformations.RotateY(1f * (float)Time.Instance.DeltaTime, ref _Geo)) { _Geo._Changes = true; } } else if (Input.Instance.IsKey(KeyCodes.Right)) { if (Transformations.RotateY(-1f * (float)Time.Instance.DeltaTime, ref _Geo)) { _Geo._Changes = true; } } if (Input.Instance.IsKey(KeyCodes.O)) { if (Transformations.RotateZ(1f * (float)Time.Instance.DeltaTime, ref _Geo)) { _Geo._Changes = true; } } else if (Input.Instance.IsKey(KeyCodes.P)) { if (Transformations.RotateZ(-1f * (float)Time.Instance.DeltaTime, ref _Geo)) { _Geo._Changes = true; } } #endregion Rotation #region ActivateVertexNormals if (Input.Instance.IsKeyDown(KeyCodes.N)) { _Geo._DoCalcVertexNormals = true; } if (Input.Instance.IsKeyDown(KeyCodes.M)) { _Geo._DoCalcVertexNormals = false; } #endregion ActivateVertexNormals if (Input.Instance.IsKeyDown(KeyCodes.T)) { if (_Geo.ResetGeometryToDefault()) { _Geo._Changes = true; } } if (_Geo._Changes) { _lfgmesh = _Geo.ToMesh(); _Geo._Changes = false; } #region Shader Render Settings and demo if (Input.Instance.IsKeyDown(KeyCodes.F1) && Input.Instance.IsKey(KeyCodes.LControl)) { _ShaderChange = true; _ShaderType = 0; } else if (Input.Instance.IsKeyDown(KeyCodes.F2) && Input.Instance.IsKey(KeyCodes.LControl)) { _ShaderChange = true; _ShaderType = 1; } else if (Input.Instance.IsKeyDown(KeyCodes.F3) && Input.Instance.IsKey(KeyCodes.LControl)) { runDemoAnimation = !runDemoAnimation; } #endregion float4x4 mtxCam = float4x4.LookAt(0, 500, 500, 0, 0, 0, 0, 1, 0); RC.ModelView = float4x4.CreateTranslation(0, 0, 0) * mtxCam; }
/// <summary> /// Initializes a new instance of the <see cref="RenderMesh"/> class. Needs to be provided with a mesh that needs to be rendered. /// </summary> /// <param name="mesh">The mesh that need's to be rendered e.g. the mesh of a ingame object.</param> public RenderMesh(Mesh mesh) { _mesh = mesh; }
public GImpactMeshShape AddGImpactMeshShape(Mesh mesh) { int[] meshTrianglesArray = new int[mesh.Triangles.Length]; for (int c = 0; c < mesh.Triangles.Length; c++) { meshTrianglesArray[c] = Convert.ToInt32(mesh.Triangles[c]); } int meshVerteciesCount = mesh.Vertices.Length; float3[] meshVerteciesArray = new float3[meshVerteciesCount]; meshVerteciesArray = mesh.Vertices; IGImpactMeshShapeImp iGImpactMeshShapeImp = _dwi.AddGImpactMeshShape(meshTrianglesArray, mesh.Vertices); var retval = new GImpactMeshShape(); retval.GImpactMeshShapeImp = iGImpactMeshShapeImp; iGImpactMeshShapeImp.UserObject = retval; return retval; }
public override void Init() { RC.ClearColor = new float4(0.5f, 0.5f, 0.5f, 1); // load meshes Body = MeshReader.LoadMesh(@"Assets/mageBodyOBJ.obj.model"); GloveL = MeshReader.LoadMesh(@"Assets/mageGloveLOBJ.obj.model"); GloveR = MeshReader.LoadMesh(@"Assets/mageGloveROBJ.obj.model"); // set up shader, lights and textures var spBody = RC.CreateShader(VsBump, PsBump); RC.SetShader(spBody); RC.SetLightActive(0, 1); RC.SetLightPosition(0, new float3(5.0f, 0.0f, 2.0f)); RC.SetLightAmbient(0, new float4(0.2f, 0.2f, 0.2f, 1.0f)); RC.SetLightSpecular(0, new float4(0.1f, 0.1f, 0.1f, 1.0f)); RC.SetLightDiffuse(0, new float4(0.8f, 0.8f, 0.8f, 1.0f)); RC.SetLightDirection(0, new float3(-1.0f, 0.0f, 0.0f)); RC.SetLightActive(1, 1); RC.SetLightPosition(1, new float3(-5.0f, 0.0f, 2.0f)); RC.SetLightAmbient(1, new float4(0.5f, 0.5f, 0.5f, 1.0f)); RC.SetLightSpecular(1, new float4(0.1f, 0.1f, 0.1f, 1.0f)); RC.SetLightDiffuse(1, new float4(1.0f, 1.0f, 1.0f, 1.0f)); RC.SetLightDirection(1, new float3(1.0f, 0.0f, 0.0f)); _texture1ParamBody = spBody.GetShaderParam("texture1"); _texture2ParamBody = spBody.GetShaderParam("normalTex"); _specularLevelBody = spBody.GetShaderParam("specularLevel"); var imgDataGlove = RC.LoadImage("Assets/HandAOMap.jpg"); var imgData2Glove = RC.LoadImage("Assets/HandschuhNormalMap.jpg"); _iTexGlove = RC.CreateTexture(imgDataGlove); _iTex2Glove = RC.CreateTexture(imgData2Glove); var imgData = RC.LoadImage("Assets/TextureAtlas.jpg"); var imgData2 = RC.LoadImage("Assets/TextureAtlasNormal.jpg"); _iTex = RC.CreateTexture(imgData); _iTex2 = RC.CreateTexture(imgData2); // misc settings _angleHorz = 0; _angleVert = 0; _rotationSpeed = 1.5f; }
/// <summary> /// Renders geometry on the attached RenderContext using this shader effect. All rendering passes are applied /// to the geometry in the order of appearance within the <see cref="EffectPassDeclaration"/> array provided /// in the constructor. /// </summary> /// <param name="mesh">The mesh to render.</param> public void RenderMesh(Mesh mesh) { int i = 0, nPasses = _vertexShaderSrc.Length; try { for (i = 0; i < nPasses; i++) { // TODO: Use shared uniform paramters - currently SetShader will query the shader params and set all the common uniforms (like matrices and light) _rc.SetShader(_compiledShaders[i]); foreach (var param in _paramsPerPass[i]) { if (param.Info.Type == typeof (int)) { _rc.SetShaderParam(param.Info.Handle, (int) param.Value); } else if (param.Info.Type == typeof (float)) { _rc.SetShaderParam(param.Info.Handle, (float) param.Value); } else if (param.Info.Type == typeof(float2)) { _rc.SetShaderParam(param.Info.Handle, (float2)param.Value); } else if (param.Info.Type == typeof(float3)) { _rc.SetShaderParam(param.Info.Handle, (float3)param.Value); } else if (param.Info.Type == typeof(float4)) { _rc.SetShaderParam(param.Info.Handle, (float4)param.Value); } else if (param.Info.Type == typeof(float4x4)) { _rc.SetShaderParam(param.Info.Handle, (float4x4)param.Value); } else if (param.Info.Type == typeof(ITexture)) { _rc.SetShaderParamTexture(param.Info.Handle, (ITexture) param.Value); } } _rc.SetRenderState(_states[i]); // TODO: split up RenderContext.Render into a preparation and a draw call so that we can prepare a mesh once and draw it for each pass. _rc.Render(mesh); } } catch (Exception ex) { throw new Exception("Error while rendering pass " + i, ex); } }
private void SetMesh(Mesh newmesh) { if (newmesh != null && _currentMesh != newmesh) { _currentMesh = newmesh; } }