Giter Club home page Giter Club logo

Comments (8)

crawlchange avatar crawlchange commented on June 28, 2024 2

Hahahah! I was able to programmatically generate one hair strand! I'll be sharing the code and step-by-step here, as this effectively provides a general api for converting any strand-based hair into this system :)

-Create a C# script called "CustomHairData" with this code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.DemoTeam.Hair;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;

[CreateAssetMenu(fileName = "CustomHairData", menuName = "ScriptableObjects/CustomHairData", order = 1)]
public class CustomHairData : HairAssetCustomData
{
    public override bool AcquireCurves(out HairAssetProvisional.CurveSet curveSet, Allocator allocator) {
        curveSet = new HairAssetProvisional.CurveSet(allocator);
        curveSet.curveCount = 1;
        curveSet.curveVertexCount = new UnsafeList<int>(1,allocator) { 2 };
        curveSet.vertexDataPosition = new UnsafeList<Vector3>(2,allocator) { new Vector3(0.0f, 0.0f, 0.0f), new Vector3(1.0f, 0.0f, 0.0f) };
        curveSet.vertexDataTexCoord = new UnsafeList<Vector2>(2,allocator) { new Vector2(), new Vector2() };
        curveSet.vertexDataDiameter = new UnsafeList<float>(2,allocator) { 1.0f, 1.0f };
        return true;
    }
}

-Go to: Assets -> Create -> ScriptableObjects -> CustomHairData

That will add this CustomHairData scriptable object in the project.

-Then: Assets -> Create -> Hair -> Hair Asset

-In the Hair Asset, under "Settings Basic", select Type: Custom. Then, under "Settings Custom", drag and drop the CustomHairData scriptable object (not the script) into "Data Provider". Then, click "Build strand groups".

-Now create a hair instance and use that hair asset. The code above creates a single-strand, two vertices hair. You can modify that to programmatically generate or import any shape.

from com.unity.demoteam.hair.

crawlchange avatar crawlchange commented on June 28, 2024

Update: I'm working out on making things work with HairAssetCustomData instead of alembic, which seems to be able to be programmatically generated. But that's not for sure yet, and this is also entirely undocumented terrain. I really hope this works as the hair system is not of very much use if it is not exposed to scripting.

from com.unity.demoteam.hair.

qlee01 avatar qlee01 commented on June 28, 2024

Regarding alembic import it works pretty much the same as Unreal Engine. It’s not supposed to be a hair authoring tool, you need to rely on Blender or Maya to author hair and export as alembic into Unity. I had no issues so far with the workflow tbh. But much try and error, as this is not yet officially part of Unity editor, but an experimental package. In my opinion for what it is it works great.

from com.unity.demoteam.hair.

crawlchange avatar crawlchange commented on June 28, 2024

@qlee01 Notice the "steps to reproduce" that I mentioned. If you merely import the SampleHair.abc file (from the Unity Learn resources!) into blender, and then export back into alembic, it already cannot be read by this plugin anymore. So what exactly would "the workflow" be?

It is not about authoring hair, it is about WHAT IS THE FILE FORMAT OF HAIR that the plugin expects. "Alembic" is not a hair file format, and this plugin does not accept every alembic file. There are 1 billion ways of authoring hair in Blender, in fact any mesh in blender can be a hair. Also blender particles can be hair. But I can't export particles into alembic, can I? There is not "a" workflow for authoring hair in Blender.

"The workflow" is undocumented. So when you refer to "the workflow" you are using, I have no idea what are you referring to, which is just another way of saying that this plugin is entirely undocumented and I have no idea how to use it (I mean, I know how to use it from the moment a suitable alembic file is provided, but there is no documentation on how to produce that alembic file, and of course you can't just export a generic scene from blender, which would almost be the definition of an alembic file, and import into this: there is some specific kind of "scene" or "object" that this project would consider a "hair", but that has not been documented).

from com.unity.demoteam.hair.

qlee01 avatar qlee01 commented on June 28, 2024

Maybe just check how it’s done for Unreal. It’s really the same, and you can import all alembic hair which were created corny unreal easily. There should be dozens of tutorials for blender to meta human hair.

from com.unity.demoteam.hair.

crawlchange avatar crawlchange commented on June 28, 2024

Thanks @qlee01 ! That is something definitely worth checking. The issue still is that I need scripting capabilities (so just producing an alembic hair by hand wouldn't be enough), so I'm trying to guess how to create a CurveSet object for the HairAssetCustomData (which I've been successful in creating so far). But that unreal workflow could definitely provide some indirect clues. I hope someone else could provide a different look on this.

from com.unity.demoteam.hair.

qlee01 avatar qlee01 commented on June 28, 2024

Great! I also figured out how to create hair with textures, albeit without reading the source code of hair package it’s hard to tell what each channel of textures is for. But with this you can create grooms, control length, distribution and direction.

from com.unity.demoteam.hair.

ldoppertin avatar ldoppertin commented on June 28, 2024

I am experiencing the same issues with the alembic import. Have you made any progress or found a solution?

Currently I am using your code to convert my data to a curve set (thanks a lot!). However, I'm stuck as I don't understand how to provide curve UVs...

from com.unity.demoteam.hair.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.