private static SceneObject ProcessOBJ(ObjContext objContext) { if (objContext == null) { throw new ArgumentNullException("objContext"); } SceneObjectGeometry sceneObject = new SceneObjectGeometry(); // Program shader to all objects // sceneObject.ProgramTag = ShadersLibrary.Instance.CreateProgramTag("OpenGL.Standard+LambertVertex", new ShaderCompilerContext("GLO_DEBUG_NORMAL")); sceneObject.ProgramTag = ShadersLibrary.Instance.CreateProgramTag("OpenGL.Standard+PhongFragment"); // sceneObject.ProgramTag = ShadersLibrary.Instance.CreateProgramTag("OpenGL.Standard+LambertVertex"); foreach (ObjGroup objGroup in objContext.Groups) { foreach (ObjGeometry objGeometry in objGroup.MergeGeometries()) { VertexArrays vertexArray = objGeometry.CreateArrays(objContext); GraphicsStateSet objectState = new GraphicsStateSet(); objectState.DefineState(objGeometry.CreateMaterialState()); sceneObject.AddGeometry(vertexArray, objectState); } } return(sceneObject); }
/// <summary> /// Static constructor. /// </summary> static SceneObject() { // Static initialization SceneGraph.Touch(); SceneObjectCamera.Touch(); SceneObjectGeometry.Touch(); SceneObjectLight.Touch(); SceneObjectLightZone.Touch(); }
/// <summary> /// Traverse delegate for creating resources. /// </summary> /// <param name="ctx"> /// The <see cref="GraphicsContext"/> used for creating resources. /// </param> /// <param name="ctxScene"></param> /// <param name="sceneObject"></param> /// <param name="data"></param> /// <returns></returns> private static bool CreateDelegate(GraphicsContext ctx, SceneGraphContext ctxScene, SceneObject sceneObject, object data) { SceneObjectGeometry sceneGeometry = sceneObject as SceneObjectGeometry; if (sceneGeometry != null) { GraphicsStateSet sceneGeometryState = ctxScene.GraphicsStateStack.Current; sceneGeometry.Create(ctx); sceneGeometryState.Create(ctx, sceneGeometry.Program); } return(true); }
/// <summary> /// Traverse delegate for collecting geometries to be drawn. /// </summary> /// <param name="ctx"> /// The <see cref="GraphicsContext"/> used for drawing. /// </param> /// <param name="ctxScene"></param> /// <param name="sceneObject"></param> /// <param name="data"></param> /// <returns></returns> private static bool GraphDrawDelegate(GraphicsContext ctx, SceneGraphContext ctxScene, SceneObject sceneObject, object data) { ObjectBatchContext objectBatchContext = (ObjectBatchContext)data; if (sceneObject.ObjectType == SceneObjectGeometry.ClassObjectType) { SceneObjectGeometry sceneGeometry = (SceneObjectGeometry)sceneObject; GraphicsStateSet sceneGeometryState = ctxScene.GraphicsStateStack.Current; TransformStateBase sceneGeometryModel = (TransformStateBase)sceneGeometryState[TransformStateBase.StateSetIndex]; IEnumerable <SceneObjectBatch> geometries; if ((ctxScene.Scene.SceneFlags & SceneGraphFlags.CullingViewFrustum) != 0) { // View-frustum culling geometries = sceneGeometry.GetGeometries(sceneGeometryState, objectBatchContext.ViewFrustumPlanes, sceneGeometryModel.ModelView); } else { // All geometries geometries = sceneGeometry.GetGeometries(sceneGeometryState); } objectBatchContext.Objects.AddRange(geometries); // Bounding volumes if ((ctxScene.Scene.SceneFlags & SceneGraphFlags.BoundingVolumes) != 0) { } } else if (sceneObject.ObjectType == SceneObjectLightZone.ClassObjectType) { SceneObjectLightZone sceneObjectLightZone = (SceneObjectLightZone)sceneObject; // TODO: Push instead of Clear to support stacked zones objectBatchContext.Lights.Clear(); objectBatchContext.LightZone = sceneObjectLightZone; } else if (sceneObject.ObjectType == SceneObjectLight.ClassObjectType) { objectBatchContext.Lights.Add((SceneObjectLight)sceneObject); } return(true); }