PavelBlend / blender-xray

STALKER (aka xray-engine) import/export plugin for Blender 3D
BSD 2-Clause "Simplified" License
185 stars 39 forks source link

Altering locations of grass in level.details using X-Ray plugin #245

Closed Szabi123 closed 5 years ago

Szabi123 commented 5 years ago

Dear Pavel!

I would like to learn how to perform the following tasks in level.details file using your Blender plugin:

  1. Change the locations of an already existing plant model on the map.
  2. Add a completely new mesh model into the row of the already existing models and define it's locations on the map.

I know, that each plant has got an own color and their locations are defined by painting or removing this specific color on the map. However you have a video called "level details plugin" and I assume you are talking about something similar, but unfortunately I don't understand russian language.

So my question is: would it be possible, that you could create a quick tutorial video specifically about those two tasks I wrote? Nothing special, just to choose a plant, delete some of it's locations from the map and add some new locations to the map, plus adding a new model and define it's locations on the map, so that I could see this process step by step in Blender from start to finish.

I would be really grateful if you could do this tutorial for me, like you did previously with other tasks.

Thank you so much in advance!

p.s.: I like your method of editing level.details in Blender so much, becouse this way we can avoid having to fidget with SDK.

PavelBlend commented 5 years ago

To understand how to do this, you need to know what the images are responsible for:

details meshes 0.png RGB - index of the first 3d model, Alpha - density of the first model(how thick will the grass grow)

details meshes 1.png RGB - index of the second 3d model, Alpha - density of the second model(how thick will the grass grow)

details meshes 2.png RGB - index of the third 3d model, Alpha - density of the third model(how thick will the grass grow)

details meshes 3.png RGB - index of the fourth 3d model, Alpha - density of the fourth model(how thick will the grass grow)

These images can be edited in blender, or in photoshop. If you need to change the position of the model, then you need to paint a certain part of the image in the color that is attached to the model.

Szabi123 commented 5 years ago

Would you please help me a bit to understand first, why are there four of these png images? For example, I open one in image editor and I see this:

kép

Now I suppose, each plant has got an own color. So I paint the squares on the image with that color, and I get the plant in those areas. But why to use four "details meshes.png" images on one map?

PavelBlend commented 5 years ago

Because one slot can store up to 4 types of models. I'll add the video now.

PavelBlend commented 5 years ago

https://youtu.be/-gXRkCnJjJI

Szabi123 commented 5 years ago

First of all, thank you so much for this video! It gives me the best way to learn!

Please let me ask two more things.

  1. You say, that "one slot can store up to 4 types of models". Now sorry for the silly question, but what types do you mean? Different type geometry? Or different height? I mean what I see, is that you paint in all four "details meshes.png" images, but you picked only one color from one specific model. So I try to understand the connection between the model and the four "details meshes.png" images.

  2. On the specific areas you first erase alpha, than you add alpha paint. What is the reason for this?

  3. I know, this is probably the most silly question, but could you please give me some instructions, how to import the map with objects (that is how you start your video, you already have the map imported)? I guess, the level must be compiled some way, and one time I tried this with Lost Alpha, but I failed. I read some pages on internet about this, but was not clear for me. Unfortunately Lost Alpha SDK doesn't contain all 24 maps compiled in *level files (I assume, that file you opened in Blender?), only 5-6 of them and I haven't found any places from where I could download these compiled maps. Or is there any other way to do this?

Thank you!

PavelBlend commented 5 years ago
  1. You can choose different colors. You can specify the colors of any 3D models that were imported. One slot can store four 3D models of grass / leaves / nuts / bolts / stones ...

  2. You can not delete the alpha, but immediately add it. Or vice versa. You can immediately add alpha and do not erase. You can and erase and add alpha. It does not matter in what order you do it. The main thing is that the alpha channel is being edited. You can leave the alpha channel as it is. The alpha channel indicates how thick the grass will be sown.

  3. I used my addon: https://github.com/PavelBlend/blender_stalker_tools_addon But it is quite raw and experimental.

Szabi123 commented 5 years ago

Would you please tell me, how to install this addon (which file to chose when I press "install addon from file" in user preferences menu)?

And after installing addon, how do I import the map, which file is selected from hard drive?

Thanks!

PavelBlend commented 5 years ago

This addon is not installed using the "Install Addon from file" button. You need to manually copy the stalker_tools folder to blender addons (C:\Program Files\Blender Foundation\Blender\2.79\scripts\addons).

Szabi123 commented 5 years ago

I copyed stalker_tools folder into addons folder. I got error message that some files are missing. Then I copyed those two files from root (just in case...) - ".GITIGNORE" and "README.md" - into stalker_tools folder as well. Now I see it in addons, as Stalker Tools, but nothing related option occurs in Import menu, plus I see a message "missing script file: io_scene_xray". What did I do wrong?

kép

Szabi123 commented 5 years ago

I reinstalled X-Ray Engine Tools and then Stalker Tools plugins, no errors now, as you see in the image below, both plugins are enabled, but still no X-Ray related options in Import menu.

kép

Szabi123 commented 5 years ago

One more note: I tried to disable X-Ray Tools. When I try to enable it again, I get the following error message:

kép

PavelBlend commented 5 years ago

Try reinstalling io_scene_xray first, then stalker_tools. Apparently the problem is in the addon io_scene_xray, since I do not see the addon settings in the screenshot.

Szabi123 commented 5 years ago

Dear Pavel!

I dived into the problem and finaly figured out, that "MappingProxyType" error is related to some leftover files of Python from previous installs. Moral of the story again, is to never trust Windows' uninstaller...

I managed to import a map. Your software is phenomenal, my compliments! I met some skilled STALKER dudes so far, but the expert level you represent is a whole different story.

My computer a bit struggles with all this crowded map. If you can advice me, what to switch off and how, in order to save some computing power, please, tell me.

kép

Next task for me is to do what you showed in the tutorial. I'll get back with results.

Thanks again!

PavelBlend commented 5 years ago

You can select FASTPATH objects and delete them:

import bpy

bpy.ops.object.select_all(action='DESELECT')
for obj in bpy.data.objects:
    if obj.name.startswith('FASTPATH'):
        obj.select = True
Szabi123 commented 5 years ago

Sorry, could you please give me some more detailed information about this? What does "import bpy" mean? Like I said, I'm new to Blender yet. I guess, this is a code I have to alter, but how and where?

Szabi123 commented 5 years ago

Note: using shift+F4 I opened script editor and typed the lines you wrote. What's next? How do I delete these objects?

PavelBlend commented 5 years ago

You need to click Run Script and the objects will be highlighted. You can then delete them using the X key.

Szabi123 commented 5 years ago

Dear Pavel!

I'm experimenting with grass using your tutorial. Thanks for teaching me these things!

I know I asked before, but please let me get back again to some questions related to alpha.

  1. So you first erase alpha in all four details.meshes.png files, then you add alpha in all four of them. Please, help me to understand the reason behind all this. What is the purpose of this alpha? I mean the plant models and textures already have alpha. But then what is this alpha, and why is it first erased and then added? F.e. what would happen, if I didn't erase and then add alpha at all, just paint with a plant's specific color?

  2. In your tutorial, you do not paint all slots using "erase alpha" or "add alpha", just some parts of them. Why?

  3. What is the effect of the "stregth" setting when you erase or add alpha?

  4. And what is the effect of the "stregth" setting when you paint with a specific color of a choosen plant?

Thank you!

PavelBlend commented 5 years ago

1 - Alpha channel you can not edit, and leave in its original state. But if you edit it, then just change the density of the grass at the level. Alpha in 3D plant models and alpha in a slot are two different things. When writing importer level.details, I could put the density in a separate image, but then the number of images would be twice as large. So I put the grass density in the alpha channel of the images. If you will not edit the alpha channel, and change only the color, then you simply change the 3D model without changing the density of this 3D model.

2 - You can draw it anywhere. I decided not to decorate the whole level, but only a small part.

3 - The higher the strangth, the faster you will erase or add an alpha channel.

4 - If you paint with a color from a plant, then you need to set the strength to 1.0. Otherwise, the colors will be distorted and the result will not be as you expect.

Szabi123 commented 5 years ago

Dear Pavel!

Please, let me ask some questions.

  1. I managed to learn your tutorial and I added one type of a plant to a specific area. For the first try I added alpha to all four details meshes png-s. Than I made a second try, this time I erased alpha in all four details meshes png-s in a circle in the middle of the area of the plants. Due to your instructions, I expected, that density will go lower in the middle part, where I erased alpha, but I don't see any difference, see the image below.

kép

  1. Is there any worth fidgeting with erasing and adding alpha, due to the fact, that in Lost Alpha menu you have a grass density slider option?

  2. If I do not want to have any plants in a certain area of the map, how can I erase them all?

Thank you!

PavelBlend commented 5 years ago

1 - Yes, the density should have decreased. If you erased the alpha channel from the image meshes png, then it should be saved as is. Can you give me a link to download the resulting level.details file? And preferably a link to download the blend file. So that I can reproduce this behavior in myself. It seems to me that there is an error in the exporter, or you have not erased all the alpha.

2 - This parameter in the settings indicates the overall density of the grass, or in other words - this is the multiplication factor for density values, which is spelled out in the level.details file. In some situations, you can not edit the density in level.details, but leave it in its original state.

3 - With Photoshop/Gimp, you can highlight pixels of the same color with the Magic Wand tool and change them with a different color.

Szabi123 commented 5 years ago

Dear Pavel!

Finaly I managed to do this, see the image below. It turned out, that I think I didn't use enough strength value in erasing alpha setting.

kép

Szabi123 commented 5 years ago

Dear Pavel!

Would it be possible to add a new tree model, or remove an existing one from a map using your Blender plugin, without having to use the SDK?

PavelBlend commented 5 years ago

At the moment it is impossible.

Szabi123 commented 5 years ago

Dear Pavel!

Please, let me ask a question. I created a flower model using 3 different textures, as you see in the image below.

kép

When I tried to export level.details from Blender, I got an error message, that it uses "more than one material". Does this mean, that for flowers I can only use one texture for each flower model? Or is there any solution?

Thank you.

PavelBlend commented 5 years ago

You can not use more than one texture for one 3D model. This format limitation. For such cases, you need to combine all the textures into one atlas.

Szabi123 commented 5 years ago

Dear Pavel!

I'm trying to add a new plant model to a map. I was trying desperately all day, following your tutorial video, but I always fail. Here is what I do:

  1. I open Blender and create my model. The dds texture I use for the model is located in the "det" folder.
  2. I open a second Blender and I import the map and the level.details file. I copy my model from the first opened Blender to the second one where I imported the map and level.details. I add a new detail index (and color) for my model, like you showed in the video and using ctrl + p I attach my new model to "level.details meshes".
  3. I copy the color of the new model to texture paint, I paint with the color in all four details.meshes png images, also erasing and adding alpha.
  4. Finaly I export level.details with the right shaders selected.

I get no error warnings, everything goes fine, but when I open the game, I see, that my models are lying on the ground norizontaly (not verticaly), and all of them are black, as you see in the image below.

kép

Please, be so kind to look into my level.details file, perhaps you will discover my mistake somewhere. Here is the link to the file: https://drive.google.com/open?id=1YrYLDUCB2fGg1zS5wiimkZOoo6AUwafP

Thank you so much!

PavelBlend commented 5 years ago

So that the grass is not turned, you need to apply a rotation to it (Ctrl + A> Rotate). About the blackness: your texture is in the det folder. And in the file level.details indicated "MACSONYA DDS". rename texture to "det\MACSONYA DDS". And re-export to level.details

Szabi123 commented 5 years ago

Thanks, you were right! However, I didn't forget to rename the texture path (det...), but now I see I did it in the wrong line...

Let me please ask something else. For a long time I'm thinking about adding ivy to tree barks or house walls. Do you think I could do this by editing level.details and without having to use SDK?

PavelBlend commented 5 years ago

Most likely it does not work out. Since the models in level.details do not have exact positions. Such things need to be done in the form of static level geometry.

Szabi123 commented 5 years ago

Dear Pavel!

I'm trying to add a new model to level details meshes, but when I'm trying to export level.details file, I get the following error message:

Traceback (most recent call last): File "C:\Program Files\Blender Foundation\Blender\2.79\scripts\addons\io_scene_xray\utils.py", line 421, in wrapper return method(self, context) File "C:\Program Files\Blender Foundation\Blender\2.79\scripts\addons\io_scene_xray\details\ops.py", line 290, in execute self.exp(objs[0], context) File "C:\Program Files\Blender Foundation\Blender\2.79\scripts\addons\io_scene_xray\details\ops.py", line 303, in exp exp.export_file(bpy_obj, self.filepath, export_context) File "C:\Program Files\Blender Foundation\Blender\2.79\scripts\addons\io_scene_xray\details\exp.py", line 29, in export_file _export(bpy_obj, chunked_writer, context) File "C:\Program Files\Blender Foundation\Blender\2.79\scripts\addons\io_scene_xray\details\exp.py", line 14, in _export write.write_details(chunked_writer, lvl_dets, context) File "C:\Program Files\Blender Foundation\Blender\2.79\scripts\addons\io_scene_xray\details\write.py", line 39, in write_details model_exp.export(detail_model, packed_writer, context, mode='DETAILS') File "C:\Program Files\Blender Foundation\Blender\2.79\scripts\addons\io_scene_xray\details\model\exp.py", line 19, in export packed_writer.puts(tx_name) File "C:\Program Files\Blender Foundation\Blender\2.79\scripts\addons\io_scene_xray\xray_io.py", line 161, in puts self.data += string.encode('cp1251') File "C:\Program Files\Blender Foundation\Blender\2.79\python\lib\encodings\cp1251.py", line 12, in encode return codecs.charmap_encode(input,errors,encoding_table) UnicodeEncodeError: 'charmap' codec can't encode character '\xd6' in position 9: character maps to location: :-1

Could you please tell me, what could be the problem?

Thanks!

PavelBlend commented 5 years ago

It looks like you are using an invalid character in the texture name. Try renaming the texture. Remove invalid characters. Characters from cp1251 encoding are allowed: https://en.wikipedia.org/wiki/Windows-1251

You can give a file that plays this error? I will make a warning instead of an error.

Szabi123 commented 5 years ago

Dear Pavel!

I renamed my file to "det_K" and now it works. However, I cared not to name the files using hungarian letters...

But now I face another issue. My texture is in det folder. I have given the right texture names and paths, but still, I get only black textures. No clue why...

My file is here: https://drive.google.com/open?id=17SZ90pG4MRQbvV5reFIwEd67LGnyXMcO

Perhaps you could tell me, what is wrong?

PavelBlend commented 5 years ago

You have the path det\det\det_K instead of det\det_K. You can check this by importing your level.details into blender. Or you can open the Lost Alpha console and find a warning in it that the texture was not found.

Szabi123 commented 5 years ago

I corrected the texture path to "det\det_K", chosen the right texture, but I still have black models. Can't find out the cause yet...

PavelBlend commented 5 years ago

Can you give a blend file that plays this behavior? And what version of addon do you use? 0.8.0? And you need to make sure that you copied all the textures into the gamedata folder from the mod.

Szabi123 commented 5 years ago

I think it must be a stupid mistake I don't recognize. Here is the blend file: https://drive.google.com/open?id=1h5Ev48J05LKXFTq-6VS0NlgTO6R2uAxk

I use version 2.79

PavelBlend commented 5 years ago

Having opened your scene, I did not find the texture det\det_K. But I found det\det_MMM. I exported the scene to level.details to launched Lost Alpha. Then I opened the console with the ~ key. And scrolled text up with the Page Up key. In the console, I saw the following: la_test_details You need to remove the build_details.001 texture in blender, and assign the build_details texture to the material. And you also need to make sure that the det\det_mmm texture exists. The texture format should be DDS. I saw in your blend scene that the texture refers to a PNG image. You need to convert PNG to DDS.

Szabi123 commented 5 years ago

Dear Pavel!

Thank you so much! Like I said, I knew it was some stupid mistake I didn't realize. I use png images to create textures and I forgot, that in det folder I only can use dds files. My bad...

Can I ask: do you have any homepage, where I can see your works, mods or anything else you are doing?

PavelBlend commented 5 years ago

I do not have a homepage. But you can download my mod here: https://ap-pro.ru/forum/129-91684-1 This is a new location for STALKER Shadow Of Chernobyl 1.0006 Here are the screenshots: ss_pavel_12-04-18_13-02-02_(l01) ss_pavel_12-04-18_13-02-45_(l01) And here's a video: https://youtu.be/K3t5m8eTwSE

Szabi123 commented 5 years ago

Dear Pavel!

However, we've already discussed about adding models and alpha, but I'm still a bit confused. Could you please help me to clarify in the following questions?

  1. If I want my model to appear in an area, do I necessarily have to use erase alpha? If yes, do I have to use it on all four level. details meshes png files? What is the effect in result of the strength value using erase alpha?
  2. What is the effect of add alpha compared to the color paint? Do I have to add alpha on all four level. details meshes png files? What is the effect in result of the strength value using add alpha?
  3. Do I necessarily have to paint with the model's color on all four level. details meshes png files to make my model appear? In your video, when you added leaves I recall you didn't use erase alpha, only the paint. But without erasing alpha my models won't appear.
  4. Is the right method of adding a model: 1. erase alpha 2. paint with color 3. add alpha?
  5. Let's assume, I would like to add a model, but only ONE SINGLE PIECE of it. Is it possible? If yes, how and with what settings?

Thanks very much!

PavelBlend commented 5 years ago

1 - You are not required to use Erease Alpha.

2 - Alpha is the density of grass.

3 - It is not necessary to draw on all four images.

4 - You can not change the alpha. To add a new model, it is enough to paint with colored paint.

5 - I did not understand the question, because I use Google translator. It does not always translate correctly.

And I hope the translator correctly translated my answers.

PavelBlend commented 5 years ago

Try to create a small level (Size 10x10 meters). Add grass to this level using the SDK. Import the resulting level.details into blender. Modify images and export back to level.details. Start the game and check the changes. If you experiment like this, you will understand how the grass in STALKER works.

I will summarize:

details meshes 0.png RGB - Index of the first 3d model of the slot details meshes 0.png Alpha - Density of the first 3d grass model

details meshes 1.png RGB - Index of the second 3d model of the slot details meshes 1.png Alpha - Density of the second 3d grass model

details meshes 2.png RGB - Index of the third 3d model of the slot details meshes 2.png Alpha - Density of the third 3d grass model

details meshes 3.png RGB - Index of the fourth 3d model of the slot details meshes 3.png Alpha - Density of the fourth 3d grass model

A slot is a parallelepiped with a width and length of 2 meters and an individual height. Each slot can store from zero to four 3D models. Therefore, 4 images meshes are imported into the blender.

Szabi123 commented 5 years ago

Dear Pavel!

Thanks for your answers!

Unfortunately I am not yet skilled enough, to create a map using SDK. But I will get back to it later, when I can use grass paint properly.

I made a test. I used only paint (no erase or add alpha). I painted four rectangles. First one on png0 with 1 strength. Second to png1 with 0.5 strength. Third to png 2 with 0.25 strength, and fourth to png3 with 0.125 strength. I see only the first rectangle made with strength 1. Others are not visible. Does this mean, that the color strength must always be 1.0? Apart from that, in the triangle you see there are too many mushrooms. How can I decrease their number? See the image:

kép

I try to ask the other question again. Let's assume, I created this mushroom model and I want to use it on in the game. But: I want to add ONLY ONE mushroom into the whole map. Not a few, but only ONE. Can I do that somehow?

Szabi123 commented 5 years ago

Dear Pavel!

I'm using Antennas level, as a test map, becouse it is small enough.

I try to write my problem in a better way. So, I paint with the model's color, either onto all four png images, or only one. If I use any other stregth value than 1.0, my model will not appear in the game. If I use exactly 1.0 stregth value, my model appears, but in a very high density, even if I only paint on one png image of the four, see this image below:

kép

The only way I can somehow decrease density is using erase alpha. But the problem with this, is that this way I will erase all other plants in that area too.

So what I would like, is to add my model, but in a very low density. For example, of this mushroom model I would need only 4-5 pieces around some trees in a few locations, but not hundreds of them. And this gives me headache. Can you tell me the proper way?

Thank you!

PavelBlend commented 5 years ago

To add the model to the map, you need to use the value of strength equal to 1.0

To make the models not so many, you need to turn off the Alpha parameter of the brush when drawing: 01 If you disable the alpha option, then you will not change the old density. Density will remain unchanged.

There is no possibility to add one model of the mushroom to the map. It is possible to add models of mushrooms in the area of 2x2 meters. To add not many models of mushrooms, you need to adjust the density.

Szabi123 commented 5 years ago

Dear Pavel!

Thank you for your reply!

I use color paint without alpha. But still the density is guite big. But I will try to experiment with erase alpha and add alpha and I will tell you about the result.

One more thing. I created a plant, that consists of two planes merged together in X-shape at the stem. My problem is, that the stem of the plant is dividing to two parts when the wind moves the plant. see the image:

kép

Did I do something wrong in modeling?

Szabi123 commented 5 years ago

One note. The original plant in Blender looks like this:

kép

PavelBlend commented 5 years ago

Make sure origin is in the center of the stem: details_model_test_origin And also make sure that the stem is always in the center (did not deviate to the left or to the right)

Szabi123 commented 5 years ago

Hi!

I don't see the problem yet, in my image the stem seems to be in center. Perhaps a little bit slipped, but I don't think this is a problem.

I uploaded the Blender file for you, and I resized the dds texture to smaller to upload quicker. Would you please take a look at it? The link:

https://drive.google.com/open?id=155D21gYNgpiSdzcUMkTAqQxW0f3b1sJV

Thanks!