Abstract The wide application of virtual reality technology has brought opportunities for teaching ideology and politics, breaking traditional education’s time and space limitations. This paper proposes an automatic three-dimensional modeling technology model, combined with computer vision camera imaging principles, to optimize the amount of data and improve optimization efficiency. And on this basis, it further proposes the Civics virtual scene construction technology, combined with the improved QEM grid simplification algorithm of edge segmentation, to optimize the virtual scene by simplifying the complex three-dimensional grid model. The experimental group’s students have shown good acceptance of this teaching method when teaching Civics in VR venues. In the cognitive and knowledge level of Civics learning, there is a significant difference between the experimental group and the control group in the dimensions of value identity and knowledge retention (P<0.05), and the mean value in the dimension of value identity is as high as 4.55, which is a very significant difference from the control class (P<0.01). And in the experiential feedback of Civics learning, the students in the experimental group have a greater sense of scene realism than the students in the control group (P<0.01), a stronger sense of realism of the interactive experience in learning (P<0.05), a higher degree of concentration in learning (P<0.01), and a more minor degree of interference by the external environment (P<0.01).