private void render() { //fShader._Metallic = (Mathf.sin(time) + 1) / 2; context3D.setCulling(Context3DTriangleFace.BACK); context3D.setDepthTest(true, Context3DCompareMode.LESS); context3D.clear(49 / 255f, 77 / 255f, 121 / 255f); Matrix3D _ObjectToWorld; Matrix3D _WorldToObject; Matrix3D _MatrixV; Matrix3D _matrix_projection; Matrix3D _MatrixVP; Matrix3D _MatrixInvV; Matrix3D m = Matrix3D.Identity; _ObjectToWorld = m; _WorldToObject = m.getInvert(); Vector4 camerpos = new Vector4(0, 0, 0.5f, 1); var camera = Matrix3D.lookAtLH(camerpos.x, camerpos.y, camerpos.z, 0f, 0f, 0, 0, 1, 0); _MatrixV = camera; _MatrixInvV = _MatrixV.getInvert(); var perspective = Matrix3D.perspectiveOffCenterLH(-0.5f, 0.5f, -0.5f, 0.5f, 0.5f, 50f); _matrix_projection = perspective; _MatrixVP = _MatrixV.append(perspective); context3D.setProgramConstants_Matrices(_ObjectToWorld, _WorldToObject, camera, _matrix_projection, _MatrixVP, _MatrixInvV, true); context3D.setProgramVariables(camerpos); context3D.bindVertexBuffer(lst_vertexes[0]); context3D.drawTriangles(lst_indexList[0]); context3D.present(); }
private void render() { Matrix3D _ObjectToWorld; Matrix3D _WorldToObject; Matrix3D _MatrixV; Matrix3D _matrix_projection; Matrix3D _MatrixVP; Matrix3D _MatrixInvV; context3D.bindVertexBuffer(vertexes); context3D.setCulling(Context3DTriangleFace.NONE); context3D.setDepthTest(true, Context3DCompareMode.LESS); Matrix3D mv = new Matrix3D(); mv.identity(); _ObjectToWorld = mv; _WorldToObject = mv.getInvert(); float angle = time * 3.14f / 2; var camera = Matrix3D.lookAtLH(Mathf.sin(angle) * -5f + 0.5f, 2f, Mathf.cos(angle) * -5f + 0.5f, 0.5f, 0.5f, 0, 0, 1, 0); _MatrixV = camera; _MatrixInvV = _MatrixV.getInvert(); var perspective = Matrix3D.perspectiveOffCenterLH(-1, 1, -1.0f * 600 / 800, 1.0f * 600 / 800, 2f, 8f); mv.append(perspective); _matrix_projection = perspective; _MatrixVP = _MatrixV.append(perspective); context3D.setProgramConstants_Matrices(_ObjectToWorld, _WorldToObject, camera, _matrix_projection, _MatrixVP, _MatrixInvV, true); context3D.clear(49 / 255f, 77 / 255f, 121 / 255f); context3D.drawTriangles(indexList); context3D.present(); }
private void render() { //fShader._Metallic = (Mathf.sin(time) + 1) / 2; context3D.setCulling(Context3DTriangleFace.FRONT); context3D.setDepthTest(true, Context3DCompareMode.LESS); Stack <Assimp.Node> nodes = new Stack <Assimp.Node>(); nodes.Push(scene.RootNode); Dictionary <Assimp.Node, Assimp.Matrix4x4> dictNodeM = new Dictionary <Assimp.Node, Assimp.Matrix4x4>(); dictNodeM.Add(scene.RootNode, scene.RootNode.Transform); context3D.clear(49 / 255f, 77 / 255f, 121 / 255f); while (nodes.Count > 0) { var n = nodes.Pop(); for (int i = 0; i < n.ChildCount; i++) { nodes.Push(n.Children[i]); dictNodeM.Add(n.Children[i], dictNodeM[n] * n.Children[i].Transform); } //if (n.Name.IndexOf("LOD") > 0 && !n.Name.EndsWith("3")) //{ //} //else if (n.MeshIndices.Count > 0) { var m = dictNodeM[n]; renderMesh(m, n.MeshIndices); } } context3D.present(); }
private void render() { //fShader._Metallic = (Mathf.sin(time) + 1) / 2; context3D.setCulling(Context3DTriangleFace.BACK); context3D.setDepthTest(true, Context3DCompareMode.LESS); Stack <Assimp.Node> nodes = new Stack <Assimp.Node>(); nodes.Push(scene.RootNode); Dictionary <Assimp.Node, Assimp.Matrix4x4> dictNodeM = new Dictionary <Assimp.Node, Assimp.Matrix4x4>(); dictNodeM.Add(scene.RootNode, scene.RootNode.Transform); context3D.clear(49 / 255f, 77 / 255f, 121 / 255f); for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { var m = Matrix3D.Identity; m.appendScale(0.5f, 0.5f, 0.5f); m.appendTranslation((i - 5) * 0.6f, (j - 5) * 0.6f, 0); fShader.Roughness = 1 - i * 1.0f / 10; fShader._Metallic = 1 - j * 1.0f / 10; renderMesh(m); } } context3D.present(); }
public ApplicationSprite() { // Set the default stage behavior stage.scaleMode = StageScaleMode.NO_SCALE; stage.align = StageAlign.TOP_LEFT; // Request a 3D context instance stage3D = stage.stage3Ds[0]; //stage3D.addEventListener(Event.CONTEXT3D_CREATE, contextReady, false, 0, true); stage3D.context3DCreate += delegate { //stage3D.removeEventListener(Event.CONTEXT3D_CREATE, contextReady); // Get the new context context = stage3D.context3D; //trace("Got context! " + context); // Configure back buffer context.configureBackBuffer(DefaultWidth, DefaultHeight, 2, true); context.setCulling(Context3DTriangleFace.BACK); stage3D.x = stage3D.y = 0; // Prepare vertex data: x,y,z, nx,ny,nz, u,v (position, normal, texture) Vector <double> vertexData = new double[] { 0.5, 0.5, -0.5, 0, 0, -1, 1, 0, // Front -0.5, 0.5, -0.5, 0, 0, -1, 0, 0, // -0.5, -0.5, -0.5, 0, 0, -1, 0, 1, // 0.5, -0.5, -0.5, 0, 0, -1, 1, 1, // 0.5, -0.5, -0.5, 0, -1, 0, 1, 0, // Bottom -0.5, -0.5, -0.5, 0, -1, 0, 0, 0, // -0.5, -0.5, 0.5, 0, -1, 0, 0, 1, // 0.5, -0.5, 0.5, 0, -1, 0, 1, 1, // -0.5, 0.5, 0.5, 0, 0, 1, 1, 0, // Back 0.5, 0.5, 0.5, 0, 0, 1, 0, 0, // 0.5, -0.5, 0.5, 0, 0, 1, 0, 1, // -0.5, -0.5, 0.5, 0, 0, 1, 1, 1, // -0.5, 0.5, 0.5, 0, 1, 0, 1, 0, // Top 0.5, 0.5, 0.5, 0, 1, 0, 0, 0, // 0.5, 0.5, -0.5, 0, 1, 0, 0, 1, // -0.5, 0.5, -0.5, 0, 1, 0, 1, 1, // -0.5, 0.5, -0.5, -1, 0, 0, 1, 0, // Left -0.5, 0.5, 0.5, -1, 0, 0, 0, 0, // -0.5, -0.5, 0.5, -1, 0, 0, 0, 1, // -0.5, -0.5, -0.5, -1, 0, 0, 1, 1, // 0.5, 0.5, 0.5, 1, 0, 0, 1, 0, // Right 0.5, 0.5, -0.5, 1, 0, 0, 0, 0, // 0.5, -0.5, -0.5, 1, 0, 0, 0, 1, // 0.5, -0.5, 0.5, 1, 0, 0, 1, 1 // }; Vector <uint> indexData = new uint[] { 0, 1, 2, 0, 2, 3, // Front face 4, 5, 6, 4, 6, 7, // Bottom face 8, 9, 10, 8, 10, 11, // Back face 14, 13, 12, 15, 14, 12, // Top face 16, 17, 18, 16, 18, 19, // Left face 20, 21, 22, 20, 22, 23 // Right face }; // Prep the bitmap data to be used as a texture var texture = new ActionScript.Images.box().bitmapData; // Prepare a shader for rendering shader = new LightedRender(); shader.upload(context); shader.setGeometry(vertexData, indexData, texture); // The projection defines a 3D perspective to be rendered projection = new PerspectiveMatrix3D(); projection.perspectiveFieldOfViewRH(45, (double)DefaultWidth / (double)DefaultHeight, 1, 500); // The pivot will keep track of the model's current rotation pivot = new Vector3D(); // Prepare a matrix which we'll use to apply transformations to the model modelMatrix = new Matrix3D(); modelMatrix.identity(); modelMatrix.appendRotation(45, Vector3D.X_AXIS, pivot); modelMatrix.appendRotation(45, Vector3D.Y_AXIS, pivot); modelMatrix.appendRotation(45, Vector3D.Z_AXIS, pivot); // The view matrix will contain the concatenation of all transformations viewMatrix = new Matrix3D(); // Prepare lighting lightColor = new Vector3D(0.95, 0.80, 0.55, 0.8); // R,G,B,strength ambient = new Vector3D(0.00, 0.05, 0.1); lightPos = new Vector3D(1.0, 1.0, -4.0, 0.2); // Start rendering frames //addEventListener(Event.ENTER_FRAME, renderFrame, false, 0, true); this.enterFrame += delegate { // Clear away the old frame render context.clear(0.05, 0.12, 0.18); // Dark grey background // Rotate the model matrix modelMatrix.appendRotation(0.4, Vector3D.X_AXIS, pivot); modelMatrix.appendRotation(0.3, Vector3D.Y_AXIS, pivot); // Calculate the view matrix, and run the shader program! viewMatrix.identity(); viewMatrix.append(modelMatrix); viewMatrix.appendTranslation(0, 0, -2); viewMatrix.append(projection); viewMatrix.transpose(); shader.render(viewMatrix, lightPos, lightColor, ambient); // Show the newly rendered frame on screen context.present(); }; // Created with EasyAGAL! //var bitmap:Bitmap = new createdWith(); //bitmap.y = CONTEXT_HEIGHT - bitmap.height; //addChild(bitmap); }; stage3D.requestContext3D(Context3DRenderMode.AUTO); //trace("Awaiting context..."); }
public ApplicationSprite() { // Set the default stage behavior stage.scaleMode = StageScaleMode.NO_SCALE; stage.align = StageAlign.TOP_LEFT; // Request a 3D context instance stage3D = stage.stage3Ds[0]; //stage3D.addEventListener(Event.CONTEXT3D_CREATE, contextReady, false, 0, true); stage3D.context3DCreate += delegate { //stage3D.removeEventListener(Event.CONTEXT3D_CREATE, contextReady); // Get the new context context = stage3D.context3D; //trace("Got context! " + context); // Configure back buffer context.configureBackBuffer(DefaultWidth, DefaultHeight, 2, true); context.setCulling(Context3DTriangleFace.BACK); stage3D.x = stage3D.y = 0; // Prepare vertex data: x,y,z, nx,ny,nz, u,v (position, normal, texture) Vector<double> vertexData = new double[] { 0.5, 0.5, -0.5, 0,0,-1, 1,0, // Front -0.5, 0.5, -0.5, 0,0,-1, 0,0, // -0.5, -0.5, -0.5, 0,0,-1, 0,1, // 0.5, -0.5, -0.5, 0,0,-1, 1,1, // 0.5, -0.5, -0.5, 0,-1,0, 1,0, // Bottom -0.5, -0.5, -0.5, 0,-1,0, 0,0, // -0.5, -0.5, 0.5, 0,-1,0, 0,1, // 0.5, -0.5, 0.5, 0,-1,0, 1,1, // -0.5, 0.5, 0.5, 0,0,1, 1,0, // Back 0.5, 0.5, 0.5, 0,0,1, 0,0, // 0.5, -0.5, 0.5, 0,0,1, 0,1, // -0.5, -0.5, 0.5, 0,0,1, 1,1, // -0.5, 0.5, 0.5, 0,1,0, 1,0, // Top 0.5, 0.5, 0.5, 0,1,0, 0,0, // 0.5, 0.5, -0.5, 0,1,0, 0,1, // -0.5, 0.5, -0.5, 0,1,0, 1,1, // -0.5, 0.5, -0.5, -1,0,0, 1,0, // Left -0.5, 0.5, 0.5, -1,0,0, 0,0, // -0.5, -0.5, 0.5, -1,0,0, 0,1, // -0.5, -0.5, -0.5, -1,0,0, 1,1, // 0.5, 0.5, 0.5, 1,0,0, 1,0, // Right 0.5, 0.5, -0.5, 1,0,0, 0,0, // 0.5, -0.5, -0.5, 1,0,0, 0,1, // 0.5, -0.5, 0.5, 1,0,0, 1,1 // }; Vector<uint> indexData = new uint[] { 0, 1, 2, 0, 2, 3, // Front face 4, 5, 6, 4, 6, 7, // Bottom face 8, 9, 10, 8, 10, 11, // Back face 14, 13, 12, 15, 14, 12, // Top face 16, 17, 18, 16, 18, 19, // Left face 20, 21, 22, 20, 22, 23 // Right face }; // Prep the bitmap data to be used as a texture var texture = new ActionScript.Images.box().bitmapData; // Prepare a shader for rendering shader = new LightedRender(); shader.upload(context); shader.setGeometry(vertexData, indexData, texture); // The projection defines a 3D perspective to be rendered projection = new PerspectiveMatrix3D(); projection.perspectiveFieldOfViewRH(45, (double)DefaultWidth / (double)DefaultHeight, 1, 500); // The pivot will keep track of the model's current rotation pivot = new Vector3D(); // Prepare a matrix which we'll use to apply transformations to the model modelMatrix = new Matrix3D(); modelMatrix.identity(); modelMatrix.appendRotation(45, Vector3D.X_AXIS, pivot); modelMatrix.appendRotation(45, Vector3D.Y_AXIS, pivot); modelMatrix.appendRotation(45, Vector3D.Z_AXIS, pivot); // The view matrix will contain the concatenation of all transformations viewMatrix = new Matrix3D(); // Prepare lighting lightColor = new Vector3D(0.95, 0.80, 0.55, 0.8); // R,G,B,strength ambient = new Vector3D(0.00, 0.05, 0.1); lightPos = new Vector3D(1.0, 1.0, -4.0, 0.2); // Start rendering frames //addEventListener(Event.ENTER_FRAME, renderFrame, false, 0, true); this.enterFrame += delegate { // Clear away the old frame render context.clear(0.05, 0.12, 0.18); // Dark grey background // Rotate the model matrix modelMatrix.appendRotation(0.4, Vector3D.X_AXIS, pivot); modelMatrix.appendRotation(0.3, Vector3D.Y_AXIS, pivot); // Calculate the view matrix, and run the shader program! viewMatrix.identity(); viewMatrix.append(modelMatrix); viewMatrix.appendTranslation(0, 0, -2); viewMatrix.append(projection); viewMatrix.transpose(); shader.render(viewMatrix, lightPos, lightColor, ambient); // Show the newly rendered frame on screen context.present(); }; // Created with EasyAGAL! //var bitmap:Bitmap = new createdWith(); //bitmap.y = CONTEXT_HEIGHT - bitmap.height; //addChild(bitmap); }; stage3D.requestContext3D(Context3DRenderMode.AUTO); //trace("Awaiting context..."); }