public AttachmentPointNode GetHeldAttachmentPointNode(AttachmentNode attachmentNode) { //Debug.Log(gameObject.name + ".CharacterEquipmentManager.GetHeldAttachmentPointNode()"); if (attachmentNode.UseUniversalAttachment == false) { AttachmentPointNode attachmentPointNode = new AttachmentPointNode(); attachmentPointNode.TargetBone = attachmentNode.HoldableObject.TargetBone; attachmentPointNode.Position = attachmentNode.HoldableObject.Position; attachmentPointNode.Rotation = attachmentNode.HoldableObject.Rotation; attachmentPointNode.RotationIsGlobal = attachmentNode.HoldableObject.RotationIsGlobal; return(attachmentPointNode); } else { // find unit profile, find prefab profile, find universal attachment profile, find universal attachment node if (unitController?.CharacterUnit?.BaseCharacter?.UnitProfile?.UnitPrefabProps?.AttachmentProfile != null) { if (unitController.CharacterUnit.BaseCharacter.UnitProfile.UnitPrefabProps.AttachmentProfile.AttachmentPointDictionary.ContainsKey(attachmentNode.UnsheathedAttachmentName)) { return(unitController.CharacterUnit.BaseCharacter.UnitProfile.UnitPrefabProps.AttachmentProfile.AttachmentPointDictionary[attachmentNode.UnsheathedAttachmentName]); } } } return(null); }
public void SheathObject(GameObject go, AttachmentNode attachmentNode, GameObject searchObject) { if (searchObject == null) { //Debug.Log(gameObject + ".CharacterEquipmentManager.SheathObject(): searchObject is null"); return; } if (attachmentNode == null || attachmentNode.HoldableObject == null) { //Debug.Log(gameObject + ".CharacterEquipmentManager.SheathObject(): MyHoldableObjectName is empty"); return; } if (go == null) { //Debug.Log(gameObject + ".CharacterEquipmentManager.SheathObject(): gameObject is null is null"); return; } AttachmentPointNode attachmentPointNode = GetSheathedAttachmentPointNode(attachmentNode); if (attachmentPointNode != null) { Transform targetBone = searchObject.transform.FindChildByRecursive(attachmentPointNode.TargetBone); if (targetBone != null) { //Debug.Log(gameObject + ".CharacterEquipmentManager.SheathObject(): targetBone is NOT null: " + holdableObject.MySheathedTargetBone); go.transform.parent = targetBone; go.transform.localPosition = attachmentPointNode.Position; go.transform.localEulerAngles = attachmentPointNode.Rotation; } else { //Debug.Log(gameObject + ".CharacterEquipmentManager.SheathObject(): targetBone is null: " + holdableObject.MySheathedTargetBone); } } }
public void HoldObject(GameObject go, AttachmentNode attachmentNode, GameObject searchObject) { //public void HoldObject(GameObject go, PrefabProfile holdableObject, GameObject searchObject) { //Debug.Log(gameObject + ".CharacterEquipmentManager.HoldObject(" + go.name + ", " + holdableObjectName + ", " + searchObject.name + ")"); if (attachmentNode == null || attachmentNode.HoldableObject == null || go == null || searchObject == null) { //Debug.Log(gameObject + ".CharacterEquipmentManager.HoldObject(): MyHoldableObjectName is empty"); return; } AttachmentPointNode attachmentPointNode = GetHeldAttachmentPointNode(attachmentNode); if (attachmentPointNode != null && attachmentPointNode.TargetBone != null && attachmentPointNode.TargetBone != string.Empty) { Transform targetBone = searchObject.transform.FindChildByRecursive(attachmentPointNode.TargetBone); if (targetBone != null) { //Debug.Log(gameObject + ".CharacterEquipmentManager.HoldObject(): targetBone: " + targetBone + "; position: " + holdableObject.MyPosition + "; holdableObject.MyPhysicalRotation: " + holdableObject.MyRotation); go.transform.parent = targetBone; go.transform.localPosition = attachmentPointNode.Position; if (attachmentPointNode.RotationIsGlobal) { go.transform.rotation = Quaternion.LookRotation(targetBone.transform.forward) * Quaternion.Euler(attachmentPointNode.Rotation); } else { go.transform.localEulerAngles = attachmentPointNode.Rotation; } } else { Debug.Log("CharacterEquipmentManager.HoldObject(): Unable to find target bone : " + attachmentPointNode.TargetBone); } } else { // disabled message because some equipment (like quivers) does not have held attachment points intentionally because it should stay in the same place in combat //Debug.Log(gameObject + ".CharacterEquipmentManager.HoldObject(): Unable to get attachment point " + attachmentNode.UnsheathedAttachmentName); } }
public AttachmentPointNode GetSheathedAttachmentPointNode(AttachmentNode attachmentNode) { if (attachmentNode.UseUniversalAttachment == false) { AttachmentPointNode attachmentPointNode = new AttachmentPointNode(); attachmentPointNode.TargetBone = attachmentNode.HoldableObject.SheathedTargetBone; attachmentPointNode.Position = attachmentNode.HoldableObject.SheathedPosition; attachmentPointNode.Rotation = attachmentNode.HoldableObject.SheathedRotation; return(attachmentPointNode); } else { // find unit profile, find prefab profile, find universal attachment profile, find universal attachment node if (unitController?.CharacterUnit?.BaseCharacter?.UnitProfile?.UnitPrefabProps?.AttachmentProfile != null) { if (unitController.CharacterUnit.BaseCharacter.UnitProfile.UnitPrefabProps.AttachmentProfile.AttachmentPointDictionary.ContainsKey(attachmentNode.PrimaryAttachmentName)) { return(unitController.CharacterUnit.BaseCharacter.UnitProfile.UnitPrefabProps.AttachmentProfile.AttachmentPointDictionary[attachmentNode.PrimaryAttachmentName]); } } else if (attachmentProfile != null) { if (attachmentProfile.AttachmentPointDictionary.ContainsKey(attachmentNode.PrimaryAttachmentName)) { return(attachmentProfile.AttachmentPointDictionary[attachmentNode.PrimaryAttachmentName]); } } else { // enable for troubleshooting only. It gets spammy with beast units that don't have attachments. //Debug.Log(gameObject.name + ".CharacterEquipmentManager.GetSheathedAttachmentPointNode(): could not get attachment profile from prefabprofile"); } } // enable for troubleshooting only. It gets spammy with beast units that don't have attachments. //Debug.Log("CharacterEquipmentManager.GetSheathedAttachmentPointNode(): Unable to return attachment point node!"); return(null); }
public void SpawnEquipmentObjects(EquipmentSlotProfile equipmentSlotProfile, Equipment newEquipment) { //Debug.Log(unitController.gameObject.name + ".MecanimModelController.SpawnEquipmentObjects()"); if (newEquipment == null || newEquipment.HoldableObjectList == null || newEquipment.HoldableObjectList.Count == 0 || equipmentSlotProfile == null) { //Debug.Log("CharacterEquipmentManager.SpawnEquipmentObjects() : FAILED TO SPAWN OBJECTS"); return; } //Dictionary<PrefabProfile, GameObject> holdableObjects = new Dictionary<PrefabProfile, GameObject>(); Dictionary <AttachmentNode, GameObject> holdableObjects = new Dictionary <AttachmentNode, GameObject>(); foreach (HoldableObjectAttachment holdableObjectAttachment in newEquipment.HoldableObjectList) { if (holdableObjectAttachment != null && holdableObjectAttachment.MyAttachmentNodes != null) { foreach (AttachmentNode attachmentNode in holdableObjectAttachment.MyAttachmentNodes) { if (attachmentNode != null && attachmentNode.MyEquipmentSlotProfile != null && equipmentSlotProfile == attachmentNode.MyEquipmentSlotProfile) { //CreateComponentReferences(); if (attachmentNode.HoldableObject != null && attachmentNode.HoldableObject.Prefab != null) { //Debug.Log("EquipmentManager.HandleWeaponSlot(): " + newItem.name + " has a physical prefab"); // attach a mesh to a bone for weapons AttachmentPointNode attachmentPointNode = GetSheathedAttachmentPointNode(attachmentNode); if (attachmentPointNode != null) { Transform targetBone = unitController.gameObject.transform.FindChildByRecursive(attachmentPointNode.TargetBone); if (targetBone != null) { //Debug.Log(unitController.gameObject.name + ".MecanimModelController.SpawnEquipmentObjects(): " + newEquipment.name + " has a physical prefab. targetbone is not null: equipSlot: " + newEquipment.EquipmentSlotType.DisplayName); GameObject newEquipmentPrefab = objectPooler.GetPooledObject(attachmentNode.HoldableObject.Prefab, targetBone); //holdableObjects.Add(attachmentNode.MyHoldableObject, newEquipmentPrefab); holdableObjects.Add(attachmentNode, newEquipmentPrefab); //currentEquipmentPhysicalObjects[equipmentSlotProfile] = newEquipmentPrefab; newEquipmentPrefab.transform.localScale = attachmentNode.HoldableObject.Scale; if (unitController?.CharacterUnit?.BaseCharacter.CharacterCombat != null && unitController?.CharacterUnit?.BaseCharacter.CharacterCombat.GetInCombat() == true) { HoldObject(newEquipmentPrefab, attachmentNode, unitController.gameObject); } else { SheathObject(newEquipmentPrefab, attachmentNode, unitController.gameObject); } } else { Debug.Log("CharacterEquipmentManager.SpawnEquipmentObjects(). We could not find the target bone " + attachmentPointNode.TargetBone + " when trying to Equip " + newEquipment.DisplayName); } } } } } } } if (holdableObjects.Count > 0) { currentEquipmentPhysicalObjects[equipmentSlotProfile] = holdableObjects; } }
public void ProcessArgs( string[] args ) { for( int i = 0; i < args.Length; ++i ) { switch( args[ i ] ) { case "--transform": for( int j = 0; j < 16; ++j ) if( i + 1 < args.Length ) transform[ j ] = float.Parse( args[ ++i ] ); else Console.WriteLine( "Invalid transform" ); break; case "--build_skeleton": build_skeleton = true; break; case "--base_skeleton": // This is overloaded. It is used for adding multiple animations // into a single skeleton, but it is also used to specify the name // of the skeleton that will be referenced by the mesh file. skeleton_file = args[ ++i ]; break; case "--build_tangents": build_tangents = true; break; case "--out_skeleton": out_skeleton_file = args[ ++i ]; break; case "--optimize_mesh": case "--optimise_mesh": optimize_mesh = true; break; case "--animation": { AnimationEntry entry = new AnimationEntry(); entry.animation_name = args[ ++i ]; entry.animation_file = args[ ++i ]; animations.Add( entry ); break; } case "--manual_lod": { LodEntry entry = new LodEntry(); entry.distance = float.Parse( args[ ++i ] ); entry.meshFile = args[ ++i ]; manualLodEntries.Add( entry ); break; } case "--socket": { Matrix4 attachTransform = Matrix4.Identity; string name = args[ ++i ]; string parentBone = args[ ++i ]; for( int j = 0; j < 16; ++j ) if( i + 1 < args.Length ) attachTransform[ j ] = float.Parse( args[ ++i ] ); else Console.WriteLine( "Invalid transform" ); AttachmentPointNode ap = new AttachmentPointNode( name, parentBone, attachTransform ); attachPoints.Add( ap ); break; } case "--test_physics": { test_physics = true; return; } // LOD options case "--lod_levels": { lodlevels = int.Parse( args[ ++i ] ); break; } case "--lod_distance": { loddist = float.Parse( args[ ++i ] ); break; } case "--lod_percent": { lodpercent = float.Parse( args[ ++i ] ); break; } case "--lod_num_triangles": { // lodnumtris break; } #if NOT_USED case "--merge_animations": { // Deprecated string destFile = args[++i]; string rigFile = args[++i]; List<string> animFiles = new List<string>(); while (i + 1 < args.Length) animFiles.Add(args[++i]); MergeAnimations(srcDir, dstDir, destFile, rigFile, animFiles); return; } case "--merge_collada": { // Deprecated string destFile = args[++i]; string rigFile = args[++i]; string animFile = args[++i]; MergeColladaFiles(srcDir, dstDir, destFile, rigFile, animFile); return; } #endif case "--3ds": { // Convert from a right handed system where z is up to a right handed system where y is up. Matrix4 yupTrans = new Matrix4( 1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1 ); transform = transform * yupTrans; break; } case "--src_dir": srcDir = MaybeAddTrailingBackslash( args[ ++i ] ); break; case "--dst_dir": dstDir = MaybeAddTrailingBackslash( args[ ++i ] ); break; #if NOT_USED case "--test_sockets": TestSockets(); break; #endif case "--dont_extract_collision_volumes": extract_collision_volumes = false; break; case "--log_collision_volumes": CVExtractor.InitLog( true ); break; case "--args_file": ProcessArgumentFile( args[ ++i ] ); break; case "--log_file": log_file = args[ ++i ]; break; case "--throw": rethrow = true; break; case "--version": Console.WriteLine( string.Format( "ConversionTool version: {0}", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString() ) ); break; case "--no_rigging_culling": ColladaMeshReader.NoRiggingCulling = true; break; case "--": case "--usage": case "--help": Convert.Usage(); abort = true; break; default: last_arg = args[ i ]; break; } if( abort ) break; } }
/// <summary> /// Set up the attachment point in the skeleton or mesh based on the /// information in the attachPoint. /// </summary> /// <param name="transform">the world transform to apply to this object</param> /// <param name="attachPoint">the AttachmentPointNode with information about parent bone, and the relative transform</param> /// <param name="skeleton">the skeleton for whcih we may create the attachment (if there is a parent bone)</param> /// <param name="mesh">the mesh for which we may create the attachment point (if there is no parent bone)</param> protected void ProcessAttachmentPointNode( Matrix4 transform, AttachmentPointNode attachPoint, Skeleton skeleton, Mesh mesh ) { string parentName = attachPoint.ParentBone; Bone parentBone = null; if( parentName != null ) parentBone = skeleton.GetBone( parentName ); Matrix4 attachPointTransform = attachPoint.Transform; if( parentBone == null ) { // The parent bone will already have the transform in the hierarchy attachPointTransform = transform * attachPointTransform; } Quaternion orientation = MathHelpers.GetRotation( attachPointTransform ); Vector3 position = m_UnitConversion * attachPointTransform.Translation; if( parentBone != null ) skeleton.CreateAttachmentPoint( attachPoint.Name, parentBone.Handle, orientation, position ); else mesh.CreateAttachmentPoint( attachPoint.Name, orientation, position ); m_Log.InfoFormat( "Created attachment point: {0}", attachPoint.Name ); m_Log.InfoFormat( "Parent Bone: {0}", parentName ); m_Log.InfoFormat( "Orientation: {0}", orientation ); m_Log.InfoFormat( "Position: {0}", position ); }