public MaterialPtr RenderPreview() { string textureName = "RttTex_Character_" + Guid.NewGuid().ToString(); string materialName = "RttMat_Character_" + Guid.NewGuid().ToString(); TexturePtr rttTexture = TextureManager.Singleton.CreateManual( textureName, ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, TextureType.TEX_TYPE_2D, GameManager.Instance.renderWindow.Width, GameManager.Instance.renderWindow.Height, 0, PixelFormat.PF_R8G8B8, (int)TextureUsage.TU_RENDERTARGET); RenderTexture renderTexture = rttTexture.GetBuffer().GetRenderTarget(); renderTexture.AddViewport(camera); renderTexture.GetViewport(0).SetClearEveryFrame(false); renderTexture.GetViewport(0).BackgroundColour = new ColourValue(0, 0, 0, 0); renderTexture.Update(); MaterialPtr materialPtr = MaterialManager.Singleton.Create(materialName, ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME); materialPtr.GetTechnique(0).GetPass(0).SetSceneBlending(SceneBlendType.SBT_TRANSPARENT_ALPHA); materialPtr.GetTechnique(0).GetPass(0).CreateTextureUnitState().SetTextureName(textureName); return(materialPtr); }
public void createScene() { Mogre.Vector3 vectLightPos = new Mogre.Vector3(75, 75, 75); m_pSceneMgr.CreateLight("Light").Position = vectLightPos;//(75, 75, 75); DotSceneLoader pDotSceneLoader = new DotSceneLoader(); pDotSceneLoader.ParseDotScene("CubeScene.xml", "General", m_pSceneMgr, m_pSceneMgr.RootSceneNode); pDotSceneLoader = null; m_pSceneMgr.GetEntity("Cube01").QueryFlags = 1 << 1; m_pSceneMgr.GetEntity("Cube02").QueryFlags = 1 << 1; //(CUBE_MASK); m_pSceneMgr.GetEntity("Cube03").QueryFlags = 1 << 1; //(CUBE_MASK); m_pOgreHeadEntity = m_pSceneMgr.CreateEntity("Cube", "ogrehead.mesh"); m_pOgreHeadEntity.QueryFlags = 1 << 0; m_pOgreHeadNode = m_pSceneMgr.RootSceneNode.CreateChildSceneNode("CubeNode"); m_pOgreHeadNode.AttachObject(m_pOgreHeadEntity); Mogre.Vector3 vectOgreHeadNodePos = new Mogre.Vector3(0, 0, -25); m_pOgreHeadNode.Position = vectOgreHeadNodePos;// (Vector3(0, 0, -25)); m_pOgreHeadMat = m_pOgreHeadEntity.GetSubEntity(1).GetMaterial(); m_pOgreHeadMatHigh = m_pOgreHeadMat.Clone("OgreHeadMatHigh"); ColourValue cvAmbinet = new Mogre.ColourValue(1, 0, 0); m_pOgreHeadMatHigh.GetTechnique(0).GetPass(0).Ambient = cvAmbinet; ColourValue cvDiffuse = new Mogre.ColourValue(1, 0, 0, 0); m_pOgreHeadMatHigh.GetTechnique(0).GetPass(0).Diffuse = cvDiffuse; physxScene.Simulate(0); }
protected void drawLine(SceneNode p_Node, string lineName, Vector3 p_Point1, Vector3 p_Point2) { // create material (colour) MaterialPtr moMaterial = MaterialManager.Singleton.Create(lineName, "debugger"); moMaterial.ReceiveShadows = false; moMaterial.GetTechnique(0).SetLightingEnabled(true); moMaterial.GetTechnique(0).GetPass(0).SetDiffuse(0, 0, 1, 0); moMaterial.GetTechnique(0).GetPass(0).SetAmbient(0, 0, 1); moMaterial.GetTechnique(0).GetPass(0).SetSelfIllumination(0, 0, 1); moMaterial.Dispose(); // dispose pointer, not the material // create line object ManualObject manOb = mSceneManager.CreateManualObject(lineName); manOb.Begin(lineName, RenderOperation.OperationTypes.OT_LINE_LIST); manOb.Position(p_Point1.x, p_Point1.y, p_Point1.z); manOb.Position(p_Point2.x, p_Point2.y, p_Point2.z); // ... maybe more points manOb.End(); // create SceneNode and attach the line // p_Node.Position = Vector3.ZERO; p_Node.AttachObject(manOb); }
public void StartBackground(string value, params object[] param) { var sceneManager = param[0] as SceneManager; MaterialManager.Singleton.Remove("Background"); MaterialPtr material = MaterialManager.Singleton.Create("Background", "General"); material.GetTechnique(0).GetPass(0).CreateTextureUnitState(value); material.GetTechnique(0).GetPass(0).DepthCheckEnabled = false; material.GetTechnique(0).GetPass(0).DepthWriteEnabled = false; material.GetTechnique(0).GetPass(0).LightingEnabled = false; Rectangle2D rect = new Rectangle2D(true); rect.SetCorners(-1.0f, 1.0f, 1.0f, -1.0f); rect.SetMaterial("Background"); rect.RenderQueueGroup = (byte)RenderQueueGroupID.RENDER_QUEUE_BACKGROUND; AxisAlignedBox aab = new AxisAlignedBox(); aab.SetInfinite(); rect.BoundingBox = aab; SceneNode node = sceneManager.RootSceneNode.CreateChildSceneNode(Guid.NewGuid().ToString()); node.AttachObject(rect); }
public VideoTexture(SceneManager scm, float width, float height, string aviFileName) { AviManager aviMgr = new AviManager(aviFileName, true); Stream = aviMgr.GetVideoStream(); TexturePtr VideoTexture = TextureManager.Singleton.CreateManual( "Video", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, TextureType.TEX_TYPE_2D, Convert.ToUInt32(Stream.Width), Convert.ToUInt32(Stream.Height), 0, PixelFormat.PF_R8G8B8A8, (int)TextureUsage.TU_DYNAMIC_WRITE_ONLY_DISCARDABLE); MaterialPtr VideoMat = MaterialManager.Singleton.Create( "VideoMat", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME); VideoMat.GetTechnique(0).GetPass(0).LightingEnabled = false; VideoMat.GetTechnique(0).GetPass(0).CreateTextureUnitState("Video"); PixelBuffer = VideoTexture.GetBuffer(); screen = scm.CreateManualObject("Screen"); screen.Dynamic = true; screen.Begin("VideoMat", RenderOperation.OperationTypes.OT_TRIANGLE_LIST); screen.Position(0, 0, 0); screen.TextureCoord(0, 0); screen.Position(width, 0, 0); screen.TextureCoord(1, 0); screen.Position(width, height, 0); screen.TextureCoord(1, 1); screen.Triangle(0, 1, 2); screen.Position(0, 0, 0); screen.TextureCoord(0, 0); screen.Position(width, height, 0); screen.TextureCoord(1, 1); screen.Position(0, height, 0); screen.TextureCoord(0, 1); screen.Triangle(3, 4, 5); screen.End(); SceneNode node = scm.RootSceneNode.CreateChildSceneNode(); node.Position = new Vector3(0, 0, 0); node.AttachObject(screen); Stream.GetFrameOpen(); FrameNum = 0; }
/// <summary> /// /// </summary> /// <param name="timeSinceLastFrame"></param> public void Update(float timeSinceLastFrame) { if (!this.IsCreated) { return; } _dataManager.Update(timeSinceLastFrame); _geometryManager.Update(timeSinceLastFrame); using (MaterialPtr mat = (MaterialPtr)MaterialManager.Singleton.GetByName("SkyX_VolClouds")) { mat.GetTechnique(0).GetPass(0).GetFragmentProgramParameters().SetNamedConstant("uInterpolation", _dataManager.Interpolation); mat.GetTechnique(0).GetPass(0).GetFragmentProgramParameters().SetNamedConstant("uSunDirection", -_sunDirection); } }
private void mnuShowIcons_Click(object sender, EventArgs e) { MaterialPtr mat = MaterialManager.Singleton.GetByName("Flag", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME); if (mnuShowIcons.Checked) { mat.GetTechnique(0).GetPass(0).GetTextureUnitState(0).SetAlphaOperation(LayerBlendOperationEx.LBX_SOURCE1, LayerBlendSource.LBS_MANUAL, LayerBlendSource.LBS_CURRENT, 0.4f); } else { mat.GetTechnique(0).GetPass(0).GetTextureUnitState(0).SetAlphaOperation(LayerBlendOperationEx.LBX_SOURCE1, LayerBlendSource.LBS_MANUAL, LayerBlendSource.LBS_CURRENT, 0.0f); } mRoot.RenderOneFrame(); }
/// <summary> /// /// </summary> public void Create() { Remove(); //Data manager this.DataManager = new DataManager(this); this.DataManager.Create(128, 128, 20); //Geometry manager this.GeometryManager = new GeometryManager(this, _height, _radius, _alpha, _beta, _numberOfBlocks, _na, _nb, _nc); this.GeometryManager.Create(); using (MaterialPtr mat = (MaterialPtr)MaterialManager.Singleton.GetByName("SkyX_VolClouds")) { mat.GetTechnique(0).GetPass(0).GetVertexProgramParameters().SetNamedConstant("uRadius", _radius); } this.IsCreated = true; // Update MaterialPtr parameters this.SunColor = _sunColor; this.AmbientColor = _ambientColor; this.LightResponse = _lightResponse; this.AmbientFactors = _ambientFactors; // Set current wheater int nforced = (_numberOfForcedUpdates == -1) ? 2 : _numberOfForcedUpdates; SetWeather(_weather.x, _weather.y, nforced); }
private void CreateLine(ManualObject mo, Vector3 origin, Vector3 final, int useMaterial, Vector4 color) { float lineWidth = 0.1f; RenderOperation.OperationTypes operation = RenderOperation.OperationTypes.OT_TRIANGLE_FAN; switch (useMaterial) { case 1: mo.Begin("SharpMap/Line3D_v1", operation); break; default: MaterialPtr material = MaterialManager.Singleton.CreateOrRetrieve("Test/ColourLines3d", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME).first; material.GetTechnique(0).GetPass(0).VertexColourTracking = (int)TrackVertexColourEnum.TVC_AMBIENT; mo.Begin("Test/ColourLines3d", operation); break; } Vector3 delta = final - origin; delta = new Vector3(-delta.y, delta.x, delta.z).NormalisedCopy *lineWidth; mo.Position(origin); mo.Position(final); mo.Position(final + delta); mo.Position(origin + delta); //lines3d.TextureCoord((float)i / (float)pointsList.Count); ManualObject.ManualObjectSection section = lines3d.End(); section.SetCustomParameter(constantColor, color); }
/// <summary> /// /// </summary> public void Update() { if (!this.IsCreated) { return; } float radius = this.SkyX.Camera.FarClipDistance * 0.95f; float size = radius * this.MoonSize; this.MoonBillboard.CommonDirection = (this.SkyX.AtmosphereManager.SunDirection).NormalisedCopy.Perpendicular; Vector3 moonRelativePos = this.SkyX.AtmosphereManager.SunDirection * Utility.Cos(Utility.ASin((size / 2.0f) / radius)) * radius; this.MoonSceneNode.Position = this.SkyX.Camera.DerivedPosition + moonRelativePos; if (moonRelativePos.y < -size / 2) { this.MoonSceneNode.SetVisible(false); } else { //this.MoonSceneNode.IsVisible = true; this.MoonSceneNode.SetVisible(true); using (MaterialPtr mat = MaterialManager.Singleton.GetByName("SkyX_Moon")) { //mat.GetTechnique(0).GetPass(0).VertexProgramParameters.SetNamedConstant("uSkydomeCenter", this.SkyX.Camera.DerivedPosition); mat.GetTechnique(0).GetPass(0).GetVertexProgramParameters().SetNamedConstant("uSkydomeCenter", this.SkyX.Camera.DerivedPosition); } } }
private void setupModMenu() { MaterialPtr thumbMat = MaterialManager.Singleton.Create("ModThumbnail", "General"); thumbMat.GetTechnique(0).GetPass(0).CreateTextureUnitState(); MaterialPtr templateMat = MaterialManager.Singleton.GetByName("ModThumbnail"); foreach (string itr in modThumb) { string name = "ModThumb" + (modThumbs.Count + 1).ToString(); MaterialPtr newMat = templateMat.Clone(name); TextureUnitState tus = newMat.GetTechnique(0).GetPass(0).GetTextureUnitState(0); if (ResourceGroupManager.Singleton.ResourceExists("General", itr)) { tus.SetTextureName(itr); } else { tus.SetTextureName("thumb_error.png"); } BorderPanelOverlayElement bp = (BorderPanelOverlayElement) OverlayManager.Singleton.CreateOverlayElementFromTemplate("SdkTrays/Picture", "BorderPanel", (name)); bp.HorizontalAlignment = (GuiHorizontalAlignment.GHA_RIGHT); bp.VerticalAlignment = (GuiVerticalAlignment.GVA_CENTER); bp.MaterialName = (name); GameManager.Instance.trayMgr.getTraysLayer().Add2D(bp); modThumbs.Add(bp); } }
protected unsafe void setupVideoGraphicsObject() { this.mCubeTexture = TextureManager.Singleton.CreateManual( "MyCubeTexture", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, TextureType.TEX_TYPE_2D, (uint)this.TexWidth, (uint)this.TexHeight, 0, Mogre.PixelFormat.PF_A8R8G8B8); MaterialPtr inMat = MaterialManager.Singleton.Create("MyCubeMat", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME); inMat.GetTechnique(0).GetPass(0).CreateTextureUnitState("MyCubeTexture"); mCubeEntity.SetMaterialName("MyCubeMat"); // draw bitmap to texture HardwarePixelBufferSharedPtr texBuffer = this.mCubeTexture.GetBuffer(); texBuffer.Lock(HardwareBuffer.LockOptions.HBL_DISCARD); PixelBox pb = texBuffer.CurrentLock; using (Bitmap bm = new Bitmap( (int)this.mCubeTexture.Width, (int)this.mCubeTexture.Height, (int)((this.mCubeTexture.Width * 4) + (pb.RowSkip * 4)), System.Drawing.Imaging.PixelFormat.Format32bppArgb, pb.data)) { mVideoGraphics = Graphics.FromImage(bm); } texBuffer.Unlock(); texBuffer.Dispose(); }
protected override void CreateScene() { mSceneMgr.AmbientLight = new ColourValue(1, 1, 1); //Entity ent = mSceneMgr.CreateEntity("Head", "ogrehead.mesh"); //SceneNode node = mSceneMgr.RootSceneNode.CreateChildSceneNode("HeadNode"); //node.AttachObject(ent); MaterialPtr mat = MaterialManager.Singleton.Create("BoxColor", "General", true); Technique tech = mat.GetTechnique(0); Pass pass = tech.GetPass(0); TextureUnitState tex = pass.CreateTextureUnitState(); tex.SetTextureName("sphax.jpg", TextureType.TEX_TYPE_2D); tex.NumMipmaps = 0; tex.TextureAnisotropy = 0; tex.SetTextureFiltering(FilterOptions.FO_POINT, FilterOptions.FO_POINT, FilterOptions.FO_POINT); //pass.DepthWriteEnabled=false; //pass.SetSceneBlending(SceneBlendType.SBT_TRANSPARENT_ALPHA); //pass.CullingMode = CullingMode.CULL_NONE; //mCamMan = new Tutorials.CameraMan(mCamera,mc); //mCameraMan = null; mCamera.SetPosition((float)mc.x, (float)mc.y, (float)mc.z); mCamera.Pitch(new Degree(mc.pitch).ValueRadians); mCamera.Yaw(new Degree(mc.yaw).ValueRadians); oldCamPos = mCamera.Position; }
public void AddHydraxDepthTechnique(String materialName) { if (hydrax == null || !hydrax.IsCreated) { return; } MaterialPtr m = MaterialManager.Singleton.GetByName(materialName); if (m != null && m.GetTechnique("_Hydrax_Depth_Technique") == null) { hydraxDepthMaterialsMap[materialName] = ((MaterialPtr)m).NumTechniques; hydraxDepthMaterials.Add(materialName); Technique t = m.CreateTechnique(); hydrax.MaterialManager.AddDepthTechnique(t); m = null; } foreach (Technique t in hydrax.MaterialManager.DepthTechniques) { t.SetFog(true, FogMode.FOG_NONE); } }
// Just override the mandatory create scene method public override void CreateScene() { // Set ambient light sceneMgr.AmbientLight = new ColourValue(0.5f, 0.5f, 0.5f); // Create a point light Light l = sceneMgr.CreateLight("MainLight"); // Accept default settings: point light, white diffuse, just set position // NB I could attach the light to a SceneNode if I wanted it to move automatically with // other objects, but I don't l.Position = new Vector3(20, 80, 50); createScalingPlane(); createScrollingKnot(); createWateryPlane(); // Set up a material for the skydome MaterialPtr skyMat = MaterialManager.Singleton.Create("SkyMat", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME); // Perform no dynamic lighting on the sky skyMat.SetLightingEnabled(false); // Use a cloudy sky TextureUnitState t = skyMat.GetTechnique(0).GetPass(0).CreateTextureUnitState("clouds.jpg"); // Scroll the clouds t.SetScrollAnimation(0.15f, 0f); // System will automatically set no depth write // Create a skydome sceneMgr.SetSkyDome(true, "SkyMat", -5, 2); }
private void setMaterialTexture(Entity p_Entity) { MaterialPtr inMat = MaterialManager.Singleton.Create("MyCubeMat", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME); inMat.GetTechnique(0).GetPass(0).CreateTextureUnitState("MyCubeTexture"); mCubeEntity.SetMaterialName("MyCubeMat"); }
public override void CreateScene() { // Set some camera params camera.FarClipDistance = 30000; camera.NearClipDistance = 20; camera.SetPosition(20000, 500, 20000); camera.SetDirection(1, 0, 0); // Create our text area for display SkyX parameters CreateTextArea(); manager = new SkyManager(base.sceneMgr, base.camera); manager.Create(); // Add our ground atmospheric scattering pass to terrain material MaterialPtr material = MaterialManager.Singleton.GetByName(TerrainMaterialName); manager.GPUManager.AddGroundPass(material.GetTechnique(0).CreatePass(), 5000, SceneBlendType.SBT_TRANSPARENT_COLOUR); // Create our terrain sceneMgr.SetWorldGeometry("Terrain.cfg"); // Add a basic cloud layer manager.CloudsManager.Add(new CloudLayer.LayerOptions()); //Add frame evnet root.FrameStarted += new FrameListener.FrameStartedHandler(FrameStarted); }
public override void InjectMousePressed(MouseEvent arg, MouseButtonID id) { base.InjectMousePressed(arg, id); if (id == MouseButtonID.MB_Right) { if (state == EditState.Free) { editor.HidePivot(); return; } MaterialPtr material = currentSelectedEnt.GetSubEntity(0).GetMaterial(); material.GetTechnique(0).SetAmbient(0, 0, 0); currentSelectedEnt.GetSubEntity(0).SetMaterial(material); state = EditState.Free; currentSelectedEnt.ParentSceneNode.ShowBoundingBox = false; currentSelectedEnt = null; editor.HidePivot(); operation = EditOperation.None; } else if (id == MouseButtonID.MB_Left) { Ray ray = UIManager.Instance.GetCursorRay(editor.Map.Camera); var query = editor.Map.SceneManager.CreateRayQuery(ray); RaySceneQueryResult result = query.Execute(); foreach (var sResult in result) { if (sResult.movable != null && (sResult.movable.Name.StartsWith("SCENE_OBJECT") || sResult.movable.Name.StartsWith("AIMESH"))) { //High light the object var ent = editor.Map.SceneManager.GetEntity(sResult.movable.Name); MaterialPtr material = ent.GetSubEntity(0).GetMaterial(); ColourValue cv = new ColourValue(1, 0, 0); material.GetTechnique(0).SetAmbient(cv); ColourValue cv2 = new ColourValue(1, 0, 0); material.GetTechnique(0).SetDiffuse(cv2); ent.GetSubEntity(0).SetMaterial(material); ent.ParentSceneNode.ShowBoundingBox = true; currentSelectedEnt = ent; state = EditState.Edit; Mogre.Vector3 entCenterPos = ent.GetWorldBoundingBox().Center; editor.ShowPivotAtPosition(entCenterPos); } } } }
/// <summary> /// Make this object opaque /// Warning: assumes the Diffuse value has no opacity set! /// </summary> public void Unghost() { if (isGhosted) { foreach (Entity e in this.entities) { MaterialPtr eMat = e.GetSubEntity(0).GetMaterial(); eMat.GetTechnique(0).GetPass(0).SetSceneBlending(SceneBlendType.SBT_REPLACE); eMat.GetTechnique(0).GetPass(0).DepthWriteEnabled = true; //ColourValue c = eMat.GetTechnique(0).GetPass(0).Diffuse; //eMat.GetTechnique(0).GetPass(0).SetDiffuse(c.r, c.g, c.b, 1.0f); e.GetSubEntity(0).SetMaterial(eMat); e.CastShadows = true; } isGhosted = false; } }
private string CreateTexture(string texture) { string matName; if (!string.IsNullOrEmpty(texture)) { matName = texture.Substring(0, texture.Length - texture.IndexOf('.')); } else { matName = "NoMaterial"; } materialPtr = MaterialManager.Singleton.Create(matName, ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME); materialPtr.GetTechnique(0).GetPass(0).SetSceneBlending(SceneBlendType.SBT_TRANSPARENT_ALPHA); materialPtr.GetTechnique(0).GetPass(0).CreateTextureUnitState().SetTextureName(texture); return(matName); }
//创建场景 private void CreateScene(int width, int height, string filename) { string planename = Guid.NewGuid().ToString("N"); // 地面的法线方向。可以决定地面的朝向, Plane p; p.normal = Vector3.UNIT_Z; p.d = 0; //判断地面模型是否已经创建,主要是处理新建场景后,关闭文档,在次打开时,模型已和纹理材质已创建,在次创建就会报错,在此做判断 if (!MeshManager.Singleton.ResourceExists(planename)) { //创建场景地面模型,通过指定的长和宽 MeshManager.Singleton.CreatePlane(planename, ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, p, width, height, 20, 20, true, 1, 1F, 1F, Vector3.UNIT_Y); //同上面 if (!TextureManager.Singleton.ResourceExists(filename)) { //载入纹理 TexturePtr textureptr = TextureManager.Singleton.Load(filename, ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME); //创建材质 MaterialPtr materialptr = MaterialManager.Singleton.Load(filename, ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME); TextureUnitState state = materialptr.GetTechnique(0).GetPass(0).CreateTextureUnitState(filename); //设置纹理的寻址模式,如果不设置。有可能在结边的时候出现缝隙 state.SetTextureAddressingMode(TextureUnitState.TextureAddressingMode.TAM_MIRROR); //材质相应设置,可参见API文档 materialptr.GetTechnique(0).GetPass(0).DepthWriteEnabled = false; materialptr.GetTechnique(0).GetPass(0).DepthFunction = CompareFunction.CMPF_LESS_EQUAL; } } EsdSceneManager.Singleton.MaterialPtr = MaterialManager.Singleton.GetByName(filename); Entity ent = EsdSceneManager.Singleton.SceneManager.CreateEntity("floor", planename); EsdSceneManager.Singleton.FloorNode = EsdSceneManager.Singleton.SceneManager.RootSceneNode.CreateChildSceneNode(); EsdSceneManager.Singleton.FloorNode.AttachObject(ent); //设计材质 ent.SetMaterialName(filename); //保存当前场景状态。 EsdSceneManager.Singleton.ModelDataManage.modelEntry.场景地面图片 = filename; EsdSceneManager.Singleton.ModelDataManage.modelEntry.场景宽 = width; EsdSceneManager.Singleton.ModelDataManage.modelEntry.场景高 = height; EsdSceneManager.Singleton.ModelDataManage.modelEntry.模型名 = planename; //开始编辑标志 EsdSceneManager.Singleton.IsStarEdit = true; EsdSceneManager.Singleton.OgreImage.UpdataCamera(); }
public static string CreateColoredMaterial(float r, float g, float b, string name = "") { if (name == "") { name = Guid.NewGuid().ToString(); } MaterialPtr moMaterial = MaterialManager.Singleton.Create(name, RESOURCE_GROUP_NAME); moMaterial.ReceiveShadows = false; moMaterial.GetTechnique(0).SetLightingEnabled(true); moMaterial.GetTechnique(0).GetPass(0).SetDiffuse(r, g, b, 0); moMaterial.GetTechnique(0).GetPass(0).SetAmbient(r, g, b); moMaterial.GetTechnique(0).GetPass(0).SetSelfIllumination(r, g, b); moMaterial.Dispose(); // dispose pointer, not the material return(name); }
public static MeshPtr makeTetra(string name, string matname) { MeshBuilderHelper mbh = new MeshBuilderHelper(name, ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, false, 0, 4); UInt32 offPos = mbh.AddElement(VertexElementType.VET_FLOAT3, VertexElementSemantic.VES_POSITION).Offset; UInt32 offNorm = mbh.AddElement(VertexElementType.VET_FLOAT3, VertexElementSemantic.VES_NORMAL).Offset; UInt32 offUV = mbh.AddElement(VertexElementType.VET_FLOAT2, VertexElementSemantic.VES_TEXTURE_COORDINATES).Offset; mbh.CreateVertexBuffer(4, HardwareBuffer.Usage.HBU_STATIC_WRITE_ONLY); int scale = 10; // calculate corners of tetrahedron (with point of origin in middle of volume) Single mbot = scale * 0.2f; // distance middle to bottom Single mtop = scale * 0.62f; // distance middle to top Single mf = scale * 0.289f; // distance middle to front Single mb = scale * 0.577f; // distance middle to back Single mlr = scale * 0.5f; // distance middle to left right Mogre.Vector3[] corners = new Mogre.Vector3[4]; // corners // width / height / depth corners[0] = new Mogre.Vector3(-mlr, -mbot, mf); // left bottom front corners[1] = new Mogre.Vector3(mlr, -mbot, mf); // right bottom front corners[2] = new Mogre.Vector3(0, -mbot, -mb); // (middle) bottom back corners[3] = new Mogre.Vector3(0, mtop, 0); // (middle) top (middle) for (int i = 0; i < 4; i++) { mbh.SetVertFloat((uint)i, offPos, corners[i].x, corners[i].y, corners[i].z); mbh.SetVertFloat((uint)i, offNorm, corners[i].NormalisedCopy.x, corners[i].NormalisedCopy.y, corners[i].NormalisedCopy.z); mbh.SetVertFloat((uint)i, offUV, 0f, 0f); } mbh.CreateIndexBuffer(4, HardwareIndexBuffer.IndexType.IT_16BIT, HardwareBuffer.Usage.HBU_STATIC_WRITE_ONLY); mbh.SetIndex16bit(0, (UInt16)0, (UInt16)1, (UInt16)2); mbh.SetIndex16bit(1, (UInt16)0, (UInt16)1, (UInt16)3); mbh.SetIndex16bit(2, (UInt16)0, (UInt16)2, (UInt16)3); mbh.SetIndex16bit(3, (UInt16)1, (UInt16)2, (UInt16)3); MaterialPtr material = MaterialManager.Singleton.Create("Test/ColourTest", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME); material.GetTechnique(0).GetPass(0).VertexColourTracking = (int)TrackVertexColourEnum.TVC_AMBIENT; material.SetCullingMode(CullingMode.CULL_NONE); MeshPtr m = mbh.Load("Test/ColourTest"); // MeshPtr m = mbh.Load(); m._setBounds(new AxisAlignedBox(0.0f, 0.0f, 0.0f, scale, scale, scale), false); m._setBoundingSphereRadius((float)System.Math.Sqrt(scale * scale + scale * scale)); // the original code was missing this line: m._setBounds(new AxisAlignedBox(new Mogre.Vector3(-scale, -scale, -scale), new Mogre.Vector3(scale, scale, scale)), false); m._setBoundingSphereRadius(scale); return(m); }
unsafe private void NotifyMaterialSetup(uint pass_id, MaterialPtr mat) { // Prepare the fragment params offsets switch (pass_id) { //case 994: // rt_lum4 case 993: // rt_lum3 case 992: // rt_lum2 case 991: // rt_lum1 case 990: // rt_lum0 break; case 800: // rt_brightpass break; case 701: // rt_bloom1 { // horizontal bloom mat.Load(); GpuProgramParametersSharedPtr fparams = mat.GetBestTechnique().GetPass(0).GetFragmentProgramParameters(); String progName = mat.GetBestTechnique().GetPass(0).FragmentProgramName; fixed(float *p_mBloomTexOffsetsHorz = &mBloomTexOffsetsHorz[0, 0]) { fparams.SetNamedConstant("sampleOffsets", p_mBloomTexOffsetsHorz, 15); } fixed(float *p_mBloomTexWeights = &mBloomTexWeights[0, 0]) { fparams.SetNamedConstant("sampleWeights", p_mBloomTexWeights, 15); } break; } case 700: // rt_bloom0 { // vertical bloom mat.Load(); GpuProgramParametersSharedPtr fparams = mat.GetTechnique(0).GetPass(0).GetFragmentProgramParameters(); String progName = mat.GetBestTechnique().GetPass(0).FragmentProgramName; fixed(float *p_mBloomTexOffsetsVert = &mBloomTexOffsetsVert[0, 0]) { fparams.SetNamedConstant("sampleOffsets", p_mBloomTexOffsetsVert, 15); } fixed(float *p_mBloomTexWeights = &mBloomTexWeights[0, 0]) { fparams.SetNamedConstant("sampleWeights", p_mBloomTexWeights, 15); } break; } } }
private void createMaterial(string name, System.Drawing.Image img) { TexturePtr tex = TextureManager.Singleton.Create(name, ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, true); tex.LoadImage(SystemtoMogreImage(img)); MaterialPtr mat = MaterialManager.Singleton.GetByName(name, ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME); if (mat == null) { mat = MaterialManager.Singleton.Create(name, ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME); } mat.CreateTechnique().CreatePass(); mat.GetTechnique(0).GetPass(0).CreateTextureUnitState(name); mat.GetTechnique(0).GetPass(0).LightingEnabled = false; mat.GetTechnique(0).GetPass(0).CullingMode = CullingMode.CULL_NONE; mat.GetTechnique(0).GetPass(0).PolygonMode = PolygonMode.PM_SOLID; mat.GetTechnique(0).GetPass(0).SetSceneBlending(SceneBlendType.SBT_TRANSPARENT_ALPHA); }
/// <summary> /// Register all /// </summary> public void RegisterAll() { for (int k = 0; k < _cloudLayers.Count; k++) { using (MaterialPtr mat = (MaterialPtr)MaterialManager.Singleton.GetByName(this.SkyX.GpuManager.SkydomeMaterialName)){ _cloudLayers[k].RegisterCloudLayer(mat.GetTechnique(0).CreatePass()); mat.Reload(); } } }
/// <summary> /// This method applies a texture map to the Cube /// </summary> private void ManualObjMat() { using (MaterialPtr manualObjMat = MaterialManager.Singleton.Create("floor_mat", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME))// Creates a new Material { using (TextureUnitState manualObjTexture = manualObjMat.GetTechnique(0).GetPass(0).CreateTextureUnitState("floor.jpg")) // Sets the texture for the material { manualObjEntity.SetMaterialName("floor_mat"); // Applies the material to the entity } } }
private void CubeMaterial() { using (MaterialPtr cubeMat = MaterialManager.Singleton.Create("groundMaterial", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME)) // Creates a new Material { using (TextureUnitState cubeTexture = cubeMat.GetTechnique(0).GetPass(0).CreateTextureUnitState("Dirt.jpg")) // Sets the texture for the material { cubeEntity.SetMaterialName("groundMaterial"); // Applies the material to the entity } } }
public void RemoveHydraxDepthTechniques() { foreach (string material in hydraxDepthMaterials) { MaterialPtr m = MaterialManager.Singleton.GetByName(material); if (m != null && m.GetTechnique("_Hydrax_Depth_Technique") != null) { m.RemoveTechnique(hydraxDepthMaterialsMap[material]); m = null; } } }
//public void SetPosition(Vector3 position) //{ // //cubeNode.Position = position; // //physObj.Position = position; //} private void CubeMaterial() { using (MaterialPtr cubeMat = MaterialManager.Singleton.Create("Cube", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME)) { using (TextureUnitState fieldTexture = cubeMat.GetTechnique(0).GetPass(0).CreateTextureUnitState("Dirt.jpg")) { ///cube.SetMaterialName("Quad", "Cube"); } } }
private void SetMaterialFragmentParameter(MaterialPtr mat, ushort passIndex, string constantName, ColourValue colour) { var ps = mat.GetTechnique(0).GetPass(passIndex).GetFragmentProgramParameters(); ps.SetNamedConstant(constantName, colour); mat.GetTechnique(0).GetPass(passIndex).SetFragmentProgramParameters(ps); }
public void InitMogre() { //----------------------------------------------------- // 1 enter ogre //----------------------------------------------------- root = new Root(); //----------------------------------------------------- // 2 configure resource paths //----------------------------------------------------- ConfigFile cf = new ConfigFile(); cf.Load("resources.cfg", "\t:=", true); // Go through all sections & settings in the file ConfigFile.SectionIterator seci = cf.GetSectionIterator(); String secName, typeName, archName; // Normally we would use the foreach syntax, which enumerates the values, but in this case we need CurrentKey too; while (seci.MoveNext()) { secName = seci.CurrentKey; ConfigFile.SettingsMultiMap settings = seci.Current; foreach (KeyValuePair<string, string> pair in settings) { typeName = pair.Key; archName = pair.Value; ResourceGroupManager.Singleton.AddResourceLocation(archName, typeName, secName); } } //----------------------------------------------------- // 3 Configures the application and creates the window //----------------------------------------------------- bool foundit = false; foreach (RenderSystem rs in root.GetAvailableRenderers()) { root.RenderSystem = rs; String rname = root.RenderSystem.Name; if (rname == "Direct3D9 Rendering Subsystem") { foundit = true; break; } } if (!foundit) return; //we didn't find it... Raise exception? //we found it, we might as well use it! root.RenderSystem.SetConfigOption("Full Screen", "No"); root.RenderSystem.SetConfigOption("Video Mode", "640 x 480 @ 32-bit colour"); root.Initialise(false); NameValuePairList misc = new NameValuePairList(); misc["externalWindowHandle"] = hWnd.ToString(); window = root.CreateRenderWindow("Simple Mogre Form Window", 0, 0, false, misc); ResourceGroupManager.Singleton.InitialiseAllResourceGroups(); //----------------------------------------------------- // 4 Create the SceneManager // // ST_GENERIC = octree // ST_EXTERIOR_CLOSE = simple terrain // ST_EXTERIOR_FAR = nature terrain (depreciated) // ST_EXTERIOR_REAL_FAR = paging landscape // ST_INTERIOR = Quake3 BSP //----------------------------------------------------- sceneMgr = root.CreateSceneManager(SceneType.ST_GENERIC, "SceneMgr"); sceneMgr.AmbientLight = new ColourValue(1f, 1f, 1f); //----------------------------------------------------- // 5 Create the camera //----------------------------------------------------- camera = sceneMgr.CreateCamera("SimpleCamera"); camera.Position = new Vector3(400f, 0f, 0f); // Look back along -Z camera.LookAt(new Vector3(-1f, 0f, 0f)); camera.NearClipDistance = 5; viewport = window.AddViewport(camera); viewport.BackgroundColour = new ColourValue(0.0f, 0.0f, 0.0f, 1.0f); material = MaterialManager.Singleton.Create("front", "General"); material.GetTechnique(0).GetPass(0).CreateTextureUnitState("snow3.jpg"); material = MaterialManager.Singleton.Create("other", "General"); material.GetTechnique(0).GetPass(0).CreateTextureUnitState("snow.jpg"); material = MaterialManager.Singleton.Create("back", "General"); material.GetTechnique(0).GetPass(0).CreateTextureUnitState("back2.jpg"); Vector3 moveVector3 = new Vector3(0f,-60f,110f); for (int i = 0; i < cubeCount; i++) { Cube cube = new Cube(); cube.CubeName = "cube" + i.ToString(); cube.BuildCube("front", ref sceneMgr); ManualObject manual = sceneMgr.GetManualObject(cube.CubeName); manual.ConvertToMesh("cubeMesh"+i.ToString()); Entity ent = sceneMgr.CreateEntity("box"+i.ToString(), "cubeMesh"+i.ToString()); SceneNode node = sceneMgr.RootSceneNode.CreateChildSceneNode("boxNode"+i.ToString()); ent.CastShadows = true; node.AttachObject(ent); float y = i * (Cube.cubeHeight + 10) + moveVector3.y; node.Position = new Vector3(0f, y, moveVector3.z); } Plane plane = new Plane(); plane.BuildPlane("back",ref sceneMgr); ManualObject manualPlane = sceneMgr.GetManualObject(plane.PlaneName); manualPlane.ConvertToMesh("planeMesh"); Entity planeEntity = sceneMgr.CreateEntity("planeEntity", "planeMesh"); SceneNode planeNode = sceneMgr.RootSceneNode.CreateChildSceneNode("planeNode"); planeNode.AttachObject(planeEntity); }
private unsafe void NotifyMaterialSetup(uint pass_id, MaterialPtr mat) { // Prepare the fragment params offsets switch (pass_id) { //case 994: // rt_lum4 case 993: // rt_lum3 case 992: // rt_lum2 case 991: // rt_lum1 case 990: // rt_lum0 break; case 800: // rt_brightpass break; case 701: // rt_bloom1 { // horizontal bloom mat.Load(); GpuProgramParametersSharedPtr fparams = mat.GetBestTechnique().GetPass(0).GetFragmentProgramParameters(); String progName = mat.GetBestTechnique().GetPass(0).FragmentProgramName; fixed (float* p_mBloomTexOffsetsHorz = &mBloomTexOffsetsHorz[0, 0]) { fparams.SetNamedConstant("sampleOffsets", p_mBloomTexOffsetsHorz, 15); } fixed (float* p_mBloomTexWeights = &mBloomTexWeights[0, 0]) { fparams.SetNamedConstant("sampleWeights", p_mBloomTexWeights, 15); } break; } case 700: // rt_bloom0 { // vertical bloom mat.Load(); GpuProgramParametersSharedPtr fparams = mat.GetTechnique(0).GetPass(0).GetFragmentProgramParameters(); String progName = mat.GetBestTechnique().GetPass(0).FragmentProgramName; fixed (float* p_mBloomTexOffsetsVert = &mBloomTexOffsetsVert[0, 0]) { fparams.SetNamedConstant("sampleOffsets", p_mBloomTexOffsetsVert, 15); } fixed (float* p_mBloomTexWeights = &mBloomTexWeights[0, 0]) { fparams.SetNamedConstant("sampleWeights", p_mBloomTexWeights, 15); } break; } } }