private void PrintBoneAngles() { var chain = chainManager.GetChain(); var baseBone = chain.GetBone(0); var baseDir = baseBone.Direction; //Debug.Log(baseDir); Debug.DrawLine(baseBone.Tip.Position, baseBone.Tip.Position + baseDir, Color.red, 10000); for (int i = 1; i < chain.BoneCount; i++) { var nextBone = chain.GetBone(i); var nextDir = nextBone.Direction; //Debug.Log(nextDir); Quaternion relativeRot = Quaternion.FromToRotation(baseBone.Direction, nextBone.Direction); float angle; Vector3 axis; relativeRot.ToAngleAxis(out angle, out axis); Debug.Log("axis: " + axis + " angle: " + angle); angle = Vector3.Angle(baseDir, nextDir); Debug.Log(angle); Debug.DrawLine(nextBone.Base.Position, nextBone.Base.Position + nextDir, Color.red, 10000); baseDir = nextDir; } }
async Task OnBlockData(NodeBlockDataMessage message, NodeConnection connection) { var chainType = message.ChainType; var blockId = message.BlockId; var chainId = message.ChainId; var chainIndex = message.ChainIndex; var chain = _chainManager.GetChain(chainType, chainId, chainIndex); if (chain == null || blockId <= chain.BlockStorage.LastStoredBlockId) { return; } if (message.BlockData != null) { await _node.SyncManager.HandleBlockData(message.BlockData, new HashSet <NodeConnection> { connection }); } else { if (connection.NodeInfo.IsPublicEndPoint || connection.AutoConnect != null) { var client = new NodeClient(connection.NodeInfo.IsPublicEndPoint ? connection.NodeInfo.PublicEndPoint : connection.AutoConnect.EndPoint); var blockData = (await client.DownloadBlockData(chainType, chainId, chainIndex, blockId)).Data; if (blockData != null) { await _node.SyncManager.HandleBlockData(blockData, new HashSet <NodeConnection> { connection }); return; } } _ = connection.Send(new NodeBlockDataRequestMessage(chainType, blockId, chain.ChainId, chainIndex) { SignKey = _node.NodeConfiguration.LocaleNodePrivateKey }); } }
private void Update() { if (Input.GetKeyDown(KeyCode.Space)) { show = !show; } if (Input.GetKeyDown(KeyCode.I)) { // Apply IK Chain c = visualizer.GetChain(); c.GetBone(1).Move(new Vector3(1, 0, 0)); visualizer.SetChain(c); } if (Input.GetKeyDown(KeyCode.Alpha1)) { Chain c = visualizer.GetChain(); c.AttachBoneToParent(1); visualizer.SetChain(c); } if (Input.GetKeyDown(KeyCode.Alpha2)) { Chain c = visualizer.GetChain(); c.AttachBoneToParent(1, false); visualizer.SetChain(c); } if (Input.GetKeyDown(KeyCode.Alpha3)) { Chain c = visualizer.GetChain(); c.AttachBoneToChild(0); visualizer.SetChain(c); } if (Input.GetKeyDown(KeyCode.Alpha4)) { Chain c = visualizer.GetChain(); c.AttachBoneToChild(0, false); visualizer.SetChain(c); } if (Input.GetKeyDown(KeyCode.F)) { if (target == null) { return; } Chain c = visualizer.GetChain(); Chain_FABRIK.Solve(c, target); visualizer.SetChain(c); } if (Input.GetKeyDown(KeyCode.A)) { applyTransforms = !applyTransforms; } if (show) { visualizer.Show(); } else { visualizer.Hide(); } }