protected override void OnPostCreate(bool loaded) { base.OnPostCreate(loaded); SubscribeToTickEvent(); if (EngineApp.Instance.ApplicationType != EngineApp.ApplicationTypes.ResourceEditor) { attached_mesh = this.AttachedObjects[0] as MapObjectAttachedMesh; if (attached_mesh == null) { Log.Error("CreatorRoads: Not found attached road mesh."); return; } else { mesh_name = this.Name; if (attached_mesh.MeshObject.Mesh.Save("Data\\" + mesh_name + ".mesh")) { attached_mesh.MeshName = mesh_name + ".mesh"; mesh = attached_mesh.MeshObject.Mesh; } } } }
void AttachMesh() { attachedMesh = new MapObjectAttachedMesh(); attachedMesh.CastDynamicShadows = false; attachedMesh.MeshName = mesh.Name; Attach(attachedMesh); }
void DetachMesh() { if (attachedMesh != null) { Detach(attachedMesh); attachedMesh = null; } }
private void DestroyProductUnitAttachedMesh() { if (productUnitAttachedMesh != null) { Detach(productUnitAttachedMesh); productUnitAttachedMesh = null; } }
private void DetachMeshFromEntity() { if (attachedMesh != null) { Detach(attachedMesh); attachedMesh = null; } }
private void DestroyAttachedMesh() { if (attachedMesh != null) { Detach(attachedMesh); attachedMesh = null; } }
private void UpdateSkin() { if (InitialFaction == null) { return; } //!!!!!!temp. not universal bool badFaction = InitialFaction.Name == "BadFaction"; if (Type.Name == "RTSRobot") { (AttachedObjects[0] as MapObjectAttachedMesh).MeshObject. SubObjects[0].MaterialName = badFaction ? "Robot2" : "Robot"; } else if (Type.Name == "RTSConstructor") { (AttachedObjects[0] as MapObjectAttachedMesh).MeshObject. SubObjects[0].MaterialName = badFaction ? "Red" : "Blue"; } else if (Type.Name == "RTSMine" || Type.Name == "RTSHeadquaters") { foreach (MapObjectAttachedObject attachedObject in AttachedObjects) { MapObjectAttachedMesh meshAttachedObject = attachedObject as MapObjectAttachedMesh; if (meshAttachedObject != null) { MapObjectTypeAttachedMesh typeObject = (MapObjectTypeAttachedMesh)meshAttachedObject.TypeObject; if (typeObject.ForceMaterial == "") { meshAttachedObject.MeshObject.SetMaterialNameForAllSubObjects( badFaction ? (Type.Name + "2") : Type.Name); } } } } else if (Type.Name == "RTSFactory") { foreach (MapObjectAttachedObject attachedObject in AttachedObjects) { MapObjectAttachedMesh meshAttachedObject = attachedObject as MapObjectAttachedMesh; if (meshAttachedObject != null) { MapObjectTypeAttachedMesh typeObject = (MapObjectTypeAttachedMesh)meshAttachedObject.TypeObject; if (typeObject.ForceMaterial == "") { meshAttachedObject.MeshObject.SetMaterialNameForAllSubObjects( badFaction ? (Type.Name + "2") : Type.Name); break; } } } } }
private void AttachMeshToEntity() { attachedMesh = new MapObjectAttachedMesh(); attachedMesh.CastDynamicShadows = true; attachedMesh.MeshName = mesh.Name; //don't scale attached mesh attachedMesh.UseOwnerScale = false; Attach(attachedMesh); RecalculateMapBounds(); }
void CreateProductUnitAttachedMesh() { productUnitAttachedMesh = new MapObjectAttachedMesh(); Attach(productUnitAttachedMesh); string meshName = null; Vec3 meshOffset = Vec3.Zero; Vec3 meshScale = new Vec3(1, 1, 1); { foreach (MapObjectTypeAttachedObject typeAttachedObject in productUnitType.AttachedObjects) { MapObjectTypeAttachedMesh typeAttachedMesh = typeAttachedObject as MapObjectTypeAttachedMesh; if (typeAttachedMesh == null) { continue; } meshName = typeAttachedMesh.MeshName; meshOffset = typeAttachedMesh.Position; meshScale = typeAttachedMesh.Scale; break; } } productUnitAttachedMesh.MeshName = meshName; Vec3 pos = meshOffset; { MapObjectAttachedObject buildPointAttachedHelper = GetAttachedObjectByAlias("productUnitPoint"); if (buildPointAttachedHelper != null) { pos += buildPointAttachedHelper.PositionOffset; } } productUnitAttachedMesh.PositionOffset = pos; productUnitAttachedMesh.ScaleOffset = meshScale; if (Type.Name == "RTSHeadquaters") { foreach (MeshObject.SubObject subMesh in productUnitAttachedMesh.MeshObject.SubObjects) { subMesh.MaterialName = "RTSBuildMaterial"; } } }
public SpringWheel(Bone bone, Unit unit, float size, float stiffness, float damping) { this.bone = bone; this.size = size; this.stiffness = stiffness; this.damping = damping; this.unit = unit; originalBonePosition = bone.Position; originalBoneRotation = bone.Rotation; mesh = new MapObjectAttachedMesh(); mesh.MeshName = "Types/Units/AwesomeAircraft/AwesomeAircraftWheel.mesh"; mesh.ScaleOffset = new Vec3(1, 1, 1); mesh.RotationOffset = Quat.Identity; mesh.PositionOffset = bone.GetDerivedPosition(); unit.Attach(mesh); }
public static bool HitsMesh(this Ray ray, MapObjectAttachedMesh mesh, float maxDistance = 2048) { ray.Direction = ray.Direction.GetNormalize() * maxDistance; Body bod = mesh.Body; if (bod == null) bod = mesh.CollisionBody; MapObject parentObj = mesh.Owner; RayCastResult[] piercingResult = PhysicsWorld.Instance.RayCastPiercing(ray, (int)ContactGroup.CastAll); foreach (var res in piercingResult) { if (res.Distance < maxDistance && res.Shape.Body._InternalUserData != null && res.Shape.Body._InternalUserData == parentObj) { if (Array.Find(bod.Shapes, s2 => s2 == res.Shape) != null) return true; } } return false; }
/// <summary>Overridden from <see cref="Engine.EntitySystem.Entity.OnPostCreate(Boolean)"/>.</summary> protected override void OnPostCreate(bool loaded) { base.OnPostCreate(loaded); //To find the first attached mesh foreach (MapObjectAttachedObject attachedObject in AttachedObjects) { MapObjectAttachedMesh attachedMesh = attachedObject as MapObjectAttachedMesh; if (attachedMesh != null) { blinkMeshObject = attachedMesh.MeshObject; break; } } //To save the original name of a material if (blinkMeshObject != null) { originalMaterialName = blinkMeshObject.SubObjects[0].MaterialName; } }
void UpdateFirstPersonArmsAttachedMesh(MapObjectAttachedMesh armsAttachedMesh, Camera camera) { //update animation tree if (EntitySystemWorld.Instance.Simulation && !EntitySystemWorld.Instance.SystemPauseOfSimulation) { AnimationTree tree = armsAttachedMesh.AnimationTree; if (tree != null) { bool onGround = GetElapsedTimeSinceLastGroundContact() < .2f; //IsOnGround(); bool move = false; float moveSpeed = 0; if (onGround && GroundRelativeVelocitySmooth.ToVec2().Length() > .05f) { move = true; moveSpeed = GroundRelativeVelocity.ToVec2().Length(); } tree.SetParameterValue("move", move ? 1 : 0); tree.SetParameterValue("run", move && IsNeedRun() ? 1 : 0); tree.SetParameterValue("moveSpeed", moveSpeed); float moveSpeedFactor = moveSpeed / Type.RunForwardMaxSpeed; if (moveSpeedFactor > 1) { moveSpeedFactor = 1; } tree.SetParameterValue("moveSpeedFactor", moveSpeedFactor); } } //update scene node armsAttachedMesh.SceneNode.Position = camera.Position + camera.Rotation * armsAttachedMesh.TypeObject.Position; armsAttachedMesh.SceneNode.Rotation = camera.Rotation * armsAttachedMesh.TypeObject.Rotation; //use this code to look arms from another point of view. Useful for calibration position of attached weapon. //armsAttachedMesh.SceneNode.Position = new Vec3( 0, 0, 2 ) + Quat.Identity * armsAttachedMesh.TypeObject.Position; //armsAttachedMesh.SceneNode.Rotation = Quat.Identity * armsAttachedMesh.TypeObject.Rotation; }
private void InitTracksAnimation() { for (int nTrack = 0; nTrack < 2; nTrack++) { Track track = nTrack == 0 ? leftTrack : rightTrack; string alias = nTrack == 0 ? "leftTrackMesh" : "rightTrackMesh"; foreach (MapObjectAttachedObject attachedObject in AttachedObjects) { if (attachedObject.Alias == alias) { MapObjectAttachedMesh attachedMesh = GetFirstAttachedObjectByAlias(alias) as MapObjectAttachedMesh; if (attachedMesh != null) { track.meshObjects.Add(attachedMesh.MeshObject); track.meshObjects[track.meshObjects.Count - 1].AddToRenderQueue += TrackMeshObject_AddToRenderQueue; } } } } }
protected override void OnPostCreate(bool loaded) { base.OnPostCreate(loaded); //get mainMeshObject foreach (MapObjectAttachedObject attachedObject in AttachedObjects) { MapObjectAttachedMesh attachedMeshObject = attachedObject as MapObjectAttachedMesh; if (attachedMeshObject != null) { if (mainMeshObject == null) { mainMeshObject = attachedMeshObject; } } } if (EntitySystemWorld.Instance.WorldSimulationType != WorldSimulationTypes.Editor) { UpdateTPSFPSCameraAttachedObjectsVisibility(false); } SubscribeToTickEvent(); }
protected override void OnPostCreate(bool loaded) { base.OnPostCreate(loaded); //get mainMeshObject foreach (MapObjectAttachedObject attachedObject in AttachedObjects) { MapObjectAttachedMesh attachedMeshObject = attachedObject as MapObjectAttachedMesh; if (attachedMeshObject != null) { if (mainMeshObject == null) { mainMeshObject = attachedMeshObject; } } } if (fpsMeshMaterialNameEnabled && !string.IsNullOrEmpty(Type.FPSMeshMaterialName)) { UpdateMainMeshObjectMaterial(); } AddTimer(); }
private void OnCollision(ref CollisionEvent collisonEvent) { if (collisonEvent.ThisShape.Name == "dmd") { hit_pos = collisonEvent.Position; hit_dep = collisonEvent.Depth; hit_norm = collisonEvent.Normal; hit_this = collisonEvent.ThisShape; hit_other = collisonEvent.OtherShape; } //light crash if (collisonEvent.ThisShape.Name == "flr" || collisonEvent.ThisShape.Name == "fll" || collisonEvent.ThisShape.Name == "blr" || collisonEvent.ThisShape.Name == "bll") { if (collisonEvent.OtherShape.Name != "flr" || collisonEvent.OtherShape.Name != "fll" || collisonEvent.OtherShape.Name != "blr" || collisonEvent.OtherShape.Name != "bll") { MapObjectAttachedMesh obj = GetFirstAttachedObjectByAlias(collisonEvent.ThisShape.Name) as MapObjectAttachedMesh; if (obj != null) { if (obj.TextUserData != "") { obj.TextUserData = (Convert.ToInt32(obj.TextUserData) + 1).ToString(); } else { obj.TextUserData = "1"; } if (Convert.ToInt32(obj.TextUserData) > 20) { Detach(obj); } } } } //glass crash if (collisonEvent.ThisShape.Name == "gforward" || collisonEvent.ThisShape.Name == "gbackward" || collisonEvent.ThisShape.Name == "gleft" || collisonEvent.ThisShape.Name == "gright") { if (collisonEvent.OtherShape.Name != "gforward" || collisonEvent.OtherShape.Name != "gbackward" || collisonEvent.OtherShape.Name != "gleft" || collisonEvent.OtherShape.Name != "gright") { MapObjectAttachedMesh obj = GetFirstAttachedObjectByAlias(collisonEvent.ThisShape.Name) as MapObjectAttachedMesh; if (obj != null) { if (obj.TextUserData != "") { obj.TextUserData = (Convert.ToInt32(obj.TextUserData) + 1).ToString(); } else { obj.TextUserData = "1"; } if (Convert.ToInt32(obj.TextUserData) < 100) { obj.MeshObject.SetMaterialNameForAllSubObjects("glass_crash"); } else { Detach(obj); } } } } }
/// <summary>Overridden from <see cref="Engine.EntitySystem.Entity.OnPostCreate(Boolean)"/>.</summary> protected override void OnPostCreate(bool loaded) { base.OnPostCreate(loaded); AddTimer(); useAttachedMesh = GetAttachedObjectByAlias(Type.UseMeshAlias) as MapObjectAttachedMesh; }
public void CreateGeometry(MapObject parent, FlightModel flightModel) { MapObjectAttachedMesh obj = new MapObjectAttachedMesh(); obj.MeshName = "Models\\DefaultBox\\DefaultBox.mesh"; float mScale = .2f; obj.ScaleOffset = new Vec3(span * mScale, chord * mScale, .1f * mScale) * flightModel.scale; obj.RotationOffset = Mat3.FromRotateByY(MathFunctions.DegToRad(-rotation)).ToQuat() * Mat3.FromRotateByX(MathFunctions.DegToRad(+inc)).ToQuat(); obj.PositionOffset = (position + Vec3.YAxis * flightModel.param.geometry_offset_for_wheels) * flightModel.scale; parent.Attach(obj); }
void CreateProductUnitAttachedMesh() { productUnitAttachedMesh = new MapObjectAttachedMesh(); Attach( productUnitAttachedMesh ); string meshName = null; Vec3 meshOffset = Vec3.Zero; Vec3 meshScale = new Vec3( 1, 1, 1 ); { foreach( MapObjectTypeAttachedObject typeAttachedObject in productUnitType.AttachedObjects ) { MapObjectTypeAttachedMesh typeAttachedMesh = typeAttachedObject as MapObjectTypeAttachedMesh; if( typeAttachedMesh == null ) continue; meshName = typeAttachedMesh.GetMeshNameFullPath(); meshOffset = typeAttachedMesh.Position; meshScale = typeAttachedMesh.Scale; break; } } productUnitAttachedMesh.MeshName = meshName; Vec3 pos = meshOffset; { MapObjectAttachedObject buildPointAttachedHelper = GetFirstAttachedObjectByAlias( "productUnitPoint" ); if( buildPointAttachedHelper != null ) pos += buildPointAttachedHelper.PositionOffset; } productUnitAttachedMesh.PositionOffset = pos; productUnitAttachedMesh.ScaleOffset = meshScale; if( Type.Name == "RTSHeadquaters" ) { foreach( MeshObject.SubObject subMesh in productUnitAttachedMesh.MeshObject.SubObjects ) subMesh.MaterialName = "RTSBuildMaterial"; } }
private void CreateAttachedMesh() { attachedMesh = new MapObjectAttachedMesh(); attachedMesh.MeshName = mesh.Name; Attach(attachedMesh); }
void CreateAttachedMesh() { attachedMesh = new MapObjectAttachedMesh(); attachedMesh.MeshName = mesh.Name; Attach( attachedMesh ); }
void CreateDirectionalDecal(Shape shape, Vec3 pos, Vec3 normal, int triangleID) { bool smallDecal = Type.Size < .3f; Body body = shape.Body; //static objects if (shape.ContactGroup == (int)ContactGroup.Collision) { ShapeTriangleID triangle = new ShapeTriangleID(shape, triangleID); //StaticMesh { StaticMesh staticMesh = StaticMesh.GetStaticMeshByBody(body); if (staticMesh != null) { if (staticMesh.AllowDecals == StaticMesh.DecalTypes.OnlySmall && smallDecal || staticMesh.AllowDecals == StaticMesh.DecalTypes.All) { CreateDecalForStaticObject(triangle, pos, normal, null); return; } } } //HeightmapTerrain if (HeightmapTerrain.GetTerrainByBody(body) != null) { CreateDecalForStaticObject(triangle, pos, normal, null); return; } if (Type.ApplyToMapObjects) { //MapObject: Attached mesh MapObject mapObject = MapSystemWorld.GetMapObjectByBody(body); if (mapObject != null) { bool isCollision = false; foreach (MapObjectAttachedObject attachedObject in mapObject.AttachedObjects) { MapObjectAttachedMesh attachedMesh = attachedObject as MapObjectAttachedMesh; if (attachedMesh != null && attachedMesh.CollisionBody == body) { isCollision = true; break; } } if (isCollision) { CreateDecalForStaticObject(triangle, pos, normal, mapObject); return; } } } } //dynamic objects { //not implemented } }
/// <summary>Overridden from <see cref="Engine.EntitySystem.Entity.OnPostCreate(Boolean)"/>.</summary> protected override void OnPostCreate( bool loaded ) { base.OnPostCreate( loaded ); AddTimer(); useAttachedMesh = GetAttachedObjectByAlias( Type.UseMeshAlias ) as MapObjectAttachedMesh; }
private void UpdateFirstPersonArmsAttachedMesh(MapObjectAttachedMesh armsAttachedMesh, Camera camera) { //update animation tree if (EntitySystemWorld.Instance.Simulation && !EntitySystemWorld.Instance.SystemPauseOfSimulation) { AnimationTree tree = armsAttachedMesh.AnimationTree; if (tree != null) { bool onGround = GetElapsedTimeSinceLastGroundContact() < .2f;//IsOnGround(); bool move = false; float moveSpeed = 0; if (onGround && GroundRelativeVelocitySmooth.ToVec2().Length() > .05f) { move = true; moveSpeed = GroundRelativeVelocitySmooth.ToVec2().Length(); } tree.SetParameterValue("move", move ? 1 : 0); tree.SetParameterValue("run", move && IsNeedRun() ? 1 : 0); tree.SetParameterValue("moveSpeed", moveSpeed); float moveSpeedFactor = moveSpeed / Type.RunForwardMaxSpeed; if (moveSpeedFactor > 1) moveSpeedFactor = 1; tree.SetParameterValue("moveSpeedFactor", moveSpeedFactor); } } //update scene node armsAttachedMesh.SceneNode.Position = camera.Position + camera.Rotation * armsAttachedMesh.TypeObject.Position; armsAttachedMesh.SceneNode.Rotation = camera.Rotation * armsAttachedMesh.TypeObject.Rotation; //use this code to look arms from another point of view. Useful for calibration position of attached weapon. //armsAttachedMesh.SceneNode.Position = new Vec3( 0, 0, 2 ) + Quat.Identity * armsAttachedMesh.TypeObject.Position; //armsAttachedMesh.SceneNode.Rotation = Quat.Identity * armsAttachedMesh.TypeObject.Rotation; }
protected override void CreateBullet(Mode mode) { //only missiles for missilelauncher if (mode.typeMode.BulletType as Missile2Type == null) { return; } Missile2 obj = (Missile2)Entities.Instance.Create(mode.typeMode.BulletType, Parent); obj.SourceUnit = GetParentUnitHavingIntellect(); obj.Position = GetFirePosition(mode.typeMode); //Correcting position at a shot in very near object (when the point of a shot inside object). { Vec3 startPos = Position; if (AttachedMapObjectParent != null) { startPos = AttachedMapObjectParent.Position; } Ray ray = new Ray(startPos, obj.Position - startPos); if (ray.Direction != Vec3.Zero) { RayCastResult[] piercingResult = PhysicsWorld.Instance.RayCastPiercing( ray, (int)ContactGroup.CastOnlyContact); foreach (RayCastResult result in piercingResult) { MapObject mapObject = MapSystemWorld.GetMapObjectByBody(result.Shape.Body); if (mapObject != null) { if (mapObject == this) { continue; } if (mapObject == this.AttachedMapObjectParent) { continue; } } obj.Position = result.Position - ray.Direction * .01f; break; } } } Quat rot = GetFireRotation(mode.typeMode); Radian dispersionAngle = mode.typeMode.DispersionAngle; if (dispersionAngle != 0) { EngineRandom random = World.Instance.Random; float halfDir; halfDir = random.NextFloatCenter() * dispersionAngle * .5f; rot *= new Quat(new Vec3(0, 0, MathFunctions.Sin(halfDir)), MathFunctions.Cos(halfDir)); halfDir = random.NextFloatCenter() * dispersionAngle * .5f; rot *= new Quat(new Vec3(0, MathFunctions.Sin(halfDir), 0), MathFunctions.Cos(halfDir)); halfDir = random.NextFloatCenter() * dispersionAngle * .5f; rot *= new Quat(new Vec3(MathFunctions.Sin(halfDir), 0, 0), MathFunctions.Cos(halfDir)); } obj.Rotation = rot; obj.PostCreate(); //set damage coefficient float coef = obj.DamageCoefficient; Unit unit = GetParentUnitHavingIntellect(); if (unit != null && unit.BigDamageInfluence != null) { coef *= unit.BigDamageInfluence.Type.Coefficient; } obj.DamageCoefficient = coef; foreach (MapObjectAttachedObject attachedObject in AttachedObjects) { MapObjectAttachedMesh attachedMesh = attachedObject as MapObjectAttachedMesh; if (attachedMesh == null) { continue; } if (attachedMesh.Alias.Equals("Missile")) { if (!attachedMesh.Visible) { continue; } else { attachedMesh.Visible = false; break; } } } }
/// <summary>Overridden from <see cref="Engine.MapSystem.MapObject.OnRender(Camera)"/>.</summary> protected override void OnRender(Camera camera) { base.OnRender(camera); //get camera state bool playerIntellectFPSCamera = false; { PlayerIntellect playerIntellect = Intellect as PlayerIntellect; if (playerIntellect != null) { playerIntellectFPSCamera = playerIntellect.FPSCamera; } } bool fpsCamera = playerIntellectFPSCamera && camera.Purpose == Camera.Purposes.MainCamera; bool mainCameraUpdating = SceneManager.Instance.CurrentUpdatingCamera.Purpose == Camera.Purposes.MainCamera; //update first person arms MapObjectAttachedMesh firstPersonArmsAttachedMesh = GetFirstAttachedObjectByAlias("firstPersonArms") as MapObjectAttachedMesh; if (firstPersonArmsAttachedMesh != null) { if (EntitySystemWorld.Instance.WorldSimulationType != WorldSimulationTypes.Editor && fpsCamera) { UpdateFirstPersonArmsAttachedMesh(firstPersonArmsAttachedMesh, camera); } } //update weapon if (activeWeapon != null && GameMap.Instance.GameType != GameMap.GameTypes.TPSArcade && GameMap.Instance.GameType != GameMap.GameTypes.PlatformerDemo) { //update weapon attached objects visibility depending camera type activeWeapon.UpdateTPSFPSCameraAttachedObjectsVisibility(fpsCamera); //update weapon position. Guns only. if (activeWeaponAttachedObject.MapObject is Gun) { //guns if (fpsCamera) { if (firstPersonArmsAttachedMesh != null) { Vec3 p; Quat r; Vec3 s; string slotName = activeWeapon.Type.CharacterBoneSlotFirstPersonCamera; if (!string.IsNullOrEmpty(slotName)) { MapObjectAttachedMesh.MeshBoneSlot slot = GetBoneSlotFromAttachedMeshes(slotName); if (slot != null) { slot.GetGlobalTransform(out p, out r, out s); } else { p = camera.Position; r = camera.Rotation; s = new Vec3(1, 1, 1); } } else { p = camera.Position + camera.Rotation * activeWeapon.Type.FPSCameraAttachPosition; r = camera.Rotation; s = new Vec3(1, 1, 1); } activeWeaponAttachedObject.MapObject.SetTransform(p, r, s); activeWeaponAttachedObject.MapObject.SetOldTransform(p, r, s); } } else { //change active weapon position for non animated characters if (activeWeaponAttachedObject.BoneSlot == null) { Vec3 diff = TurnToPosition - Position; float dirV = -MathFunctions.ATan(diff.Z, diff.ToVec2().Length()); float halfDirV = dirV * .5f; Quat rot = new Quat(0, MathFunctions.Sin(halfDirV), 0, MathFunctions.Cos(halfDirV)); activeWeaponAttachedObject.RotationOffset = rot; activeWeaponAttachedObject.PositionOffset = Type.NotAnimatedWeaponAttachPosition; } } } //no cast shadows from active weapon in the FPS mode foreach (MapObjectAttachedObject weaponAttachedObject in activeWeapon.AttachedObjects) { MapObjectAttachedMesh weaponAttachedMesh = weaponAttachedObject as MapObjectAttachedMesh; if (weaponAttachedMesh != null && weaponAttachedMesh.MeshObject != null) { if (weaponAttachedMesh.RemainingTime == 0) { weaponAttachedMesh.MeshObject.CastShadows = !fpsCamera; } } } } //change visibility of attached objects { foreach (MapObjectAttachedObject attachedObject in AttachedObjects) { if (attachedObject == activeWeaponAttachedObject) { //attached weapon is always visible attachedObject.Visible = true; } else if (attachedObject == firstPersonArmsAttachedMesh) { //first person arms is visible only for first person camera. The weapon is also must be activated. attachedObject.Visible = fpsCamera && activeWeaponAttachedObject != null; } else { //hide attached objects for first person camera attachedObject.Visible = !fpsCamera; } } //hide shadows for first person camera mode if (playerIntellectFPSCamera && mainCameraUpdating && camera.Purpose == Camera.Purposes.ShadowMap) { foreach (MapObjectAttachedObject attachedObject in AttachedObjects) { attachedObject.Visible = false; } } } }
void AttachMesh() { attachedMesh = new MapObjectAttachedMesh(); attachedMesh.CastDynamicShadows = false; attachedMesh.MeshName = mesh.Name; Attach( attachedMesh ); }
protected override void OnPostCreate(bool loaded) { base.OnPostCreate(loaded); current_gears = Type.CONF.SoundGears.Find(delegate(SSDCType.SSDC_CONF.SoundGear gear) { return(gear.Number == 0); }); if (EngineApp.Instance.ApplicationType != EngineApp.ApplicationTypes.ResourceEditor) { if (PhysicsModel == null) { Log.Error("Car: Physics model not exists."); return; } car_body = PhysicsModel.GetBody("chassis"); dmd_shape = car_body.GetShape("dmd"); if (car_body == null) { Log.Error("Car: \"chassis\" body not exists."); return; } if (dmd_shape == null) { Log.Error("Car: \"dmd\" shape not exists."); return; } attached_mesh = GetFirstAttachedObjectByAlias("dmd") as MapObjectAttachedMesh; if (attached_mesh == null) { Log.Error("Car: mesh by \"dmd\" alias not exists."); return; } else { mesh_name = this.Name; attached_mesh.MeshObject.Mesh.Save("Data\\" + mesh_name + ".mesh"); attached_mesh.MeshName = mesh_name + ".mesh"; mesh = attached_mesh.MeshObject.Mesh; if (Type.CONF.RandomMaterials.Any()) { attached_mesh.MeshObject.SetMaterialNameForAllSubObjects(Type.CONF.RandomMaterials[World.Instance.Random.Next(0, Type.CONF.RandomMaterials.Count)].Path); } } if (Type.CONF.Deformation) { ParsingMesh(); } } if (EntitySystemWorld.Instance.WorldSimulationType != WorldSimulationTypes.Editor) { SubscribeToTickEvent(); MapObjectAttachedObject[] ortbrake = GetAllAttachedObjectsByAlias("brake"); for (int i = 0; i < ortbrake.Length; i++) { MapObjectAttachedRibbonTrail rt = ortbrake[i] as MapObjectAttachedRibbonTrail; if (rt != null) { rtbrake.Add(rt.RibbonTrail); } } } if (car_body != null) { car_body.Collision += OnCollision; } }
protected override void OnPostCreate( bool loaded ) { base.OnPostCreate( loaded ); //get mainMeshObject foreach( MapObjectAttachedObject attachedObject in AttachedObjects ) { MapObjectAttachedMesh attachedMeshObject = attachedObject as MapObjectAttachedMesh; if( attachedMeshObject != null ) { if( mainMeshObject == null ) mainMeshObject = attachedMeshObject; } } if( fpsMeshMaterialNameEnabled && !string.IsNullOrEmpty( Type.FPSMeshMaterialName ) ) UpdateMainMeshObjectMaterial(); AddTimer(); }
protected override void OnPostCreate( bool loaded ) { base.OnPostCreate( loaded ); //get mainMeshObject foreach( MapObjectAttachedObject attachedObject in AttachedObjects ) { MapObjectAttachedMesh attachedMeshObject = attachedObject as MapObjectAttachedMesh; if( attachedMeshObject != null ) { if( mainMeshObject == null ) mainMeshObject = attachedMeshObject; } } if( EntitySystemWorld.Instance.WorldSimulationType != WorldSimulationTypes.Editor ) UpdateTPSFPSCameraAttachedObjectsVisibility( false ); SubscribeToTickEvent(); }
private static Sphere GetSwitchUseAttachedMeshWorldSphere(MapObjectAttachedMesh attachedMesh) { float radius = 0; Bounds meshBounds = attachedMesh.MeshObject.Mesh.Bounds; Vec3[] points = null; meshBounds.ToPoints(ref points); foreach (Vec3 point in points) { Vec3 p = point * (attachedMesh.SceneNode.Scale * .5f); float length = p.Length(); if (length > radius) radius = length; } return new Sphere(attachedMesh.SceneNode.GetWorldBounds().GetCenter(), radius); }
void DestroyAttachedMesh() { if( attachedMesh != null ) { Detach( attachedMesh ); attachedMesh = null; } }
/// <summary>Overridden from <see cref="Engine.EntitySystem.Entity.OnPostCreate(Boolean)"/>.</summary> protected override void OnPostCreate( bool loaded ) { base.OnPostCreate( loaded ); SubscribeToTickEvent(); useAttachedMesh = GetFirstAttachedObjectByAlias( Type.UseMeshAlias ) as MapObjectAttachedMesh; }
/// <summary>Overridden from <see cref="Engine.MapSystem.MapObject.OnRender(Camera)"/>.</summary> protected override void OnRender(Camera camera) { base.OnRender(camera); //no update in cubemap generation mode if (Map.Instance.CubemapGenerationMode) { return; } bool playerIntellectFPSCamera = false; { PlayerIntellect playerIntellect = Intellect as PlayerIntellect; if (playerIntellect != null) { playerIntellectFPSCamera = playerIntellect.FPSCamera; } } bool fpsCamera = playerIntellectFPSCamera && RendererWorld.Instance.DefaultCamera == camera; if (activeWeapon != null && GameMap.Instance.GameType != GameMap.GameTypes.TPSArcade) { //FPS mesh material activeWeapon.FPSMeshMaterialNameEnabled = fpsCamera && !camera.IsForShadowMapGeneration(); //update weapon vertical orientation if (activeWeaponAttachedObject.MapObject is Gun) { //for guns if (fpsCamera) { Vec3 p = camera.Position + camera.Rotation * Type.WeaponFPSAttachPosition; Quat r = camera.Rotation; Vec3 s = new Vec3(1, 1, 1); activeWeaponAttachedObject.MapObject.SetTransform(p, r, s); activeWeaponAttachedObject.MapObject.SetOldTransform(p, r, s); //Vec3 diff = playerIntellect.LookDirection.GetVector(); //float dirV = -MathFunctions.ATan( diff.Z, diff.ToVec2().Length() ); //float halfDirV = dirV * .5f; //Quat rot = new Quat( 0, MathFunctions.Sin( halfDirV ), 0, // MathFunctions.Cos( halfDirV ) ); //activeWeaponAttachedObject.RotationOffset = rot; //activeWeaponAttachedObject.PositionOffset = // Type.FPSCameraOffset + Type.WeaponFPSAttachPosition * rot; } else { float dirV; if (EntitySystemWorld.Instance.IsClientOnly()) { //client specific dirV = client_weaponVerticalAngle; } else { Vec3 diff = TurnToPosition - Position; dirV = -MathFunctions.ATan(diff.Z, diff.ToVec2().Length()); } float halfDirV = dirV * .5f; Quat rot = new Quat(0, MathFunctions.Sin(halfDirV), 0, MathFunctions.Cos(halfDirV)); activeWeaponAttachedObject.RotationOffset = rot; activeWeaponAttachedObject.PositionOffset = Type.WeaponAttachPosition; } } else { //for melee weapons activeWeaponAttachedObject.RotationOffset = Quat.Identity; activeWeaponAttachedObject.PositionOffset = Vec3.Zero; } //no cast shadows from active weapon in the FPS mode foreach (MapObjectAttachedObject weaponAttachedObject in activeWeapon.AttachedObjects) { MapObjectAttachedMesh weaponAttachedMesh = weaponAttachedObject as MapObjectAttachedMesh; if (weaponAttachedMesh != null && weaponAttachedMesh.MeshObject != null) { if (weaponAttachedMesh.RemainingTime == 0) { weaponAttachedMesh.MeshObject.CastShadows = !fpsCamera; } } } } //only weapon visible in the FPS mode foreach (MapObjectAttachedObject attachedObject in AttachedObjects) { attachedObject.Visible = !fpsCamera || attachedObject == activeWeaponAttachedObject; } //no cast shadows in the FPS mode if (camera.IsForShadowMapGeneration() && playerIntellectFPSCamera) { foreach (MapObjectAttachedObject attachedObject in AttachedObjects) { attachedObject.Visible = false; } } }
/// <summary>Overridden from <see cref="Engine.EntitySystem.Entity.OnPostCreate(Boolean)"/>.</summary> protected override void OnPostCreate(bool loaded) { base.OnPostCreate(loaded); SubscribeToTickEvent(); useAttachedMesh = GetFirstAttachedObjectByAlias(Type.UseMeshAlias) as MapObjectAttachedMesh; }
void DestroyProductUnitAttachedMesh() { if( productUnitAttachedMesh != null ) { Detach( productUnitAttachedMesh ); productUnitAttachedMesh = null; } }