private void AddHumanCurve(GameObject gObject, RigController controller) { RigGoalController goalController = controller.RootObject.GetComponent <RigGoalController>(); RigGoalController[] controllers = goalController.GetComponentsInChildren <RigGoalController>(); foreach (RigGoalController ctrl in controllers) { AddGoalCurve(ctrl, controller); } }
public PoseManipulation(Transform objectTransform, RigController controller, Transform mouthpiece, RotationAxis axis) { MeshController = controller; oTransform = objectTransform; poseMode = AnimationTool.PoseEditMode.AC; switch (axis) { case RotationAxis.X: acAxis = oTransform.right; initForward = oTransform.up; break; case RotationAxis.Y: acAxis = oTransform.up; initForward = oTransform.forward; break; case RotationAxis.Z: acAxis = oTransform.forward; initForward = oTransform.right; break; } previousAngle = Vector3.SignedAngle(initForward, mouthpiece.position - objectTransform.position, acAxis); movedObjects = new List <GameObject>() { oTransform.gameObject }; startPositions = new List <Vector3>() { oTransform.localPosition }; endPositions = new List <Vector3>() { oTransform.localPosition }; startRotations = new List <Quaternion>() { oTransform.localRotation }; endRotations = new List <Quaternion>() { oTransform.localRotation }; startScales = new List <Vector3>() { oTransform.localScale }; endScales = new List <Vector3>() { oTransform.localScale }; }
public void GenerateGoalController(RigController rootController, Transform transform, List <Transform> path) { string boneName = transform.name; if (boneName.Contains("mixamorig:")) { boneName = boneName.Split(':')[1]; } Joint joint = JointsList.Find(x => x.Name == boneName); if (null != joint) { SphereCollider collider = transform.gameObject.AddComponent <SphereCollider>(); collider.isTrigger = true; RigGoalController controller = transform.gameObject.AddComponent <RigGoalController>(); controller.SetPathToRoot(rootController, path); controller.IsGoal = joint.isGoal; controller.stiffness = joint.stiffness; controller.ShowCurve = joint.showCurve; controller.LowerAngleBound = joint.LowerAngleBound; controller.UpperAngleBound = joint.UpperAngleBound; if (joint.isGoal) { controller.gameObject.layer = 21; controller.goalCollider = collider; controller.tag = "Goal"; if (!transform.TryGetComponent <MeshFilter>(out MeshFilter filter)) { filter = transform.gameObject.AddComponent <MeshFilter>(); } filter.mesh = mesh; if (!transform.TryGetComponent(out MeshRenderer renderer)) { renderer = transform.gameObject.AddComponent <MeshRenderer>(); } renderer.material = new Material(material); controller.MeshRenderer = renderer; controller.UseGoal(false); } } path.Add(transform); foreach (Transform child in transform) { GenerateGoalController(rootController, child, new List <Transform>(path)); } }
public void SetPathToRoot(RigController controller, List <Transform> path) { path.ForEach(x => { AnimationSet anim = GlobalState.Animation.GetObjectAnimation(x.gameObject); PathToRoot.Add(x); AnimToRoot.Add(anim); }); if (PathToRoot.Count == 0) { PathToRoot.Add(transform); } Animation = GlobalState.Animation.GetObjectAnimation(this.gameObject); RootController = controller; }
public PoseManipulation(Transform objectTransform, List <Transform> objectHierarchy, Transform mouthpiece, RigController skinController, AnimationTool.PoseEditMode mode) { MeshController = skinController; poseMode = mode; oTransform = objectTransform; fullHierarchy = new List <Transform>(objectHierarchy); if (!fullHierarchy.Contains(objectTransform)) { fullHierarchy.Add(objectTransform); } hierarchySize = fullHierarchy.Count; InitialTRS = Matrix4x4.TRS(oTransform.localPosition, oTransform.localRotation, oTransform.localScale); initialMouthMatrix = mouthpiece.worldToLocalMatrix; InitialParentMatrix = oTransform.parent.localToWorldMatrix; InitialParentMatrixWorldToLocal = oTransform.parent.worldToLocalMatrix; InitialTRS = Matrix4x4.TRS(oTransform.localPosition, oTransform.localRotation, oTransform.localScale); initialTransformMatrix = oTransform.localToWorldMatrix; rootScale = skinController.transform.localScale.x; controllers = new List <RigGoalController>(); for (int i = 0; i < hierarchySize; i++) { controllers.Add(fullHierarchy[i].GetComponent <RigGoalController>()); } if (mode == AnimationTool.PoseEditMode.FK || fullHierarchy.Count == 1) { movedObjects = new List <GameObject>() { oTransform.gameObject }; startPositions = new List <Vector3>() { oTransform.localPosition }; endPositions = new List <Vector3>() { oTransform.localPosition }; startRotations = new List <Quaternion>() { oTransform.localRotation }; endRotations = new List <Quaternion>() { oTransform.localRotation }; startScales = new List <Vector3> { oTransform.localScale }; endScales = new List <Vector3> { oTransform.localScale }; fromRotation = Quaternion.FromToRotation(Vector3.forward, oTransform.localPosition) * Vector3.forward; if (hierarchySize > 2) { initialRotation = fullHierarchy[hierarchySize - 2].localRotation; movedObjects.Add(fullHierarchy[hierarchySize - 2].gameObject); startPositions.Add(fullHierarchy[hierarchySize - 2].localPosition); endPositions.Add(fullHierarchy[hierarchySize - 2].localPosition); startRotations.Add(fullHierarchy[hierarchySize - 2].localRotation); endRotations.Add(fullHierarchy[hierarchySize - 2].localRotation); startScales.Add(fullHierarchy[hierarchySize - 2].localScale); endScales.Add(fullHierarchy[hierarchySize - 2].localScale); } } else { movedObjects = new List <GameObject>(); startPositions = new List <Vector3>(); endPositions = new List <Vector3>(); startRotations = new List <Quaternion>(); endRotations = new List <Quaternion>(); startScales = new List <Vector3>(); endScales = new List <Vector3>(); fullHierarchy.ForEach(x => { movedObjects.Add(x.gameObject); startPositions.Add(x.localPosition); endPositions.Add(x.localPosition); startRotations.Add(x.localRotation); endRotations.Add(x.localRotation); startScales.Add(x.localScale); endScales.Add(x.localScale); }); } }
private void AddGoalCurve(RigGoalController goalController, RigController skinController) { if (!goalController.ShowCurve) { return; } AnimationSet goalAnimation = GlobalState.Animation.GetObjectAnimation(goalController.gameObject); if (null == goalAnimation) { return; } Curve rotationX = goalAnimation.GetCurve(AnimatableProperty.RotationX); if (rotationX.keys.Count == 0) { return; } int frameStart = Mathf.Clamp(rotationX.keys[0].frame, GlobalState.Animation.StartFrame, GlobalState.Animation.EndFrame); int frameEnd = Mathf.Clamp(rotationX.keys[rotationX.keys.Count - 1].frame, GlobalState.Animation.StartFrame, GlobalState.Animation.EndFrame); List <Vector3> positions = new List <Vector3>(); GameObject curve3D = curves.TryGetValue(goalController.gameObject, out GameObject current) ? current : Instantiate(curvePrefab, curvesParent); Vector3 forwardOffset = (skinController.transform.forward * skinController.transform.localScale.x) * currentCurveOffset; goalController.CheckAnimations(); for (int i = frameStart; i <= frameEnd; i++) { Vector3 position = curve3D.transform.InverseTransformDirection(goalController.FramePosition(i) - (forwardOffset * i)); positions.Add(position); } LineRenderer line = curve3D.GetComponent <LineRenderer>(); line.positionCount = positions.Count; line.SetPositions(positions.ToArray()); line.startWidth = lineWidth / GlobalState.WorldScale; line.endWidth = line.startWidth; curve3D.transform.position = forwardOffset * GlobalState.Animation.CurrentFrame; MeshCollider collider = curve3D.GetComponent <MeshCollider>(); Mesh lineMesh = new Mesh(); line.BakeMesh(lineMesh); collider.sharedMesh = lineMesh; curves[goalController.gameObject] = curve3D; if (goalCurves.ContainsKey(skinController)) { goalCurves[skinController].Add(curve3D); } else { goalCurves[skinController] = new List <GameObject>(); goalCurves[skinController].Add(curve3D); } }
public void GenerateImportSkeleton(Transform root, RigController rootController) { importer.GenerateSkeleton(root, rootController); }
public void GenerateSkeleton(Transform root, RigController rootController) { rigConfiguration.GenerateGoalController(rootController, root, new List <Transform>()); }
private IEnumerator ImportScene(string fileName, Transform root = null) { if (blocking) { ImportMaterials().MoveNext(); } else { yield return(StartCoroutine(ImportMaterials())); } if (blocking) { ImportMeshes().MoveNext(); } else { yield return(StartCoroutine(ImportMeshes())); } GameObject objectRoot = root.gameObject; objectRoot = new GameObject(); // Right handed to Left Handed objectRoot.name = Utils.CreateUniqueName(Path.GetFileNameWithoutExtension(fileName)); objectRoot.transform.parent = root; objectRoot.transform.localPosition = Vector3.zero; if (!isHuman) { objectRoot.transform.localScale = new Vector3(-1, 1, 1); objectRoot.transform.localRotation = Quaternion.Euler(0, 180, 0); } importCount = 1; if (blocking) { ImportHierarchy(scene.RootNode, root, objectRoot, Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3.one), Quaternion.identity).MoveNext(); } else { yield return(StartCoroutine(ImportHierarchy(scene.RootNode, root, objectRoot, Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3.one), Quaternion.identity))); } //if (blocking) // ImportHierarchy(scene.RootNode, root, objectRoot).MoveNext(); //else // yield return StartCoroutine(ImportHierarchy(scene.RootNode, root, objectRoot)); if (null == rootBone) { foreach (Transform child in objectRoot.transform) { if (child.childCount > 0) { rootBone = child; } } } foreach (KeyValuePair <Assimp.Node, GameObject> pair in delayedMesh) { AssignSkinnedMeshes(pair.Key, pair.Value); } if (isHuman) { objectRoot.tag = "PhysicObject"; BoxCollider objectCollider = objectRoot.AddComponent <BoxCollider>(); objectCollider.center = meshCenter; objectCollider.size = meshSize; bodyMesh.updateWhenOffscreen = true; RigController skinMesh = objectRoot.AddComponent <RigController>(); skinMesh.SkinMesh = bodyMesh; skinMesh.Collider = objectCollider; skinMesh.RootObject = rootBone; GenerateSkeleton(rootBone, skinMesh); } }