public void SaveAnimationClipFromPath(MWB_Path path, string filePath)
    {
        var world = path.SourceDummyObject.correspondingDummyList;
        var clip  = MWBDummyClipUtility.GenerateClipFromDummyList(world);

        ClipExportUtility.ExportAnimationClip(clip, filePath);
    }
Пример #2
0
    public void InitializeRootPath()
    {
        MWB_PathFactory Factory = MWB_PathFactory.Instance;

        RootPath = CurrentMainPath = Factory.GetPath();
        //selectablePaths.Add(RootPath);
    }
Пример #3
0
    private MWB_Path createNewPath()
    {
        var path = new MWB_Path(); //Instantiate(PathInstance, Vector3.zero, Quaternion.identity, this.transform);

        path.Init();
        m_PathsPool.Add(path);
        return(path);
    }
Пример #4
0
    public void Init()
    {
        OnSelect += () =>
        {
            //Debug.Log(name + " OnSelect , selectablePaths.Count = " + selectablePaths.Count);
            //MWB_SelectionQuery.Instance.CleanRegisteredPaths();
            //MWB_SelectionQuery.Instance.RegisterPaths(selectablePaths);

            List <MWB_SelectablePath> previousSelectedPaths = MWB_SelectionQuery.Instance.SelectedPaths;
            // valid world
            List <MWB_DummyObjectList> previousSelectedWorlds = new List <MWB_DummyObjectList>();

            foreach (MWB_SelectablePath previousSelectedPath in previousSelectedPaths)
            {
                MWB_Path            t_previousSelectedPath = previousSelectedPath as MWB_Path;
                MWB_DummyObjectList t_world = t_previousSelectedPath.SourceDummyObject.correspondingDummyList;

                previousSelectedWorlds.Add(t_world);
            }

            List <MWB_SelectablePath> newSelectedPaths = new List <MWB_SelectablePath>();
            foreach (MWB_SelectablePath selectablePath in selectablePaths)
            {
                MWB_Path t_selectablePath = selectablePath as MWB_Path;

                if (t_selectablePath.SourceDummyObject != null && previousSelectedWorlds.Contains(t_selectablePath.SourceDummyObject.correspondingDummyList))
                {
                    newSelectedPaths.Add(selectablePath);
                }
            }

            MWB_SelectionQuery.Instance.ChangeSelectablePathList(selectablePaths);

            // pre select some of the paths base on previously selected worlds
            MWB_SelectionQuery.Instance.SelectPaths(newSelectedPaths);
        };
        OnDeselect += () =>
        {
            //Debug.Log(name + " OnDeselect ");
            //MWB_SelectionQuery.Instance.CleanRegisteredPaths();
        };
        //
        MWB_PathFactory Factory = MWB_PathFactory.Instance;

        if (CurrentMainPath == null)
        {
            RootPath = CurrentMainPath = Factory.GetPath();
        }
        else
        {
            var newPath = Factory.GetSubPath(CurrentMainPath);
            CurrentMainPath = newPath;
        }
        //selectablePaths.Add(RootPath);
    }
    //public int GetWorldIndex(MWB_DummyObjectList world)
    //{
    //    return forkedDummyObjectLists.FindIndex(x => x.GetHashCode() == world.GetHashCode());
    //}

    public void Preview(MWB_Path selectedPath, int frameIndex)
    {
        if (frameIndex < 0 || frameIndex > SimulateFrameCount + 1)
        {
            Debug.LogWarning("frameIndex invalid!");
            return;
        }

        if (selectedPath == null)
        {
            Debug.LogWarning("selectedPath invalid!");
            return;
        }

        var world = selectedPath.SourceDummyObject.correspondingDummyList;

        foreach (MWB_DummyObject dummy in world.MWB_DummyObjects)
        {
            Stack <TransformDataSegment> dataSegmentStack   = new Stack <TransformDataSegment>();
            TransformDataSegment         currentDataSegment = dummy.transformDataSegment;

            while (currentDataSegment != null)
            {
                dataSegmentStack.Push(currentDataSegment);
                // travese upward in fork tree
                currentDataSegment = currentDataSegment.previousSegment;
            }

            int currentFrameIndex = 0;

            while (dataSegmentStack.Count > 0)
            {
                currentDataSegment = dataSegmentStack.Pop();
                if (currentDataSegment == null)
                {
                    break;
                }

                if (currentFrameIndex + currentDataSegment.transformData.Count > frameIndex)
                {
                    //TODO set the objects' transform
                    dummy.objectSource.transform.localPosition = currentDataSegment.transformData[frameIndex - currentFrameIndex].localPosition;
                    dummy.objectSource.transform.localRotation = currentDataSegment.transformData[frameIndex - currentFrameIndex].localRotation;
                    dummy.objectSource.transform.localScale    = currentDataSegment.transformData[frameIndex - currentFrameIndex].localScale;
                    break;
                }
                else
                {
                    currentFrameIndex += currentDataSegment.transformData.Count;
                }
            }
        }
    }
    public void SetSubPath(MWB_Path parentPath)
    {
        if (parentPath == null)
        {
            Debug.LogError("dummy object : " + name + " , parentPath is null");
            return;
        }
        dummyMainPath = MWB_PathFactory.Instance.GetSubPath(parentPath);

        objectSource.selectablePaths.Add(dummyMainPath);
        pathIndex = objectSource.selectablePaths.Count - 1;

        pathNumber++;
    }
Пример #7
0
    public MWB_Path GetPath()
    {
        foreach (MWB_Path path in m_PathsPool)
        {
            if (path.IsInitialized)
            {
                path.Use();
                return(path);
            }
        }

        for (int i = 0; i < SpawnLimitPerFrame; i++)
        {
            createNewPath();
        }
        MWB_Path ret = m_PathsPool[m_PathsPool.Count - 1];

        ret.Use();

        return(ret);
    }
 public void SetParentPath(MWB_Path parentPath)
 {
     m_RootPath = parentPath;
 }
    private MWB_DummyObjectList ForkDummyObjects(MWB_DummyObjectList dummyObjectList, bool isInitializedAsAble, int worldIndex = 0)
    {
        //Debug.Log("Forking");
        GameObject parent = new GameObject("collide-forked dummy parent"); // this will also instantiate

        // !!! IMPORTANT : set the transform data of dummys' parent to the same as original objects'
        parent.transform.parent = dummyMasterParent.transform;
        // parent, which is the MWB_SYSTEM
        parent.transform.localPosition = transform.localPosition;
        parent.transform.localRotation = transform.localRotation;
        parent.transform.localScale    = transform.localScale;
        // add parent to dummyParent list for clean up !
        dummyParentList.Add(parent);

        MWB_DummyObjectList forkedDummyObjectList = new MWB_DummyObjectList();

        foreach (MWB_DummyObject mwbDummyObject in dummyObjectList.MWB_DummyObjects)
        {
            GameObject forkedObject = Instantiate(mwbDummyObject.gameObject, parent.transform);

            // Set layer
            forkedObject.layer = MWBWaitingLayer;
            forkedObject.SetActive(isInitializedAsAble);
            // initilize as kinematic
            forkedObject.GetComponent <Rigidbody>().isKinematic       = true;
            forkedObject.gameObject.GetComponent <Renderer>().enabled = false;
            //
            Destroy(forkedObject.GetComponent <MWB_Object>());

            MWB_DummyObject forkedDummy = forkedObject.GetComponent <MWB_DummyObject>();

            forkedDummy.Manager = this;
            // record object source
            forkedDummy.objectSource = mwbDummyObject.objectSource;
            // record fork source ( initial object has null )
            forkedDummy.forkedSource = mwbDummyObject;
            // record corresponding dummy list
            forkedDummy.correspondingDummyList = forkedDummyObjectList;

            // record previous transform data segment (initial dummy object has null)
            TransformDataSegment parentSegment = mwbDummyObject.transformDataSegment;
            forkedDummy.transformDataSegment.previousSegment = parentSegment;
            mwbDummyObject.transformDataSegment = new TransformDataSegment(parentSegment);

            // use main path to generate two sub
            MWB_Path parentPath = mwbDummyObject.dummyMainPath;

            //mwbDummyObject.RecordPosition(); // !!! Record position to avoid broken line segment

            mwbDummyObject.SetSubPath(parentPath);

            //mwbDummyObject.RecordPosition(); // !!! Record position to avoid broken line segment

            forkedDummy.SetSubPath(parentPath);

            // assign reference of dummy to path
            mwbDummyObject.dummyMainPath.SourceDummyObject = mwbDummyObject;
            forkedDummy.dummyMainPath.SourceDummyObject    = forkedDummy;
            //

            // set pathIndex
            //forkedDummy.pathIndex = mwbDummyObject.pathIndex;

            //
            Vector3 additionalImpulse;
            if (m_collidingDummyObjects.ContainsKey(mwbDummyObject))
            {
                // TODO : add a logical additional pulse, rather than just random a force

                Collision collision = m_collidingDummyObjects[mwbDummyObject];

                //additionalImpulse = Vector3.Cross(collision.impulse, Vector3.up) * collision.impulse.magnitude * 5f;
                //additionalImpulse = new Vector3(UnityEngine.Random.Range(-100, 100), 0, UnityEngine.Random.Range(-100, 100));

                Vector3 origin  = Vector3.zero;
                int     counter = 0;
                foreach (var contactPoint in collision.contacts)
                {
                    origin += contactPoint.point;
                    counter++;
                }
                origin /= counter;

                List <Vector3> perturbation = SinDistributionUtility.CalculatePerturbation(origin, collision.impulse);

                if (perturbation.Count > worldIndex)
                {
                    additionalImpulse = perturbation[worldIndex];
                }
                else
                {
                    additionalImpulse = perturbation[perturbation.Count - 1];
                }
            }
            else
            {
                additionalImpulse = Vector3.zero;
            }
            //

            // maintain rigidbody info , otherwise it'll only copy variables info but not state info
            RigidbodyState rigidbodyState = new RigidbodyState(mwbDummyObject.GetComponent <Rigidbody>(), additionalImpulse);
            forkedDummy.rigidbodyState = rigidbodyState;
            forkedDummyObjectList.AddToDummyObjectList(forkedDummy);
            //
        }

        return(forkedDummyObjectList);
    }
 public void AddPath(MWB_Path path)
 {
     throw new NotImplementedException();
 }