Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7180777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:25:11+00:00 2026-05-28T17:25:11+00:00

I am using DirectX 9 in C# I store all my vertices in a

  • 0

I am using DirectX 9 in C#
I store all my vertices in a list (not an array) because I use a dynamic LOD algorithm, so everything is calculated per frame, so my vertices could potentially be different every frame.

Everything works fine until I tried to add normals and lighting.
I found out that you can’t edit the normal once you add a vertex to a list, because it is a list of structs rather than classes. So it just gives an error like “can’t modify the return value of blablaba because it is not a variable”
For example if I tried to do this it won’t work –

vertices[i].Normal = new Vector3(0, 1, 0);

Normals have to be added when the vertex is put in the list, but you can’t calculate normals until you have a full mesh.

So I made a new custom vertex type, and instead of making it a struct I made it a class. This doesn’t work either because directx won’t accept it unless it is a struct…

So then I tried to make it work with arrays instead of a list of vertices. This resulted in having less than one frame per second. I had to use Array.Resize to change the size of my array a few hundred times per frame and I guess it didn’t like that.

You are probably thinking I should turn the final list into an array, and then calculate the normals from there. This won’t work because the vertices aren’t added in any particular order, so I can’t know which vertices are near a given vertex to be able to calculate a normal.

So how can I store my vertices in a way where I can give them normals after I have my mesh built?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T17:25:12+00:00Added an answer on May 28, 2026 at 5:25 pm

    C# prevents you from writing vertices[i].Normal = new Vector3(0, 1, 0) because that expression wouldn’t do what you wanted. Unlike an array indexer, the List<T> indexer returns a copy of the specified element, and because the vertex is a struct, the whole vertex is copied, Normal and all. You would be updating a temporary copy of the vertex, not the actual vertex that’s inside the list.

    The workaround is to get (a copy of) the vertex from the list, update it, and put (a copy of) it back:

    var vertex = vertices[i];
    vertex.Normal = new Vector3(0, 1, 0); 
    vertices[i] = vertex;
    

    It’s unfortunate that there’s no simple way to avoid this repeated copying.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to draw a polygon using c# and directx All I get is
I'd like to display 100 floating cubes using DirectX or OpenGL . I'm looking
I have a program that loads an image from a file with DirectX using
Hi i am developing game level editor.Currently I am using win32 with directX.But with
Using the D3DX library that is a part of directX, specifically directx9 in this
I'm opening a new thread based on this how to store an array in
I've made a small 3D viewer application using DirectX 9.0. Now I would like
I have some columns in a data store using 12 decimal precision. I want
First of all, please forgive me for not knowing the proper terminology, I'm sure
I am trying to use --whole-archive option, but it seems to not work with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.