Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

3D dress-up game?

edited August 2015 in General Posts: 553

My daughter (8 yo) has been asking if there's an iPad game that, it seems to me, ought to actually exist.

There are plllllllllllenty of dress-up-doll games on the App Store, but they all are mix-n-match experiences. Some have a ton of things to mix and match from, but everything that you can do is to some extent pre-rolled.

What my daughter wants is to be able to literally design the clothes--dictate the length of the sleeves, the size of the shoulders, choose all the colors, etc--and see them on a 3D model.

There are some things very close, but nothing like this actually exists. I know it would be a huge project for Codea, but would it be, theoretically, a stretch for the engine's current capabilities?

You'd need:

  • some form of human model, both male and female (doesn't have to be ultra detailed)
  • some basic template for clothes that hug limbs -- i.e. pants and shirts
  • some basic template for clothes that hang--dresses, basically
  • an ability to edit the visible/invisible parts of the clothes templates--so you could make a sleeve shorter, for instance, or a neckline wider
  • a visual editor that basically was the flattened 3D mesh of the basic templates--draw directly on the mesh and you see it on the model right away
  • possibly hair and face stuff (a whole pickle on its own right there, but let's stick with just clothes for the moment)

...of course, each of those bullet points is a heck of a project all on its own!

...but other than the huge expenditure of time required, it seems to me there's no reason Codea couldn't do that. Is there any reason Codea couldn't do that?



  • Posts: 835

    It would be possible, but extremely difficult

  • Posts: 553

    Well, sure it's hard!

    But let's break it down:

    • Making a simple human form is the first huge hurdle, but the challenge is mainly plotting the vertices. Once you've got that figured out, rendering it and rotating it and etc is not problem for Codea. And if you do it nice and modularly:

      • you can use the torso mesh for shirts
      • you can use the pelvis mesh for pants
    • Creating a UI for drawing an image to be used by the mesh is the next big hurdle, though lots of people on these forums have posted some basic drawing projects that could be used to build on.
    • Applying the image to the mesh once you've drawn it is just basic Codea stuff.

    There would of course be an issue with how the image distorts around the mesh vertices, but for a first pass it would be a good start.

    That wouldn't achieve everything I described at first, but it seems like it would establish the core functionality.

  • edited August 2015 Posts: 2,015

    MakeHuman can create humanoid meshes and has a few types of clothes. I think it can export .obj format, and then you can use @Ignatz 's .obj importer to import them. By far the hardest part of the spec would be modifying these meshes within Codea (eg adding and deforming verts).

    I think the easiest way to do this would be to set up a bunch of shape deform keys in Blender (eg for short short sleeves/ long sleeves etc). Then export models for the full extent of each deformation, and then use my key frame interpolation code to leap lerp between these key frames, so that you can animate a sleeve lengthening and shortening in response to user's touch.

  • IgnatzIgnatz Mod
    edited August 2015 Posts: 5,396

    @UberGoober - Having raised three girls who spent a lot of time dressing real and virtual dolls, I think I know exactly what you are looking for - a version of the Sims dressing room, where you can modify the actual clothing design.

    If you simply want to give your daughter something that works, before she outgrows this phase, I suggest getting one of The Sims mods, like this.

    That's because what you're asking is horrendously difficult. Getting clothing to hang properly, the look of different materials, and making face and hair (with different options, please, dad), is something I can't do after nearly three years with Codea, and then if you want to animate the model............ To see just how hard it is, you just have to look at the Sims, and you'll see it is quite wooden and not very realistic, and that was done with a big budget, with skills evolved over many years and different versions, by highly skilled professionals!

    So the reason most of my 3D projects (and many commercial games) involve vehicles is that they have a fixed shape,which don't have to be animated (or have clothes hung on them!).

    If you still want to do it as a challenge, I would recommend finding a different one. It's really that hard, unless you have amazing graphic skills, and it would take so long, and still be so lame compared with programs like the Sims, that I doubt it would end up achieving what you want.

    If you are really keen, I would treat it as a series of projects and start on them one by one. It will probably morph into something completely different over time, but that's the fun of programming..

  • Posts: 553

    @Ignatz - you're right on target, and who knows how far this will get. Getting a good idea of the challenge seems like the first order of business.

    I'm thinking what's needed is to pare the objectives way, way down. To wit:

    1. get a female 3D model from MakeHuman into a dress--oddly enough this seems like one of the hardest steps right there!--and make the dress have a separate long-sleeved top and floor-length bottom
    2. get that model into Codea via the .obj importer--theoretically simple enough
    3. make the meshes for dress and for the top each use a local image resource for texture--it looks like yojimbo's .ply importer can do some of this, so I guess that's where I'd look first
    4. get the top mesh to treat the alpha color as the model's flesh color, and the dress mesh to treat alpha normally (as transparent)--Codea's built-in image manipulation methods should be able to handle that
    5. as for editing the texture file, the simplest thing would be to skip the whole "image editing UI" thing and just have the file on Dropbox, and edit it with an external image editor.

    ...while still challenging, that seems well short of "horrendously difficult," at least on paper.

  • IgnatzIgnatz Mod
    Posts: 5,396

    Try making the dress drape realistically over a curved figure, then you'll know the meaning of horrendous.

  • IgnatzIgnatz Mod
    Posts: 5,396

    But don't let me put you off. I'll be delighted if you prove me wrong.

  • edited August 2015 Posts: 553

    I guess I was assuming MakeClothes and MakeHuman would produce a reasonable facsimile of a draping dress. Not talking about it moving or anything. But those programs seem like that's their whole thing.

  • IgnatzIgnatz Mod
    Posts: 5,396

    Your problem is that you want to be able to change the design of the dress. Colour would be easy. But once you start moving vertices, you have to think about how it changes the way it hangs.

  • edited August 2015 Posts: 553

    Right, that's definitely true, and in that five-step plan I made up there I'm thinking way less ambitious than moving vertices at all.

    To get the thing started, I meant to describe simply a dress and top whose length could be easily modified in a drawing program--just by messing with transparency. So the floor-length dress could be erased into a miniskirt--the rest would still be there, but it would be invisible because of alpha channeling.

    This would also allow you to mess with not just sleeve length but the cut of the collar, or you could even make a strapless dress top, all relatively cheaply and needing no vertex fooling around at all.

    Of course it would be janky in all sorts of ways, but I'm just saying, seems like a reasonably achievable way to start.

  • IgnatzIgnatz Mod
    Posts: 5,396

    OK, good luck. You may find shaders useful for this project.

  • Posts: 2,015

    Ok, that sounds a lot more manageable. Essentially you'd be writing a 2D drawing program, just one that projects its image onto a 3D model. You might want to look around for some starting points that offer simpler, and less photorealistic, models than makehuman. There are certainly no shortage of simple humanoid models out there. I find blendswap a good site to go to for inspiration, and lots of the models there are licensed so that it's easy to use them in your own projects (eg CC By, where you just have to attribute the author).

  • Posts: 553

    Do these other human models have built-in modular clothing that can be swapped on and off the model? I'm not crazy about the MakeHuman look, but it pre-rolls a system for swapping clothes in and out. If there's something of a comparable facility, I haven't been able to find it. I'd love it though!

  • Posts: 2,015

    I don't know, you'd have to search. Finding usable models can be tricky. People do quite often create characters with a variety of "skins".

    I think the success of this project is going to depend to an extent on how comfortable you are with 3D modelling software such as Blender. I've seen quite simple tutorials about creating clothing for a model using Blender's shrinkwrap modifier. You basically put a simple shape, even just a cube, the rough dimensions of the clothing you're creating, over the humanoid figure and hit shrinkwrap. If you're not after hyper-realism, that could be enough. There's also a cloth simulator. I've not used that though, and I don't know if that's something that would translate into a usable .obj export. Blender's UI is a nightmare at first, but there are so, so many tutorials out there that it really doesn't take long to get some basic sculpting skills (apologies if you are already past this stage). I would recommend to anyone to give it a bash. It's a lot more satisfying than using an off-the-shelf model, and you can make something to precisely your own specifications.

  • Posts: 553

    I don't have any Blender skills, but just in MakeHuman I've been able to get a full-sleeve sweater, jeans, and shoes on a female model, and export it to .obj format.

    It's not exactly what I was hoping for as step 1, according to the 5 steps above, but let's be a little agile about this, right? I'd say it's good enough for the moment to proceed to step 2.

  • Posts: 553

    I must say, it's odd that MakeHuman is built in Python and yet doesn't export to .ply format...

  • Posts: 553

    Is this the link to the code to use to import the .obj file to Codea?

  • Posts: 2,015

    yes. Have you found the instructions on coolcodea?

  • IgnatzIgnatz Mod
    Posts: 5,396

    Read the instructions, because you need to combine the two obj files

  • Posts: 553

    @Ignatz, I actually looked at that page before and didn't realize it contained the actual instructions. It seemed more like a developer's journal kind of thing, so I thought "ah, this is him going through a lot of different approaches, there's got to be another post where he sums it all up."

    I think you're great for doing this and helping us all with it. I might suggest, if you're open to it, separating the "design exploration" part of the article from the "how-to" part of it--or at least making a separate article that is only the how-to and nothing else. I just kept looking and looking for that, and I didn't realize that it was right there at the bottom of the post.

    But in any case thanks for sharing all the amazing work.

  • Posts: 553

    Also, viva Herrimann. Sad that he doesn't even make the top of the page when you type his name in Google.

  • Posts: 553

    Erk-- 3D demo code at github link-- project runs ok at first, but after i tap "load" in the parameters pane, it takes a couple seconds and then spits errors-- never see the models

  • Posts: 2,015

    Can you tell us what the errors are? If you tap any line in the output pane of Codea, the contents is copied to the clipboard, so you can paste the errors here.

  • Posts: 553

    @yojimbo2000 - I think Ignatz is doing something in the project where anything printed to the output pane quickly gets replaced by the index of the models. So directly tapping any output seems impossible.

    There are two different kinds of errors that happen.

    One printed all in yellow that says something about a duplicate symbol, which seems to happen on its own while the model loads.

    One printed in the normal reddish/orangeish Codea error color, and it seems to happen the first time I touch the screen after the model loads.

    I say "while the model loads" and "after the model loads" as if I have any way to tell this--the screen never changes at all, so there's no visual evidence that anything has happened. I'm just making these assumptions based on the timing of the errors.

    But as I said, they both vanish pretty quickly.

  • Posts: 2,015

    Comment out the lines in the code that say output.clear. Then you'll be able to read the messages.

  • IgnatzIgnatz Mod
    Posts: 5,396

    @UberGoober - Post the error messages and I'll have a look (a little later, it's 5am here). It might be a good idea to post a link to the obj file too. And while I programmed it to handle faces with more than three sides, it might be a good idea to ensure the vertices are triangulated.

    I take the point about the blog. I tend to summarise all the good stuff in my ebooks (linked from the index page in my blog).

    PS viva Herriman indeed, and 'lil anjil' ignatz...

  • Posts: 553

    Thanks for the commenting-out tip!

    The yellow errors are all the same:

    Shader Compile Error

    ERROR: 0:5: Attempt to redeclare 'reflect' as a variable
    ERROR: 0:49: Attempt to use 'reflect' as a variable
    ERROR: 0:50: Use of undeclared identifier 'totalColor'
    ERROR: 0:51: Use of undeclared identifier 'totalColor'

    ...a bunch of times in a row.

    I've so far been unable to reproduce the red-text errors. Will update if I do.

  • IgnatzIgnatz Mod
    Posts: 5,396

    Ah, that's caused by a change in the shader compiler (I think) in a recent Codea update, which no longer allows you to use a variable name of reflect.

    Change all the reflect references to (eg) reflec and hopefully it will work. I thought I'd fixed all that.

  • Posts: 553

    That did it!

  • IgnatzIgnatz Mod
    Posts: 5,396

    it's a great feeling seeing the objects appear in Codea, isn't it?

  • Posts: 553

    It is--though I've still got only your stuff up. I'm having trouble importing my files. I'm trying to do it directly, without the http calls, and it's tricky.

    Incidental to which: the in-app docs for saveText(key, data) say that if data is nil, any file by that name will be deleted. This doesn't work for me--it actually crashes the project, complaining about the nil. Is there a different way to delete files?

  • IgnatzIgnatz Mod
    Posts: 5,396

    I'm not aware of any other way. Can you post the code that crashes?

  • edited August 2015 Posts: 553

    Don't laugh, I'm actually trying to write unit tests:

    function DropboxAccessTests:saveTextFile()
        local dummyText = "lalalalalalalalalalalalalalalalalala"
        local dummyAssetKey = "Dropbox:dummyText"
        saveText(dummyAssetKey, dummyText)
        local loadedText = readText(dummyAssetKey)
        local sameTexts = dummyText == loadedText
        saveText(dummyAssetKey, nil)

    The crash message:

    error: [string "DropboxAccessTests = class(Pseudotest)..."]:38: bad argument #2 to 'saveText' (string expected, got nil)
  • IgnatzIgnatz Mod
    Posts: 5,396

    @Simeon - is there a bug in saveText? It gives an error if you provide a nil second parameter, in order to delete the saved text.

    See example immediately above. It gives an error for me, too.

  • Posts: 2,015

    @UberGoober so you're putting the .obj file into Dropbox/Apps/Codea and loading it with loadText? That's interesting, let us know how that goes. @Ignatz what do you think the pros and cons are of using Dropbox to import the models vs using http.request? Presumably the loader would be a bit simpler, because http.request is asynchronous, whereas loadText isn't ( I think)? But could this create problems down the line in terms of code portability, exporting to xCode etc? I'm not at this stage yet, so I'm a bit vague about what happens to a project's assets when you export. I guess I should do a test-run...

  • IgnatzIgnatz Mod
    Posts: 5,396

    It's fine if it's just you using the app, but if other people want to use it, they have to manually download the files into Dropbox, and sync in Codea. That's why I used http.

    If you were writing an app for the store, however, I guess you'd bundle the files with the app.

  • Posts: 553

    Still working on this, getting step 2 done seems really close.

    Isn't there some sort of io command that can delete files?

  • IgnatzIgnatz Mod
    Posts: 5,396

    Have a look at the Storage section of the Reference link above - unless you are talking about Lua's io commands, in which case I would google.

  • edited August 2015 Posts: 2,015

    If it's text assets you can delete them in the asset picker (press "edit" in the top right corner of the pane, select the files you want to delete). But it seems it's a bug that saveText nil doesn't work. It works for the globalData, projectdata commands, and according to the reference, it should also work for saveText. Perhaps we should file a bug report in the issue tracker.

    You can access assets using the Lua io library, but the io.remove command (which is how you would delete a file) has been removed from Codea (presumably to meet Apple's requirements, as you could do some serious damage). io.write doesn't except a nil value either. oops, typed in the wrong command. Its os.remove, not io, and it is present in Codea. It doesn't seem to delete the file as such, though, just deletes its contents (presumably the same as writing an empty "" string).

    If you want to experiment, here is how you use the io library to access files in the Documents folder.

    local path = os.getenv("HOME").."/Documents/"
    local file = path..fileName --unlike readText etc, with io library, path needs to include extension
    local data = file:read("*all")
    file:close() --not sure if this is necessary. Probably a good idea

    Not sure if this really gives you any useful options vs just using readText.

    In theory it should also be possible to access files in Dropbox in this way. Does anyone know the path for Dropbox assets in Codea? (the app I used to use to examine file structure, iFunBox, doesn't seem to be able to look inside apps' structure from iOS 8.3. Is this the same with iExplorer? Perhaps someone who is still on iOS 7 could take a look?)

  • Posts: 553

    Is there a way to access the Dropbox from saveLocalData, saveGlobalData, or saveProjectData? That would do the trick while saveText isn't working.

  • Posts: 2,015

    SaveText does work, just not for deleting. But it's easier to delete text assets in the asset picker, no? I don't believe it's possible to add paths to global, project, and local data.

    We just need to work out the path for Dropbox. According to the Codea wiki, section Under the Hood, Dropbox images are in HOME/Documents/Dropbox.spritepack/ . But the page hasn't been updated since the text assets feature was added, so it doesn't say what the path for Dropbox text files is. I've tried HOME/Dropbox/ , HOME/Documents/Dropbox, HOME/Documents/Dropbox.textpack/ HOME/Documents/Dropbox.text/ etc.

    If someone with a pre-iOS 8.3 device and iExplorer/ iFunBox (or a jail broken iPad) or whatever could check what the path is for Dropbox text assets, I'd be really grateful.

  • dave1707dave1707 Mod
    Posts: 6,828

    @yojimbo2000 Try this.

    file = os.getenv("HOME").."/Documents/Dropbox.assetpack/FileName.png"
  • Posts: 2,015

    @dave1707 Awesome, that works! Thank you.

    I've been doing some more experiments, and one big advantage of using text assets (ie readText saveText) for things like 3D models, if anyone is thinking of going the XCode/ AppStore route, is that they automatically get exported with your project, whereas global data/ project data isn't.

  • Posts: 2,015

    btw, one slightly odd behaviour I've noticed as that when you create a file with saveText it doesn't always appear straight away in the asset picker in your project. At first I thought the old "save text can't create new files" bug had appeared again, but the files are there, it just sometimes takes a while for them to show up. If you exit the project and look in the general asset viewer you can see them, and then when you go back into the project they're there. Just thought I'd post in case it's confusing anyone else.

  • Posts: 2,015

    @dave1707 @UberGoober more testing... using and on Dropbox files in HOME/Documents/Dropbox.assetpack works for text files with extensions other than .txt. You can't see or select the files in the asset-picker, or load them with readText, and they won't be automatically exported as assets when you export the project. But you can read the files in Codea with and (and of course you can see, rename, delete etc the files in Dropbox). This is actually pretty cool, as it gives you an option to easily bring data into Codea (and manage it with Dropbox), but without cluttering up your asset pickers.

    Slightly off-topic, but my current thinking is (I'm going to write a blog post on this eventually, in the series on keyframe interpolation of Blender models) that I want an interim 3D format. The reason why is that when you have a project with lots of models, string.gmatch iterating over several long .obj files every time you launch the programs takes time (in one of my 3D projects, the launch time is already around 6 seconds, and I'm only half way through adding models).

    What I'm planning on doing is having a separate model loader program that loads the models, parses the .obj files, and then saves the tables of vertices, texCoords, colours etc as json strings with saveText (by adding the __tojson metamethod to vec2, vec3, and color). This would pack all of the animation frames into a single text asset that you could select in the asset picker of the main program, and that could be unpacked into a mesh very quickly, and would automatically be exported as an asset.

    This means you could keep most of the file i/o and string parsing out of the main program (and the source files, the .obj, .mtl files etc would stay hidden in Dropbox). The resulting text asset would take up more space than the .obj files (because it describes every vertex in the mesh, not just the unique vertices, as .obj files do), but I've been experimenting with different ways of encoding the vec2s & vec3s in the json string and I think I've got it so that the resulting files are less than twice the size of the .obj files, which is a worthwhile trade-off for how much faster the app startup time would be, and how much simpler loading a model would be in the main program.

  • IgnatzIgnatz Mod
    edited August 2015 Posts: 5,396

    From my observation, obj files do include every vertex in the mesh, they come in sets of three (or four), like this

    v -2.328231 -0.889590 -3.267325
    v -2.301960 -0.868956 -3.298030

    and in the case of this file, each of these vertices appears twice.

    wrt compressing the data, simply dropping less significant digits would make a huge difference to size, I imagine. Our models don't need too much precision.

    JSON is also very verbose. It would be a lot more compact to simply concatenate the vertices with a delimiter, and use a split function to put them into a table. If you'd like me to do some testing, I'm happy to help.

  • edited August 2015 Posts: 2,015

    In the .obj file the lines beginning "v" describe unique points, and the lines beginning "f" wind those points into triangles, avoiding describing the same point twice. I just did a quick check with some obj files, and couldn't find any duplicate points in the lines beginning with "v".

    In the interests of load-speed and simplicity, my format is a dump of the vertices that will be applied to mesh.vertices, so would include duplicate points.

    Good point about rounding the figures. Your .obj importer already rounds to 2 decimal places, and the json encoder detects this and lops off the unneeded zeroes. This is actually probably why the json file is as small as it is. I'd forgotten that your .obj importer did this until you mentioned it.

    If you're writing your own __tojson metamethod, then json can be as verbose or as minimal as you want it to be. Because the table is homogenous, I'm just putting an identifier at the head, and then each vert is just a three part array. This is what the start of the file looks like:


    No white space, comma-separated values, trailing zeroes omitted etc. Can't get much more minimal than that I think.

  • IgnatzIgnatz Mod
    Posts: 5,396

    actually, you're right, now I remember how it works (it's been a while)

    Why not just string them all together without any square brackets, because they have to be packaged into vertices in threes at the end anyway? In other words, are square brackets necessary when the format is so simple?

  • Posts: 2,015

    You could do, though sounds a little risky to me! Just one number missing would destroy the entire mesh

Sign In or Register to comment.