예제 #1
0
    private bool LoadXmlMeshAsset(XmlNode mesh_node)
    {
        string mesh_name = XmlUtils.GetString(mesh_node, "name", null);

        if (mesh_name == null)
        {
            Logger.Error("RobotLoader::LoadXmlMeshAsset::Missing mesh name.");
            return(false);
        }

        string mesh_file = XmlUtils.GetString(mesh_node, "file", null);

        if (mesh_file == null)
        {
            Logger.Error("RobotLoader::LoadXmlMeshAsset::Missing mesh file for: {}.", mesh_name);
            return(false);
        }

        string mesh_path = ConfigUtils.ResolveFile(asset_basedir_, Path.Combine(mesh_dir_, mesh_file));

        // Import STL for this mesh. Unity has a 64k vertices per mesh
        // limit (in order to fit indexes in short) so one STL might
        // produce multiple Meshes.
        IList <Mesh> meshes = pb_Stl_Importer.Import(mesh_path);

        // We can globaly turn convexification on. MuJoCo convexifies all
        // geoms for collision detection, this mode can help debug / inspect it.
        if (convexify_meshes_)
        {
            List <Mesh> convex_meshes = new List <Mesh>();
            foreach (Mesh mesh in meshes)
            {
                convex_meshes.Add(ConvexHull.CreateConvexHull(mesh));
            }
            meshes = convex_meshes;
        }

        if (meshes == null)
        {
            Logger.Error("RobotLoader::LoadXmlMeshAsset::Cannot load: {} from: {}.", mesh_name, mesh_path);
            return(false);
        }

        if (meshes.Count == 0)
        {
            Logger.Error("RobotLoader::LoadXmlMeshAsset::No meshes in: {} for: {}.", mesh_path, mesh_name);
            return(false);
        }

        Vector3 scale = XmlUtils.GetVector3(mesh_node, "scale", Vector3.one);

        return(CreateMeshAsset(assembly_parts_, mesh_name, scale, meshes));
    }
예제 #2
0
    void UpdateFlows()
    {
        // timer countdown
        updateTimer -= Time.deltaTime;

        if (updateTimer <= .0f)
        {
            // randomize com every update frequency
            rand = Random.insideUnitCircle * GM.omega;

            updateTimer = updateFrequency / GM.speedup;
        }

        // get com and n of sheep
        m_torunning = 0;
        m_toidle    = 0;

        // get points
        List <Vector3> positions = new List <Vector3>();

        // centre of mass
        int totalMass = 0;

        com = new Vector3();
        // clear list and add full cells for area purposes
        for (int i = 0; i < GM.flowPrecision; i++)
        {
            for (int j = 0; j < GM.flowPrecision; j++)
            {
                // add cell to hull positions
                if (forceField[i, j].m_sheep > 0)
                {
                    positions.Add(forceField[i, j].coordinates);
                }

                // com
                totalMass += forceField[i, j].m_sheep;
                com       += forceField[i, j].coordinates * forceField[i, j].m_sheep;

                // clear cell
                forceField[i, j].hcList.Clear();
                forceField[i, j].m_sheep = 0;
            }
        }

        // centre of mass
        com /= totalMass;

        // randomize
        com = new Vector3(com.x + rand.x, .0f, com.z + rand.y);

        // allocate sheep to cells
        foreach (HybridController HC in sheepList)
        {
            AddSheepToField(HC);
        }

        // convex hull
        hull = ConvexHull.CreateConvexHull(positions);
        area = ConvexHull.PolygonArea(hull);

        // if all cells are in a line
        if (area == 0)
        {
            area = hull.Count * binSize * binSize;
        }

        area -= binSize * binSize;

        // update flow field
        for (int i = 0; i < GM.flowPrecision; i++)
        {
            for (int j = 0; j < GM.flowPrecision; j++)
            {
                forceField[i, j].UpdateField(com);
            }
        }
    }