protected virtual void setupEnvironment() { // add skybox cube var mesh = SSAssetManager.GetInstance<SSMesh_wfOBJ>("./skybox/","skybox.obj"); SSObject skyboxCube = new SSObjectMesh(mesh); environmentScene.AddObject(skyboxCube); skyboxCube.Scale = new Vector3(0.7f); skyboxCube.renderState.lighted = false; // scene.addObject(skyboxCube); SSObject skyboxStars = new SSObjectMesh(new SimpleStarfieldMesh(1600)); environmentScene.AddObject(skyboxStars); skyboxStars.renderState.lighted = false; }
public void setupScene() { scene = new SSScene (); var lightPos = new Vector3 (5.0f, 40.0f, 10.0f); // 0. Add Lights var light = new SSLight (LightName.Light0); light.Pos = lightPos; scene.addLight(light); // 1. Add Objects SSObject triObj; scene.addObject (triObj = new SSObjectTriangle () ); triObj.Pos = lightPos; // add drone SSObject droneObj = new SSObjectMesh (new SSMesh_wfOBJ (SSAssetManager.mgr.getContext ("./drone2/"), "drone2.obj", true, shaderPgm)); scene.addObject (this.activeModel = droneObj); droneObj.renderState.lighted = true; droneObj.ambientMatColor = new Color4(0.2f,0.2f,0.2f,0.2f); droneObj.diffuseMatColor = new Color4(0.3f,0.3f,0.3f,0.3f); droneObj.specularMatColor = new Color4(0.3f,0.3f,0.3f,0.3f); droneObj.shininessMatColor = 10.0f; droneObj.MouseDeltaOrient(-40.0f,0.0f); droneObj.Pos = new OpenTK.Vector3(-5,0,0); // add second drone SSObject drone2Obj = new SSObjectMesh( new SSMesh_wfOBJ(SSAssetManager.mgr.getContext("./drone2/"), "drone2.obj", true, shaderPgm) ); scene.addObject (drone2Obj); drone2Obj.renderState.lighted = true; drone2Obj.ambientMatColor = new Color4(0.3f,0.3f,0.3f,0.3f); drone2Obj.diffuseMatColor = new Color4(0.3f,0.3f,0.3f,0.3f); drone2Obj.shininessMatColor = 10.0f; drone2Obj.Pos = new OpenTK.Vector3(20,0,0); drone2Obj.MouseDeltaOrient(20.0f,0.0f); // last. Add Camera scene.addObject (scene.activeCamera = new SSCameraThirdPerson (droneObj)); }
protected override void setupScene() { base.setupScene (); // checkerboard floor #if true { SSTexture tex = SSAssetManager.GetInstance<SSTexture> (".", "checkerboard.png"); const float tileSz = 4f; const int gridSz = 10; var tileVertices = new SSVertex_PosNormTex[SSTexturedNormalQuad.c_doubleFaceVertices.Length]; SSTexturedNormalQuad.c_doubleFaceVertices.CopyTo(tileVertices, 0); for (int v = 0; v < tileVertices.Length; ++v) { tileVertices[v].TexCoord *= (float)gridSz; } var quadMesh = new SSVertexMesh<SSVertex_PosNormTex>(tileVertices); quadMesh.textureMaterial = new SSTextureMaterial(tex); var tileObj = new SSObjectMesh(quadMesh); tileObj.Name = "Tiles"; tileObj.Selectable = false; tileObj.Orient(Quaternion.FromAxisAngle(Vector3.UnitX, (float)Math.PI/2f)); tileObj.Scale = new Vector3(tileSz * gridSz); //tileObj.boundingSphere = new SSObjectSphere(0f); scene.AddObject(tileObj); } #endif // skeleton mesh test #if true { SSSkeletalAnimation animIdle = SSAssetManager.GetInstance<SSSkeletalAnimationMD5>("./boneman", "boneman_idle.md5anim"); SSSkeletalAnimation animRunning = SSAssetManager.GetInstance<SSSkeletalAnimationMD5>("./boneman", "boneman_running.md5anim"); SSSkeletalAnimation animAttack = SSAssetManager.GetInstance<SSSkeletalAnimationMD5>("./boneman", "boneman_attack.md5anim"); SSSkeletalMesh[] meshes = SSAssetManager.GetInstance<SSSkeletalMeshMD5[]>("./boneman", "boneman.md5mesh"); var tex = SSAssetManager.GetInstance<SSTexture>("./boneman", "skin.png"); foreach (var skeliMesh in meshes) { #if true var renderMesh0 = new SSSkeletalRenderMesh(skeliMesh); var obj0 = new SSObjectMesh(renderMesh0); obj0.MainColor = Color4.DarkGray; obj0.Name = "grey bones (bind pose)"; obj0.Pos = new Vector3(-18f, 0f, -18f); obj0.Orient(Quaternion.FromAxisAngle(Vector3.UnitX, -(float)Math.PI/2f)); scene.AddObject(obj0); tracker0 = new SSSimpleObjectTrackingJoint(obj0); tracker0.jointPositionLocal = animIdle.computeJointFrame(11, 0).position; tracker0.neutralViewOrientationLocal = animIdle.computeJointFrame(11, 0).orientation; tracker0.neutralViewDirectionBindPose = Vector3.UnitY; tracker0.neutralViewUpBindPose = Vector3.UnitZ; renderMesh0.addCustomizedJoint(11, tracker0); #endif #if true var renderMesh1 = new SSSkeletalRenderMesh(skeliMesh); var obj1 = new SSObjectMesh(renderMesh1); obj1.MainColor = Color4.DarkRed; obj1.Name = "red bones (running loop)"; obj1.Pos = new Vector3(6f, 0f, -12f); obj1.Orient(Quaternion.FromAxisAngle(Vector3.UnitX, -(float)Math.PI/2f)); scene.AddObject(obj1); renderMesh1.playAnimationLoop(animRunning, 0f); #endif #if true var renderMesh2 = new SSSkeletalRenderMesh(skeliMesh); renderMesh2.playAnimationLoop(animIdle, 0f, "all"); renderMesh2.playAnimationLoop(animRunning, 0f, "LeftClavicle", "RightClavicle"); var obj2 = new SSObjectMesh(renderMesh2); obj2.MainColor = Color.Green; obj2.Name = "green bones (idle + running loop mixed)"; obj2.Pos = new Vector3(0f, 0f, -12f); obj2.Orient(Quaternion.FromAxisAngle(Vector3.UnitX, -(float)Math.PI/2f)); scene.AddObject(obj2); #endif #if true var renderMesh3 = new SSSkeletalRenderMesh(skeliMesh); renderMesh3.playAnimationLoop(animIdle, 0f, "all"); var obj3 = new SSObjectMesh(renderMesh3); obj3.MainColor = Color.DarkCyan; obj3.Name = "blue bones (idle loop)"; obj3.Pos = new Vector3(-6f, 0f, -12f); obj3.Orient(Quaternion.FromAxisAngle(Vector3.UnitX, -(float)Math.PI/2f)); scene.AddObject(obj3); #endif // state machines setup for skeletal render mesh 4 and 5 var skeletonWalkDescr = new SSAnimationStateMachine(); skeletonWalkDescr.addState("idle", animIdle, true); skeletonWalkDescr.addState("running1", animRunning); skeletonWalkDescr.addState("running2", animRunning); skeletonWalkDescr.addAnimationEndsTransition("idle", "running1", 0.3f); skeletonWalkDescr.addAnimationEndsTransition("running1", "running2", 0f); skeletonWalkDescr.addAnimationEndsTransition("running2", "idle", 0.3f); var skeletonAttackDescr = new SSAnimationStateMachine(); skeletonAttackDescr.addState("inactive", null, true); skeletonAttackDescr.addState("attack", animAttack); skeletonAttackDescr.addStateTransition(null, "attack", 0.5f); skeletonAttackDescr.addAnimationEndsTransition("attack", "inactive", 0.5f); #if true // state machine test (in slow motion) var renderMesh4 = new SSSkeletalRenderMesh(skeliMesh); renderMesh4.timeScale = 0.25f; var obj4 = new SSObjectMesh(renderMesh4); obj4.MainColor = Color.DarkMagenta; obj4.Name = "magenta bones (looping idle/walk; interactive attack; slowmo)"; obj4.Pos = new Vector3(-12f, 0f, 0f); obj4.Orient(Quaternion.FromAxisAngle(Vector3.UnitX, -(float)Math.PI/2f)); scene.AddObject(obj4); var renderMesh4WallSm = renderMesh4.addStateMachine(skeletonWalkDescr, "all"); renderMesh4AttackSm = renderMesh4.addStateMachine(skeletonAttackDescr, "LeftClavicle", "RightClavicle"); tracker4 = new SSSimpleObjectTrackingJoint(obj4); tracker4.jointPositionLocal = animRunning.computeJointFrame(11, 0).position; tracker4.neutralViewOrientationLocal = animRunning.computeJointFrame(11, 0).orientation; tracker4.neutralViewDirectionBindPose = Vector3.UnitY; renderMesh4.addCustomizedJoint(11, tracker4); #endif #if true // another mesh, using the same state machine but running at normal speed var renderMesh5 = new SSSkeletalRenderMesh(skeliMesh); var renderMesh5WalkSm = renderMesh5.addStateMachine(skeletonWalkDescr, "all"); renderMesh5AttackSm = renderMesh5.addStateMachine(skeletonAttackDescr, "LeftClavicle", "RightClavicle"); var obj5 = new SSObjectMesh(renderMesh5); obj5.Name = "orange bones (looping idle/walk, interactive attack + parametric neck rotation)"; obj5.Pos = new Vector3(12f, 0f, 0f); obj5.Orient(Quaternion.FromAxisAngle(Vector3.UnitX, -(float)Math.PI/2f)); obj5.MainColor = Color4.DarkOrange; scene.AddObject(obj5); renderMesh5NeckJoint = new SSPolarJoint(); renderMesh5NeckJoint.positionOffset = new Vector3(0f, 0.75f, 0f); renderMesh5.addCustomizedJoint("UpperNek", renderMesh5NeckJoint); #endif } } #endif #if true // bob mesh test { var bobMeshes = SSAssetManager.GetInstance<SSSkeletalMeshMD5[]>( "./bob_lamp/", "bob_lamp_update.md5mesh"); var bobAnim = SSAssetManager.GetInstance<SSSkeletalAnimationMD5>( "./bob_lamp/", "bob_lamp_update.md5anim"); var bobRender = new SSSkeletalRenderMesh(bobMeshes); bobRender.playAnimationLoop(bobAnim, 0f); bobRender.alphaBlendingEnabled = true; bobRender.timeScale = 0.5f; var bobObj = new SSObjectMesh(bobRender); bobObj.Name = "Bob"; bobObj.Pos = new Vector3(10f, 0f, 10f); bobObj.Orient(Quaternion.FromAxisAngle(Vector3.UnitX, -(float)Math.PI/2f)); scene.AddObject(bobObj); } #endif }
protected override void setupScene() { base.setupScene (); var mesh = SSAssetManager.GetInstance<SSMesh_wfOBJ> ("./drone2/", "Drone2.obj"); // add drone SSObject droneObj = new SSObjectMesh (mesh); main3dScene.AddObject (droneObj); droneObj.renderState.lighted = true; droneObj.AmbientMatColor = new Color4(0.1f,0.1f,0.1f,0.1f); droneObj.DiffuseMatColor = new Color4(0.3f,0.3f,0.3f,0.3f); droneObj.SpecularMatColor = new Color4(0.3f,0.3f,0.3f,0.3f); droneObj.EmissionMatColor = new Color4(0.3f,0.3f,0.3f,0.3f); droneObj.ShininessMatColor = 10.0f; //droneObj.EulerDegAngleOrient(-40.0f,0.0f); droneObj.Pos = new OpenTK.Vector3(0f, 0f, -15f); droneObj.Name = "drone 1"; // add second drone SSObject drone2Obj = new SSObjectMesh( SSAssetManager.GetInstance<SSMesh_wfOBJ>("./drone2/", "Drone2.obj") ); main3dScene.AddObject (drone2Obj); drone2Obj.renderState.lighted = true; drone2Obj.AmbientMatColor = new Color4(0.3f,0.3f,0.3f,0.3f); drone2Obj.DiffuseMatColor = new Color4(0.3f,0.3f,0.3f,0.3f); droneObj.SpecularMatColor = new Color4(0.3f,0.3f,0.3f,0.3f); drone2Obj.EmissionMatColor = new Color4(0.3f,0.3f,0.3f,0.3f); drone2Obj.ShininessMatColor = 10.0f; drone2Obj.EulerDegAngleOrient(-40f, 0f); drone2Obj.Pos = new OpenTK.Vector3(0f, 0f, 0f); drone2Obj.Name = "drone 2"; // instanced asteroid ring //if (false) { var roidmesh = SSAssetManager.GetInstance<SSMesh_wfOBJ> ("simpleasteroid", "asteroid.obj"); var ringGen = new BodiesRingGenerator ( 120f, 50f, Vector3.Zero, Vector3.UnitY, 250f, 0f, (float)Math.PI*2f, 1f, 3f, 1f, 0.5f //10f, 30f, 1f, 20f ); var ringEmitter = new SSBodiesFieldEmitter (ringGen); ringEmitter.particlesPerEmission = 10000; //ringEmitter.ParticlesPerEmission = 10; var ps = new SSParticleSystemData(10000); ps.addEmitter(ringEmitter); Console.WriteLine ("Packing 10k asteroids into a ring. This may take a second..."); ps.emitAll(); asteroidRingRenderer = new SSInstancedMeshRenderer (ps, roidmesh, BufferUsageHint.StaticDraw); asteroidRingRenderer.simulateOnUpdate = false; asteroidRingRenderer.Name = "instanced asteroid renderer"; asteroidRingRenderer.renderState.castsShadow = true; asteroidRingRenderer.renderState.receivesShadows = true; asteroidRingRenderer.selectable = true; asteroidRingRenderer.useBVHForIntersections = true; main3dScene.AddObject (asteroidRingRenderer); } // particle system test // particle systems should be drawn last (if it requires alpha blending) //if (false) { // setup an emitter var box = new ParticlesSphereGenerator (new Vector3(0f, 0f, 0f), 10f); var emitter = new SSParticlesFieldEmitter (box); //emitter.EmissionDelay = 5f; emitter.particlesPerEmission = 1; emitter.emissionInterval = 0.5f; emitter.life = 1000f; emitter.colorOffsetComponentMin = new Color4 (0.5f, 0.5f, 0.5f, 1f); emitter.colorOffsetComponentMax = new Color4 (1f, 1f, 1f, 1f); emitter.velocityComponentMax = new Vector3 (.3f); emitter.velocityComponentMin = new Vector3 (-.3f); emitter.angularVelocityMin = new Vector3 (-0.5f); emitter.angularVelocityMax = new Vector3 (0.5f); emitter.dragMin = 0f; emitter.dragMax = .1f; RectangleF[] uvRects = new RectangleF[18*6]; float tileWidth = 1f / 18f; float tileHeight = 1f / 6f; for (int r = 0; r < 6; ++r) { for (int c = 0; c < 18; ++c) { uvRects [r*18 + c] = new RectangleF (tileWidth * (float)r, tileHeight * (float)c, tileWidth, tileHeight); } } emitter.spriteRectangles = uvRects; var periodicExplosiveForce = new SSPeriodicExplosiveForceEffector (); periodicExplosiveForce.effectInterval = 3f; periodicExplosiveForce.explosiveForceMin = 1000f; periodicExplosiveForce.explosiveForceMax = 5000f; periodicExplosiveForce.effectDelay = 5f; periodicExplosiveForce.centerMin = new Vector3 (-30f, -30f, -30f); periodicExplosiveForce.centerMax = new Vector3 (+30f, +30f, +30f); //periodicExplosiveForce.Center = new Vector3 (10f); // make a particle system SSParticleSystemData cubesPs = new SSParticleSystemData (1000); cubesPs.addEmitter(emitter); cubesPs.addEffector (periodicExplosiveForce); // test a renderer var tex = SSAssetManager.GetInstance<SSTextureWithAlpha>(".", "elements.png"); var cubesRenderer = new SSInstancedMeshRenderer (cubesPs, SSTexturedNormalCube.Instance); cubesRenderer.Pos = new Vector3 (0f, 0f, -30f); cubesRenderer.alphaBlendingEnabled = false; cubesRenderer.Name = "cube particle renderer"; cubesRenderer.renderState.castsShadow = true; cubesRenderer.renderState.receivesShadows = true; cubesRenderer.textureMaterial = new SSTextureMaterial (null, null, tex, null); cubesRenderer.selectable = true; main3dScene.AddObject(cubesRenderer); //cubesRenderer.renderState.visible = false; // test explositons //if (false) { SExplosionRenderManager aer = new SExplosionRenderManager (100); aer.Pos = cubesRenderer.Pos; alpha3dScene.AddObject (aer); periodicExplosiveForce.explosionEventHandlers += (pos, force) => { aer.showExplosion(pos, force/periodicExplosiveForce.explosiveForceMin*1.5f); }; } } }
protected Vector3 _neutralViewYLocal; // "Y" #endregion Fields #region Constructors public SSSimpleObjectTrackingJoint(SSObjectMesh hostObject, SSObject target = null) { _hostObject = hostObject; targetObject = target; }
protected override void setupScene() { base.setupScene (); laserOccDiskScene3d = new SSScene (mainShader, pssmShader, instancingShader, instancingPssmShader); laserFlareScene2d = new SSScene (mainShader, pssmShader, instancingShader, instancingPssmShader); var mesh = SSAssetManager.GetInstance<SSMesh_wfOBJ> ("./drone2/", "Drone2.obj"); // add drones droneObj1 = new SSObjectMesh (mesh); droneObj1.Pos = new OpenTK.Vector3(-20f, 0f, -15f); droneObj1.Orient(Quaternion.FromAxisAngle(Vector3.UnitY, (float)Math.PI/2f)); droneObj1.AmbientMatColor = new Color4(0.1f,0.1f,0.1f,0.1f); droneObj1.DiffuseMatColor = new Color4(0.3f,0.3f,0.3f,0.3f); droneObj1.SpecularMatColor = new Color4(0.3f,0.3f,0.3f,0.3f); droneObj1.EmissionMatColor = new Color4(0.3f,0.3f,0.3f,0.3f); //droneObj1.renderState.visible = false; droneObj1.Name = "attacker drone"; main3dScene.AddObject (droneObj1); droneObj2 = new SSObjectMesh (mesh); droneObj2.Pos = new OpenTK.Vector3(20f, 0f, -15f); droneObj2.AmbientMatColor = new Color4(0.1f,0.1f,0.1f,0.1f); droneObj2.DiffuseMatColor = new Color4(0.3f,0.3f,0.3f,0.3f); droneObj2.SpecularMatColor = new Color4(0.3f,0.3f,0.3f,0.3f); droneObj2.EmissionMatColor = new Color4(0.3f,0.3f,0.3f,0.3f); droneObj2.Name = "target drone"; droneObj2.MainColor = new Color4(1f, 0f, 0.7f, 1f); //droneObj2.renderState.visible = false; main3dScene.AddObject (droneObj2); // manages laser objects laserManager = new SLaserManager(alpha3dScene, laserOccDiskScene3d, laserFlareScene2d); // tweak the laser start point (by adding an offset in object-local coordinates) laserSourceTxfm = Matrix4.CreateTranslation (0f, 1f, 2.75f); // debugging snippets: //droneObj1.MainColor = Color4.Green; //droneObj1.renderState.visible = false; }
public SSSimpleObjectTrackingJoint(SSObjectMesh hostObject, SSObject target = null) { _hostObject = hostObject; targetObject = target; }
protected override void setupScene() { base.setupScene(); var droneMesh = SSAssetManager.GetInstance<SSMesh_wfOBJ> ("./drone2/", "Drone2.obj"); //var droneMesh = SSAssetManager.GetInstance<SSMesh_wfOBJ> ("missiles", "missile.obj"); var vandalMesh = SSAssetManager.GetInstance<SSMesh_wfOBJ> ("missiles", "vandal_assembled.obj"); // add drones attackerDrone = new SSObjectMesh (droneMesh); attackerDrone.Pos = new OpenTK.Vector3(-20f, 0f, 0f); attackerDrone.Orient(Vector3.UnitX, Vector3.UnitY); attackerDrone.AmbientMatColor = new Color4(0.1f,0.1f,0.1f,0.1f); attackerDrone.DiffuseMatColor = new Color4(0.3f,0.3f,0.3f,0.3f); attackerDrone.SpecularMatColor = new Color4(0.3f,0.3f,0.3f,0.3f); attackerDrone.EmissionMatColor = new Color4(0.3f,0.3f,0.3f,0.3f); attackerDrone.Name = "attacker drone"; main3dScene.AddObject (attackerDrone); targetDrone = new SSObjectMesh (droneMesh); targetDrone.Pos = new OpenTK.Vector3(200f, 0f, 0f); targetDrone.Orient(-Vector3.UnitX, Vector3.UnitY); targetDrone.AmbientMatColor = new Color4(0.1f,0.1f,0.1f,0.1f); targetDrone.DiffuseMatColor = new Color4(0.3f,0.3f,0.3f,0.3f); targetDrone.SpecularMatColor = new Color4(0.3f,0.3f,0.3f,0.3f); targetDrone.EmissionMatColor = new Color4(0.3f,0.3f,0.3f,0.3f); targetDrone.Name = "target drone"; targetDrone.MainColor = new Color4(1f, 0f, 0.7f, 1f); main3dScene.AddObject (targetDrone); vandalShip = new SSObjectMesh (vandalMesh); vandalShip.Pos = new OpenTK.Vector3(100f, 0f, 0f); vandalShip.Scale = new Vector3 (0.05f); vandalShip.AmbientMatColor = new Color4(0.1f,0.1f,0.1f,0.1f); vandalShip.DiffuseMatColor = new Color4(0.1f,0.1f,0.1f,0.1f); vandalShip.SpecularMatColor = new Color4(0.1f,0.1f,0.1f,0.1f); vandalShip.EmissionMatColor = new Color4(0.0f,0.0f,0.0f,0.0f); vandalShip.Name = "Vandal ship"; vandalShip.MainColor = new Color4 (0.6f, 0.6f, 0.6f, 1f); //vandalShip.MainColor = new Color4(1f, 0f, 0.7f, 1f); //droneObj2.renderState.visible = false; vandalShip.Orient((targetDrone.Pos-vandalShip.Pos).Normalized(), Vector3.UnitY); main3dScene.AddObject (vandalShip); // shows explosions explosionManager = new SExplosionRenderManager (); explosionManager.particleSystem.doShockwave = false; explosionManager.particleSystem.doDebris = false; explosionManager.particleSystem.timeScale = 3f; //explosionManager.renderState.visible = false; alpha3dScene.AddObject(explosionManager); // attacker drone missile parameters attackerDroneMissileParams = new SSpaceMissileParameters(); attackerDroneMissileParams.targetHitHandlers += targetHitHandler; // vandal missile params vandalShipMissileParams = new SSpaceMissileParameters(); vandalShipMissileParams.spawnGenerator = null; vandalShipMissileParams.spawnTxfm = straightMissileSpawnTxfm; vandalShipMissileParams.ejectionMaxRotationVel = 0.05f; vandalShipMissileParams.ejectionVelocity = 15f; vandalShipMissileParams.targetHitHandlers += targetHitHandler; vandalShipMissileParams.pursuitActivationTime = 0.1f; vandalShipMissileParams.ejectionSmokeDuration = 0.5f; vandalShipMissileParams.ejectionSmokeSizeMax = 5f; cameraMissileParams = new SSpaceMissileParameters(); cameraMissileParams.targetHitHandlers += targetHitHandler; cameraMissileParams.spawnGenerator = null; cameraMissileParams.spawnTxfm = straightMissileSpawnTxfm; cameraMissileParams.ejectionMaxRotationVel = 0.05f; cameraMissileParams.ejectionVelocity = 10f; // missile manager missileManager = new SSpaceMissilesRenderManager(main3dScene, alpha3dScene, hud2dScene); // additional statistics text missileStatsText = new SSObjectGDISurface_Text(); missileStatsText.alphaBlendingEnabled = true; missileStatsText.Label = "stats placeholder..."; missileStatsText.Pos = new Vector3 (100f, 100f, 0f); //missileStatsText.Size = 20f; hud2dScene.AddObject(missileStatsText); var targetsManager = new SHudTargetsManager (main3dScene, hud2dScene); targetHud = targetsManager.addTarget( Color4.Red, _showDistanceFunc, (o) => o != null ? o.Name : "none", getTargetObject() ); }